Package logfjournald
provides logf
Appender and Encoder for systemd Journal. It supports structured logging and bulk operations with zero allocs.
The following example creates the new logf
logger with logfjournald
appender.
package main
import (
"runtime"
"github.com/ssgreg/logf"
"github.com/ssgreg/logfjournald"
)
func main() {
// Create journald Appender with default journald Encoder.
appender, appenderClose := logfjournald.NewAppender(logfjournald.NewEncoder.Default())
defer appenderClose()
// Create ChannelWriter with journald Encoder.
writer, writerClose := logf.NewChannelWriter(logf.ChannelWriterConfig{
Appender: appender,
})
defer writerClose()
// Create Logger with ChannelWriter.
logger := logf.NewLogger(logf.LevelInfo, writer)
logger.Info("got cpu info", logf.Int("count", runtime.NumCPU()))
}
The JSON representation of the journal entry this generates:
{
"TS": "2018-11-01T07:25:18Z",
"PRIORITY": "6",
"LEVEL": "info",
"MESSAGE": "got cpu info",
"COUNT": "4",
}