Introduce more context to logging#256
Conversation
|
thanks Ross I'll take a look! |
A new log formatter is introduced that adds program contex to the log output, e.g. source file, and line of code where a log call is made. Additional program context can be added consistently. Datetime is formatted in ISO format and an option is provided to use UTC or local timezones.
461aa16 to
b27db87
Compare
|
@richardlehane follow up on our previous conversation, based on this stack overflow, I wonder if an overhaul of the logging to log/slog (introduced in 1.20) could also improve things? https://stackoverflow.com/a/76867161 -- possibly allowing for the implementation of some more idiomatic datetime in logging and control of logging at all (if desired) with easier control of its output than maybe currently? E.g. you maybe only want a global default of error or even "emergency", whereas if i look at how i was using it in the Wikidata module previously, debug might have been very useful. |
|
sorry for sitting on this so long Ross, I think it is a step forward in any case so will merge now. Maybe upgrade to slog in future? (though that would require pinning sf to a later go release - it can currently compile with 1.18 so maybe hold off on that for now) |
|
p.s. I made a couple of tweaks post-merge to remove init funcs & move set-up to a new Set func and the main funcs for sf and roy |
Thanks Richard. I have to get better at that, I've leaned on init a bit too much in the past but am recently learning it's not the best pattern. RE: slog -- I'm still experimenting with it myself. It's good to take a bit more time to consider. I'll circle back around if I find anything useful. |
A new log formatter is introduced that adds program contex to the log output, e.g. source file, and line of code where a log call is made. Additional program context can be added consistently. Datetime is formatted in ISO format and an option is provided to use UTC or local timezones.
Log formatting now looks more like as follows:
versus;
In future commits, log messages can be modified to remove manually entered references to "roy" or "sf".
One question might be to set datetime to UTC by default or not. I've started using the former in most codebases. Folks may still prefer local.