Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce more context to logging #256

Merged
merged 2 commits into from
Jan 17, 2025
Merged

Introduce more context to logging #256

merged 2 commits into from
Jan 17, 2025

Conversation

ross-spencer
Copy link
Collaborator

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:

r0ss@exponential-decay:~/git/richardlehane/siegfried/cmd/roy$ ./roy harvest
2024-08-03 13:26:06 :: roy :: roy.go:658: roy: errors saving reports to disk [open : no such file or directory]

r0ss@exponential-decay:~/git/richardlehane/siegfried/cmd/roy$ ./roy build
2024-08-03 13:32:20 :: roy :: roy.go:658: pronom: error loading containers; got open : no such file or directory
Unless you have set `-nocontainer` you need to download a container signature file

r0ss@exponential-decay:~/git/richardlehane/siegfried/cmd/sf$ ./sf
2024-08-03 13:37:10 :: sf :: sf.go:477: [FATAL] expecting one or more file or directory arguments (or '-' to scan stdin)

versus;

r0ss@exponential-decay:~/git/richardlehane/siegfried/cmd/sf$ ./sf
2024/08/03 15:49:38 [FATAL] expecting one or more file or directory arguments (or '-' to scan stdin)

r0ss@exponential-decay:~/git/richardlehane/siegfried/cmd/roy$ ./roy build
2024/08/03 15:49:29 pronom: error loading containers; got open : no such file or directory
Unless you have set `-nocontainer` you need to download a container signature file

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.

@richardlehane
Copy link
Owner

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.
@ross-spencer
Copy link
Collaborator Author

@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.

@richardlehane
Copy link
Owner

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)

@richardlehane richardlehane merged commit 52085f4 into develop Jan 17, 2025
0 of 12 checks passed
@richardlehane richardlehane deleted the dev/log-formatter branch January 17, 2025 23:44
@richardlehane
Copy link
Owner

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

@ross-spencer
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants