log/formatter.go

52 lines
1.1 KiB
Go

package log
import "time"
// Formatter ...
// - must be thread safe
// TODO: measure if it's faster to have a goroutine consuming a chan, compared to locking using a mutex.
//
// TODO: what about buffered channels? How/When will the timestamp be added?
//
// -> Answer: should be added to the Envelope right before the call to Output()
// -> There should be an in between layer doing the channel thing calling Output()
type Formatter interface {
// Output generates a log entry based on the given message and Envelope
Output(message string, e Envelope)
}
type Envelope interface {
Logger() logger
Level() level
Error() error
Arguments() []*Argument
Time() time.Time
}
// envelopeData wraps an envelope to match the Envelope interface.
type envelopeData struct {
envelope
t time.Time
}
func (e envelopeData) Logger() logger {
return e.log
}
func (e envelopeData) Level() level {
return e.lvl
}
func (e envelopeData) Error() error {
return e.err
}
func (e envelopeData) Arguments() []*Argument {
return e.args
}
func (e envelopeData) Time() time.Time {
return e.t
}