Documentation ¶
Overview ¶
logfmt is a small and opinionated logging package.
The only possible output format is logfmt, all string values are quoted, keys are sorted, time.Time values are in UTC and formatted using time.RFC3339.
Example ¶
package main import ( "os" "github.com/inkel/logfmt" ) func main() { l := logfmt.NewLogger(os.Stdout) l.Log("just a string", nil) l.Logf("%s %d", nil, "Hello", 2022) l.Log("a string with labels", logfmt.Labels{ "lorem": "ipsum", "int": 1234, }) }
Output: ts=1978-07-16T05:55:00Z msg="just a string" ts=1978-07-16T05:55:00Z msg="Hello 2022" ts=1978-07-16T05:55:00Z msg="a string with labels" int=1234 lorem="ipsum"
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Format ¶ added in v0.0.2
Format transform any value into a string in an opinionated way:
- String, error and fmt.Stringer values are quoted.
- Floating values uses the %g Format with a maximum of 6 significant digits.
- time.Time are converted to UTC and use time.RFC3339 Format.
- Integer values use strconv.FormatUint and strconv.FormatInt.
- All other values are formatted as %v and quoted if they have a space.
Types ¶
Click to show internal directories.
Click to hide internal directories.