-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Added basic syslog support #486
Conversation
Thanks, interesting approach. I like the mapping of the 4 levels to the the corresponding syslog priorities. I don't like the fact that it's defined in package level, nor that it uses a factory parameter to manufacture new loggers. I guess I'd want to see the constructor to a SyslogLogger take a Does all of that make sense? |
@peterbourgon It does make a lot of sense. Thanks for the feedback. I'd actually like to propose another option first where there is no explicit syslog logger, but rather a new kind of |
@peterbourgon Here is my updated PR. It should give you a gist of the idea:
I think it makes sense to do it that way because from my understanding, loggers implement how the logs are formatted and writers define where/how they are written. Syslog does not impose any format in the log messages themselves, so this implementation allows users to use whatever log formatter they want (LogFmt or JSON for instance). New example usage:
|
log/syslog.go
Outdated
func (w syslogWriter) GetSpecializedWriter(keyvals ...interface{}) io.Writer { | ||
priority := w.selector(keyvals...) | ||
|
||
switch priority { |
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.
A complete implementation will of course handle all supported syslog.Priority
values.
Yeah, this isn't gonna fly, sorry. It's not reasonable to have every other logger implementation wrap its underlying writer at serialization time with a decorator — neither from a design perspective nor (I'm guessing) a performance perspective. As far as I can see, the design challenges here boil down to two competing requirements. First, the Syslog thing needs to introspect on the keyvals, in order to determine a priority, which means it most naturally needs to implement the Logger interface. But second, the Syslog thing is ultimately going to be a destination for other logger implementations, which means it most naturally needs to implement io.Writer. I'm not sure how to square this circle, except to say the current approach isn't the right one. Speculating: what about a type that implements both Logger and io.Writer, and can be wired in as both a decorator and a destination, shuttling state (i.e. priority) from the decorator part to the writer part with each invocation? e.g.
If you don't Decorate your Logger stack, that's fine: you'll get some default priority. |
Disclaimer: I haven't looked at the code in this PR yet, so forgive me if this is off base.
That sounds like the same problem that we had with term.NewColorLogger. Take a look at its approach to composing a |
@peterbourgon & @ChrisHines Okay. I'll look at that and I see how I can follow the same design. Looking back at the derivative I'll keep you posted. |
Any progress on the code, @ereOn, or should I take crack at it? |
@mingan You can take over if you like. I sadly am swamped in many other things to do these days. |
Closing in favor of #574 |
This PR is an attempt to add basic syslog support as requested in #333.
It does so by relying on the very recent
log/level
package.Example usage: