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

Add syslog support #574

Merged
merged 6 commits into from
Feb 13, 2018
Merged

Add syslog support #574

merged 6 commits into from
Feb 13, 2018

Conversation

mingan
Copy link
Contributor

@mingan mingan commented Jul 14, 2017

This is another crack at #333. It incorporates the discussion from #486 but it shares very little code with it. In structure, it's very similar to term.NewColorLogger - it's so similar that loggerBuf could be extracted and be used b both (but in which package should it live? it would have to be exported which might be confusing?).

However, while working on this I realized that it breaks on one the 12 factor app principles. Including it in Go kit might be a promotion of a suboptimal approach, so I'm not sure it should be included at all.

@gouthamve
Copy link

Hi, any updates on this?

Copy link
Member

@peterbourgon peterbourgon left a comment

Choose a reason for hiding this comment

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

For the most part, I like this approach. A couple of tiny changes and I'll be happy to add it. I apologize profusely for the delay. If the original author doesn't show up in a little bit, I'll make the changes myself.

"sync"
)

// PrioritySelector inspects list of keyvals and select a syslog priority
Copy link
Member

Choose a reason for hiding this comment

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

PrioritySelector inspects the list of keyvals, and selects a syslog priority.

"github.com/go-kit/kit/log"
"fmt"
"github.com/go-kit/kit/log/level"
)
Copy link
Member

Choose a reason for hiding this comment

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

Can we do proper import grouping, i.e.

import (
    // stdlib

    // go-kit
)

@peterbourgon
Copy link
Member

@ChrisHines Any blockers that you see?

Copy link
Member

@ChrisHines ChrisHines left a comment

Choose a reason for hiding this comment

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

I don't have any experience with the stdlib log/syslog package, or syslog in general, so I don't have any opinion on the use of syslog here.

I like the exported API presented by this package. It matches the style of the other go-kit/log packages. 👍

I found an edge case that will panic which should be fixed.

Otherwise just a few nits and some readability bike shedding.

func defaultPrioritySelector(keyvals ...interface{}) gosyslog.Priority {
for i := 0; i < len(keyvals); i += 2 {
if keyvals[i] == level.Key() {
if v, ok := keyvals[i+1].(level.Value); ok {
Copy link
Member

Choose a reason for hiding this comment

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

This line may panic if len(keyvals) is odd and the last element == level.Key().

gosyslog "log/syslog"
)

// SyslogWriter is an interface wrapping stdlib syslog Writer
Copy link
Member

Choose a reason for hiding this comment

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

Missing period (.) at end of comment.


type syslogWriter struct {
gosyslog.Writer
}
Copy link
Member

Choose a reason for hiding this comment

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

type syslogWriter doesn't appear to be used anywhere, I think it can be removed.

)

// PrioritySelector inspects the list of keyvals and selects a syslog priority
type PrioritySelector func(keyvals ...interface{}) gosyslog.Priority
Copy link
Member

Choose a reason for hiding this comment

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

  • Missing period (.) at end of comment.
  • Do we need to emphasize that a PrioritySelector may not modify the contents of keyvals?
  • For readability of the source code I would move to just before the func PrioritySelectorOption declaration.


func (l *syslogLogger) putLoggerBuf(cb *loggerBuf) {
l.bufPool.Put(cb)
}
Copy link
Member

Choose a reason for hiding this comment

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

  • s/cb/lb to be consistent with variable names in getLoggerBuf.
  • I feel like it would help readability to move the type loggerBuf, func (l *syslogLogger) getLoggerBuf, and func (l *syslogLogger) putLoggerBuf declarations to after the func (l *syslogLogger) Log declaration because they are couple together more tightly than the Options related code. I find myself having to skip over the Options stuff a lot while reading the code.

Info(string) error
Debug(string) error
}

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer all of the code in this file be combined with syslog_logger.go and the combined file be renamed to syslog.go. I would put the type SyslogWriter declaration directly above the func NewSyslogLogger declaration.

@mingan
Copy link
Contributor Author

mingan commented Feb 13, 2018

I implemented all the comments apart from those phrased as questions. I rebased on top of master so tests from other subpackages pass as well.

@peterbourgon peterbourgon merged commit 328b7e6 into go-kit:master Feb 13, 2018
@peterbourgon
Copy link
Member

Thanks everyone, and sorry again for that inexcusably long delay.

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.

4 participants