diff --git a/README.md b/README.md index d8ccc90..ca88b52 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ `logf` is a high-performance, zero-alloc logging library for Go applications with a minimal API overhead. It's also the fastest logfmt logging library for Go. -`logf` emits structured logs in [`logfmt`](https://brandur.org/logfmt) style. `logfmt` is a flexible format which involves `key=value` pairs to emit structured log lines. `logfmt` achieves the goal of generating logs that are not just machine-friendly but also readable by humans, unlike the clunky JSON lines. +`logf` emits structured logs in [`logfmt`](https://brandur.org/logfmt) style. `logfmt` is a flexible format that involves `key=value` pairs to emit structured log lines. `logfmt` achieves the goal of generating logs that are not just machine-friendly but also readable by humans, unlike the clunky JSON lines. ## Example @@ -61,12 +61,12 @@ timestamp=2022-07-07T12:09:10.221+05:30 level=fatal message="goodbye world" ## Why another lib -There are several logging libraries, but our usecase weren't met by the available options. +There are several logging libraries, but the available options didn't meet our use case. `logf` meets our constraints of: - Clean API -- Minimal Dependencies +- Minimal dependencies - Structured logging but human-readable (`logfmt`!) - Sane defaults out of the box diff --git a/log.go b/log.go index b2f4f42..6a4cda4 100644 --- a/log.go +++ b/log.go @@ -73,7 +73,7 @@ var colorLvlMap = [...]string{ // New instantiates a logger object. func New(opts Opts) Logger { - // Initialise fallbacks if unspecified by user. + // Initialize fallbacks if unspecified by user. if opts.Writer == nil { opts.Writer = os.Stderr } @@ -207,8 +207,7 @@ func (l Logger) handleLog(msg string, lvl Level, fields ...any) { // Format the line as logfmt. var ( - // count is find out if this is the last key in while itering fields. - count int + count int // to find out if this is the last key in while itering fields. fieldCount = len(l.DefaultFields) + len(fields) key string val any @@ -277,7 +276,7 @@ func writeTimeToBuf(buf *byteBuffer, format string, lvl Level, color bool) { } // writeStringToBuf takes key, value and additional options to write to the buffer in logfmt. -func writeStringToBuf(buf *byteBuffer, key string, val string, lvl Level, color, space bool) { +func writeStringToBuf(buf *byteBuffer, key, val string, lvl Level, color, space bool) { if color { escapeAndWriteString(buf, getColoredKey(key, lvl)) } else { @@ -335,11 +334,11 @@ func writeToBuf(buf *byteBuffer, key string, val any, lvl Level, color, space bo case int32: buf.AppendInt(int64(v)) case int64: - buf.AppendInt(int64(v)) + buf.AppendInt(v) case float32: buf.AppendFloat(float64(v), 32) case float64: - buf.AppendFloat(float64(v), 64) + buf.AppendFloat(v, 64) case bool: buf.AppendBool(v) case error: diff --git a/log_test.go b/log_test.go index ece0f29..cdd2a9a 100644 --- a/log_test.go +++ b/log_test.go @@ -89,7 +89,7 @@ func TestLogFormat(t *testing.T) { l = New(Opts{Writer: buf}) - // Debug log but with defualt level set to info. + // Debug log but with default level set to info. l.Debug("debug log") require.NotContains(t, buf.String(), `level=debug message="debug log"`) buf.Reset() @@ -111,7 +111,7 @@ func TestLogFormat(t *testing.T) { buf.Reset() // Fatal log - var hadExit = false + hadExit := false exit = func() { hadExit = true }