35 lines
592 B
Go
35 lines
592 B
Go
package logfrog
|
|
|
|
type LogFormatter interface {
|
|
Close() error
|
|
Ref()
|
|
Unref() error
|
|
Format(*LogRecord) ([]byte, error)
|
|
}
|
|
|
|
type LogFormatterFn func(*LogRecord) ([]byte, error)
|
|
|
|
type BaseLogFormatter struct {
|
|
LogFormatter
|
|
refs int
|
|
}
|
|
|
|
func NewBaseLogFormatter() *BaseLogFormatter {
|
|
return &BaseLogFormatter{ refs: 0 }
|
|
}
|
|
|
|
func (b *BaseLogFormatter) Close() error {
|
|
return nil
|
|
}
|
|
|
|
func (b *BaseLogFormatter) Ref() {
|
|
b.refs++
|
|
}
|
|
|
|
func (b *BaseLogFormatter) Unref() error {
|
|
b.refs--
|
|
if b.refs <= 0 {
|
|
return b.LogFormatter.Close()
|
|
}
|
|
return nil
|
|
} |