Skip to content

set_global needs guard alternative #1517

Open
@HK416-is-all-you-need

Description

@HK416-is-all-you-need

Feature Request

As of now only set_global_default is only reliable way to set logger available to all threads within application.
While set_default/with_default actually sets logger onto thread local hence making it unsuitable for needs of multi-threaded application.
Documentation on these functions fails to mention that.

Ideally we should have be able to created scoped and global logger.
The reason being is that sometimes you want to be able to gracefully drop your logger, especially if you have some caching mechanism to prevent network IO from being used too often.
In my case I have fluentd logger which only sends log records after reaching certain limit, hence I need logger to be scoped so that it would flush it on application termination.

Obviously I can do it with hacks myself, but I believe proper logger would benefit from having scoped guard for global one.
Considering complexity of tracing over log I do not see a reason to copy this flaw

Alternatives

Install default logger with each new thread

Metadata

Metadata

Assignees

No one assigned

    Labels

    crate/coreRelated to the `tracing-core` cratekind/featureNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions