Skip to content

Commit 80ca796

Browse files
shmsrmr-karan
authored andcommitted
chore: make general improvements
Signed-off-by: subham sarkar <[email protected]>
1 parent 018fc3d commit 80ca796

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
`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.
1010

11-
`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.
11+
`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.
1212

1313
## Example
1414

@@ -61,12 +61,12 @@ timestamp=2022-07-07T12:09:10.221+05:30 level=fatal message="goodbye world"
6161

6262
## Why another lib
6363

64-
There are several logging libraries, but our usecase weren't met by the available options.
64+
There are several logging libraries, but the available options didn't meet our use case.
6565

6666
`logf` meets our constraints of:
6767

6868
- Clean API
69-
- Minimal Dependencies
69+
- Minimal dependencies
7070
- Structured logging but human-readable (`logfmt`!)
7171
- Sane defaults out of the box
7272

log.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var colorLvlMap = [...]string{
7373

7474
// New instantiates a logger object.
7575
func New(opts Opts) Logger {
76-
// Initialise fallbacks if unspecified by user.
76+
// Initialize fallbacks if unspecified by user.
7777
if opts.Writer == nil {
7878
opts.Writer = os.Stderr
7979
}
@@ -207,8 +207,7 @@ func (l Logger) handleLog(msg string, lvl Level, fields ...any) {
207207

208208
// Format the line as logfmt.
209209
var (
210-
// count is find out if this is the last key in while itering fields.
211-
count int
210+
count int // to find out if this is the last key in while itering fields.
212211
fieldCount = len(l.DefaultFields) + len(fields)
213212
key string
214213
val any
@@ -277,7 +276,7 @@ func writeTimeToBuf(buf *byteBuffer, format string, lvl Level, color bool) {
277276
}
278277

279278
// writeStringToBuf takes key, value and additional options to write to the buffer in logfmt.
280-
func writeStringToBuf(buf *byteBuffer, key string, val string, lvl Level, color, space bool) {
279+
func writeStringToBuf(buf *byteBuffer, key, val string, lvl Level, color, space bool) {
281280
if color {
282281
escapeAndWriteString(buf, getColoredKey(key, lvl))
283282
} else {
@@ -335,11 +334,11 @@ func writeToBuf(buf *byteBuffer, key string, val any, lvl Level, color, space bo
335334
case int32:
336335
buf.AppendInt(int64(v))
337336
case int64:
338-
buf.AppendInt(int64(v))
337+
buf.AppendInt(v)
339338
case float32:
340339
buf.AppendFloat(float64(v), 32)
341340
case float64:
342-
buf.AppendFloat(float64(v), 64)
341+
buf.AppendFloat(v, 64)
343342
case bool:
344343
buf.AppendBool(v)
345344
case error:

log_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func TestLogFormat(t *testing.T) {
8989

9090
l = New(Opts{Writer: buf})
9191

92-
// Debug log but with defualt level set to info.
92+
// Debug log but with default level set to info.
9393
l.Debug("debug log")
9494
require.NotContains(t, buf.String(), `level=debug message="debug log"`)
9595
buf.Reset()
@@ -111,7 +111,7 @@ func TestLogFormat(t *testing.T) {
111111
buf.Reset()
112112

113113
// Fatal log
114-
var hadExit = false
114+
hadExit := false
115115
exit = func() {
116116
hadExit = true
117117
}

0 commit comments

Comments
 (0)