50 lines
1.0 KiB
Go
50 lines
1.0 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(message string, e Envelope)
|
||
|
}
|
||
|
|
||
|
type Envelope interface {
|
||
|
Logger() logger
|
||
|
Level() level
|
||
|
Error() error
|
||
|
Arguments() map[string]string
|
||
|
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() map[string]string {
|
||
|
return e.args
|
||
|
}
|
||
|
|
||
|
func (e envelopeData) Time() time.Time {
|
||
|
return e.t
|
||
|
}
|