Uh oh!
There was an error while loading. Please reload this page.
std.log: add scoped logging struct - #6039
Conversation
* Add a std.log.scoped function that returns a scoped logging struct * Add a std.log.default struct that logs using the .default scope Implementation of daurnimator's proposal: #5943 (comment) Note that I named the function "scoped" instead of "scope" so as not to clash with the scope parameter that is used everywhere; this seemed a better solution to me than renaming the scope parameter to "s" or "log_scope" or the like.
* Add short documentation to std.log.scoped and std.log.default * Update the module documentation and example to explain the difference between using explicit scopes, using a scoped logging namespace, and using the default namespace
Since the logger implementation can be overridden, the messages might not be logged to stderr at all.
andrewrk
commented
Aug 12, 2020
I don't see this as a problem, especially since it only exists when you explicitly override the log function (only doing The simple use case (not overriding
👍
Nice work! |
Shouldn't this have done something like pubconstemerg=default.emerg;
pubconstalert=default.alert;
pubconstcrit=default.crit;
pubconsterr=default.err;
pubconstwarn=default.warn;
pubconstinfo=default.info;
pubconstdebug=default.debug;and deleted the old ones and moved their docstrings over, so it would be used as
|
@nmichaels The way I read the proposal, using a scoped logging namespace is a feature in addition to the current logging interface. Personally I would be fine with restructuring it in the way you mention, but I don't know whether people want to explicitly keep the current interface as well. Edit: Since this has been merged already, do you want me to do a follow-up PR? |
andrewrk
commented
Aug 13, 2020
I support @nmichaels follow up proposal |
nmichaels
commented
Aug 13, 2020
It is a breaking API change, but I think it's an improvement. A quick grep of the standard library didn't turn up anything obvious that depends on the current API, so it's probably not as much work as I originally assumed it would be. |
heidezomp
commented
Aug 13, 2020
Cool, I'll send a follow-up PR tomorrow then. Thank you both for the helpful reviews! 😄 |
This is an implementation of @daurnimator's proposal: #5943 (comment)
std.log.scopedfunction that returns a scoped logging structstd.log.defaultstruct that logs using the.defaultscopeNote that I named the function "scoped" instead of "scope" so as not to clash with the scope parameter that is used everywhere; I didn't feel comfortable simply renaming the scope parameter to something like "s" or "log_scope" everywhere.
Questions for review
const log = std.log.scoped(.main); log.err("oops", .{});can be used everywhere except in the root source file, if that file overrides the log implementation (since it would result in a naming conflict). Is this a problem? Maybe the log implementation could be renamed to "logger" instead?.app,.default,.mainand.root.Closes#5943