Skip to content

Commit

Permalink
WIP: Shuffle code around
Browse files Browse the repository at this point in the history
  • Loading branch information
mingan committed Feb 13, 2018
1 parent a6dc69e commit 7c423b4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 45 deletions.
58 changes: 36 additions & 22 deletions log/syslog/syslog_logger.go → log/syslog/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@ import (
"github.com/go-kit/kit/log/level"
)

// PrioritySelector inspects the list of keyvals and selects a syslog priority
type PrioritySelector func(keyvals ...interface{}) gosyslog.Priority
// SyslogWriter is an interface wrapping stdlib syslog Writer.
type SyslogWriter interface {
Write([]byte) (int, error)
Close() error
Emerg(string) error
Alert(string) error
Crit(string) error
Err(string) error
Warning(string) error
Notice(string) error
Info(string) error
Debug(string) error
}

// NewSyslogLogger returns a new Logger which writes to syslog in syslog format.
// The body of the log message is the formatted output from the Logger returned
Expand Down Expand Up @@ -73,9 +84,32 @@ func (l *syslogLogger) Log(keyvals ...interface{}) error {
}
}

type loggerBuf struct {
buf *bytes.Buffer
logger log.Logger
}

func (l *syslogLogger) getLoggerBuf() *loggerBuf {
lb := l.bufPool.Get().(*loggerBuf)
if lb.buf == nil {
lb.buf = &bytes.Buffer{}
lb.logger = l.newLogger(lb.buf)
} else {
lb.buf.Reset()
}
return lb
}

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

// Option sets a parameter for syslog loggers.
type Option func(*syslogLogger)

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

// PrioritySelectorOption sets priority selector function to choose syslog
// priority.
func PrioritySelectorOption(selector PrioritySelector) Option {
Expand Down Expand Up @@ -107,23 +141,3 @@ func defaultPrioritySelector(keyvals ...interface{}) gosyslog.Priority {

return gosyslog.LOG_INFO
}

type loggerBuf struct {
buf *bytes.Buffer
logger log.Logger
}

func (l *syslogLogger) getLoggerBuf() *loggerBuf {
lb := l.bufPool.Get().(*loggerBuf)
if lb.buf == nil {
lb.buf = &bytes.Buffer{}
lb.logger = l.newLogger(lb.buf)
} else {
lb.buf.Reset()
}
return lb
}

func (l *syslogLogger) putLoggerBuf(cb *loggerBuf) {
l.bufPool.Put(cb)
}
File renamed without changes.
23 changes: 0 additions & 23 deletions log/syslog/syslog_writer.go

This file was deleted.

0 comments on commit 7c423b4

Please sign in to comment.