Skip to content

Add syslog support - #574

Merged
peterbourgon merged 6 commits into
go-kit:masterfrom
mingan:syslog
Feb 13, 2018
Merged

Add syslog support#574
peterbourgon merged 6 commits into
go-kit:masterfrom
mingan:syslog

Conversation

@mingan

@mingan mingan commented Jul 14, 2017

Copy link
Copy Markdown
Contributor

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
Copy Markdown

Hi, any updates on this?

@peterbourgon peterbourgon left a comment

Copy link
Copy Markdown
Member

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.

Comment thread log/syslog/syslog_logger.go Outdated
"sync"
)

// PrioritySelector inspects list of keyvals and select a syslog priority

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

@ChrisHines Any blockers that you see?

@ChrisHines ChrisHines left a comment

Copy link
Copy Markdown
Member

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.

Comment thread log/syslog/syslog_logger.go Outdated
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
Copy Markdown
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().

Comment thread log/syslog/syslog_writer.go Outdated
gosyslog "log/syslog"
)

// SyslogWriter is an interface wrapping stdlib syslog Writer

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

Comment thread log/syslog/syslog_writer.go Outdated

type syslogWriter struct {
gosyslog.Writer
}

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

Comment thread log/syslog/syslog_logger.go Outdated
)

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

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

Comment thread log/syslog/syslog_logger.go Outdated

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

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

Comment thread log/syslog/syslog_writer.go Outdated
Info(string) error
Debug(string) error
}

Copy link
Copy Markdown
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

mingan commented Feb 13, 2018

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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