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

Return from handle_message as to if message was handled or not #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

oxinabox
Copy link
Member

@oxinabox oxinabox commented Nov 6, 2019

Will close #23

I am not sure on the name of the struct.
Possibly should be HandlerResponse?

cc @tkf

@codecov-io
Copy link

codecov-io commented Nov 6, 2019

Codecov Report

Merging #25 into master will decrease coverage by 2.47%.
The diff coverage is 76.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #25      +/-   ##
==========================================
- Coverage   78.94%   76.47%   -2.48%     
==========================================
  Files           7        8       +1     
  Lines          57       68      +11     
==========================================
+ Hits           45       52       +7     
- Misses         12       16       +4
Impacted Files Coverage Δ
src/LoggingExtras.jl 100% <ø> (ø) ⬆️
src/earlyfiltered.jl 50% <0%> (-5.56%) ⬇️
src/minlevelfiltered.jl 50% <0%> (-7.15%) ⬇️
src/transformer.jl 90.9% <100%> (+0.9%) ⬆️
src/tee.jl 90.9% <100%> (+3.4%) ⬆️
src/filelogger.jl 88.88% <100%> (+1.38%) ⬆️
src/activefiltered.jl 83.33% <100%> (+1.51%) ⬆️
src/common.jl 66.66% <66.66%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 76edd6f...1c979ae. Read the comment docs.

val :: Bool
end

was_handled(response) = true # If we don;t get a MessageHandled then assume worked
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it makes sense to return missing here so that tee logger would use three-valued logic automatically. The caller can then distinguish "definitely handled", "maybe handled", "not handled." Example use-case may be that, in FirstMatchLogger #23:

  • !== false is considered true for info level and below
  • but only == true is considered true for more urgent messages (to make sure they are shown)

Not sure it's worth the complexity, though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh interesting idea. Worth consideration

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or could it make sense to just return an Enum value? Then we have the option to expand the possible statuses later if necessary. On the downside making that forward compatible could be annoying.

If people always write utility routing tools in terms of was_handled (or other verbs we provide) forward compatibility would be easier. Can we somehow arrange was_handled to be the main API with the type MessageHandled as secondary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conversely: maybe was_handled should just be moved into TeeLogger
Right now it is only used to Booleanize the status so that can be written using handled |= was_handled(status)

@tkf
Copy link

tkf commented Nov 9, 2019

I am not sure on the name of the struct.
Possibly should be HandlerResponse?

MessageHandled sounds OK to me. If you go with HandlerResponse, maybe the tee logger should return HandlerResponse wrapping a vector of the returned values? Maybe it makes sense as you can let the user of the tee logger decide what it means to be "handled".

Copy link
Member

@c42f c42f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see this until just now sorry!

This is thought provoking thanks. The biggest question for me is what verbs should act on the "return status type". Personally I'm not sure I'd like to subscribe to the particular three-valued logic of missing, though if we did decide it had the right semantic it would be a nice win to have less types.

src/common.jl Outdated
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
til `handle_message` if a log message will be filtered or not.
util `handle_message` if a log message will be filtered or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
til `handle_message` if a log message will be filtered or not.
until `handle_message` if a log message will be filtered or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha yes. oops 😬

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.
Copy link
Member

@c42f c42f Nov 12, 2019

Choose a reason for hiding this comment

The 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 MessageHandled(false)?

Copy link
Member

Choose a reason for hiding this comment

The 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.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if a sink unsuccessfully handles a message, what then?

I imaging mostly that would result in an exception (e.g. could not write to file)
but that might not be a good thing.

(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.)

Something like #12

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right.

val :: Bool
end

was_handled(response) = true # If we don;t get a MessageHandled then assume worked
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or could it make sense to just return an Enum value? Then we have the option to expand the possible statuses later if necessary. On the downside making that forward compatible could be annoying.

If people always write utility routing tools in terms of was_handled (or other verbs we provide) forward compatibility would be easier. Can we somehow arrange was_handled to be the main API with the type MessageHandled as secondary?

Co-Authored-By: Chris Foster <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make handle_message return true/false depending on if accepted
4 participants