-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: Add hooks log handler wrapper for olog package #441
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to still think about your questions in the PR summary, sorry for the delay.
I think as long as they reside in logically distinct files in the
I would prefer if the hook funcs live in their related domain. I am generally worried that folks will start to just dump hooks in the
It seems fine, it's similar to the |
…app pkg; update README
I've gone ahead and refactored per your comments. Seems reasonable to me. |
What this PR does / why we need it
This PR attempts to address the issues/omissions noted here. This PR provides an example implementation of a log handler wrapper which provides callers with the ability to automatically add further attributes to all logs written to that logger instance. This helps solve for callers being able to easily and consistently add standard information to all logs, especially with information that is usually on the context or controlled by other tools (such as tracing information). This package provides both a handler and Logger function by which to provide these hooks, as well as an out-of-the-box hook for adding AppInfo (which also required an addition to the
app
package to implement theslog.LogValuer
interface).Ideally, this package would be a place where we could provide other out-of-the-box hooks for other information such as tracing, actor, and whatever else makes sense. However, there is also an argument that these hooks could simply live in the packages which govern that data (i.e. the AppInfo hook could live in the
app
package).TODO: Expose global registry level setting. More info below:
In addition to this hooks package, I also added a potential way to actually get/set the levels for different modules/packages using the global level registry (currently not used or accessible from what I can tell). Not sure if this is something we want to support, but I feel could be nice to adjust required logging levels for different packages for a variety of purposes (debugging, cost cutting, etc...).
Notes for your reviewers
This is just an example implementation and is written primarily to start the discussion around how we want to handle this workflow, as the base
olog
implementation doesn't easily allow for adding data to logs, especially from context (theolog
log handler is not exposed in any way). While a lot of this functionality could be provided by developers in each of their funcs which are called per request/transaction, it would be cumbersome and easily missed. That being said, there are a number of points I think are worth discussing regarding this implementation and I'd like thoughts on:olog
package directly instead of thishooks
sub-package? The more I think about this, the more I'm inclined to think it should, and then be exposed as options on theNew
func. The options would basically just allow for hook funcs to be provided similar to theLogger
func provided by this hooks package. However, I wanted to keep these concepts isolated for now, which is why I chose to implement it in a separate package. Thoughts?AppInfo
hook for extracting and adding AppInfo data to the logs, but should this hook just live in theapp
package?Global registry level setting
Not sure if this is something we necessarily want/need to support, especially in the near-term, but since it was noted as a goal (Ability to change log level at a module and package level.), I felt it should probably be addressed or at least discussed. However, I can't quite determine a great solution for this as of yet. I don't think wholly exposing the entire global level registry necessarily makes sense, and I personally think having users set levels by key where the key is either some package or module name is also not that great of an experience (what specifically is a module or package name key? You can only really know for sure when looking under the hood at the implementation). 2 possible ways to help ease the usage of the global registry could be (but I'm not sold on either tbh):
olog
/slog
to expose their module/package names (as determined by theolog
package) as package vars. Then any called could simply use these vars when accessing (set/get'ing) the global registry and not need to care about the actual format of the keys for those packages/modules. However, this then puts the burden on those packages to always expose this information, which also isn't necessarily great.Also, I could just be over-thinking this and it could be entirely reasonable for people to know what the key for any given package/module will be, and use that to directly access to registry. May not be too bad if given proper documentation for expected format. Thoughts?