-
Notifications
You must be signed in to change notification settings - Fork 22
Return from handle_message as to if message was handled or not #25
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
""" | ||
MessageHandled(::Bool) | ||
|
||
`MessageHandled(false)` should be returned from a `handle_message` on a logger, | ||
if it did not actually handle the log message. | ||
For example, if the log message was below the level it should log. | ||
This is of particular relevance to the [`ActiveFilteredLogger`](@ref), which can't know | ||
til `handle_message` if a log message will be filtered or not. | ||
Ideally, `MessageHandled(true)` would be returned from loggers when when they | ||
successfully handled a message, however this is not strictly required. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But if a sink unsuccessfully handles a message, what then? Maybe most log routing networks should routinely be set up to have a safe-as-possible fallback of "just print synchronously to the console if all else fails"? Then there would be meaning for a sink returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Tangentially related thought: a composable safe fallback logger could allow us to move the try/catch logic which is currently hardcoded in the frontend out into a backend.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I imaging mostly that would result in an exception (e.g. could not write to file)
Something like #12 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. |
||
E.g Sinks should always return `MessageHandled(true)`. | ||
""" | ||
struct MessageHandled | ||
val :: Bool | ||
end | ||
|
||
was_handled(response) = true # If we don;t get a MessageHandled then assume worked | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it makes sense to return
Not sure it's worth the complexity, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oooh interesting idea. Worth consideration There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or could it make sense to just return an If people always write utility routing tools in terms of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Conversely: maybe |
||
was_handled(response::MessageHandled) = response.val | ||
|
||
|
||
# Since the logging system itself will not engage its checks | ||
# Once the first logger has started, any compositional logger needs to check | ||
# before passing anything on. | ||
|
||
# For checking child logger, need to check both `min_enabled_level` and `shouldlog` | ||
function comp_shouldlog(logger, args...) | ||
level = first(args) | ||
min_enabled_level(logger) <= level && shouldlog(logger, args...) | ||
end | ||
|
||
# For checking if child logger will take the message you are sending | ||
function comp_handle_message_check(logger, args...; kwargs...) | ||
level, message, _module, group, id, file, line = args | ||
return comp_shouldlog(logger, level, _module, group, id) | ||
end |
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.
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.
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.
Haha yes. oops 😬