How opinionated?
- The only possible output format is logfmt.
- All string values are quoted.
- Label keys are sorted except
ts
for timestamp andmsg
for the message are sorted. time.Time
values are in UTC and formatted using time.RFC3339.
Another strong opinion is that it simply writes to an io.Writer
.
You get to choose if this writer is buffered, a file, a network connection, a terminal.
It's not something the package should worry about.
package main
import (
"os"
"time"
"github.com/inkel/logfmt"
)
func main() {
l := logfmt.NewLogger(os.Stdout)
l.Log("a simple log message without any labels", nil)
l.Logf("a formatted log %s without any labels", nil, "message")
l.Log("message with a few labels of different types", logfmt.Labels{
"foo": "bar",
"err": os.ErrPermission,
"now": time.Now(),
})
}
This will produce an output like the following:
ts=2022-07-13T12:31:41Z msg="a simple log message without any labels"
ts=2022-07-13T12:31:41Z msg="a formatted log message without any labels"
ts=2022-07-13T12:31:41Z msg="message with a few labels of different types" err="permission denied" foo="bar" now=2022-07-13T12:31:41Z
MIT. See LICENSE.