Skip to content

Commit effffa9

Browse files
author
Dean Karn
authored
Merge pull request #10 from go-playground/sb10-master
Add SetExitFunc() + Additions
2 parents b107c19 + 38c9337 commit effffa9

File tree

13 files changed

+49
-20
lines changed

13 files changed

+49
-20
lines changed

README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## log
2-
<img align="right" src="https://raw.githubusercontent.com/go-playground/log/master/logo.png">![Project status](https://img.shields.io/badge/version-4.2.0-green.svg)
2+
<img align="right" src="https://raw.githubusercontent.com/go-playground/log/master/logo.png">![Project status](https://img.shields.io/badge/version-4.3.0-green.svg)
33
[![Build Status](https://semaphoreci.com/api/v1/joeybloggs/log/branches/master/badge.svg)](https://semaphoreci.com/joeybloggs/log)
44
[![Coverage Status](https://coveralls.io/repos/github/go-playground/log/badge.svg?branch=master)](https://coveralls.io/github/go-playground/log?branch=master)
55
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/log)](https://goreportcard.com/report/github.com/go-playground/log)
@@ -204,20 +204,17 @@ things for you the community.
204204

205205
Benchmarks
206206
----------
207-
###### Run on MacBook Pro (Retina, 15-inch, Late 2013) 2.6 GHz Intel Core i7 16 GB 1600 MHz DDR3 using Go version go1.6.2 darwin/amd64
207+
###### Run on i5-7600 16 GB DDR4-2400 using Go version go1.8 linux/amd64
208208
NOTE: only putting benchmarks at others request, by no means does the number of allocations
209209
make one log library better than another!
210210
```go
211-
go test -cpu=4 -bench=. -benchmem=true
212-
213-
PASS
214-
BenchmarkLogConsoleTenFieldsParallel-4 1000000 1985 ns/op 1113 B/op 35 allocs/op
215-
BenchmarkLogConsoleSimpleParallel-4 3000000 455 ns/op 88 B/op 4 allocs/op
216-
BenchmarkLogrusText10Fields-4 300000 4179 ns/op 4291 B/op 63 allocs/op
217-
BenchmarkLogrusTextSimple-4 2000000 655 ns/op 672 B/op 15 allocs/op
218-
BenchmarkLog1510Fields-4 100000 16376 ns/op 4378 B/op 92 allocs/op
219-
BenchmarkLog15Simple-4 1000000 1983 ns/op 320 B/op 9 allocs/op
220-
ok github.com/go-playground/log/benchmarks 10.716s
211+
go test --bench=. -benchmem=true
212+
BenchmarkLogConsoleTenFieldsParallel-4 1000000 1294 ns/op 1065 B/op 32 allocs/op
213+
BenchmarkLogConsoleSimpleParallel-4 3000000 549 ns/op 104 B/op 5 allocs/op
214+
BenchmarkLogrusText10Fields-4 500000 2079 ns/op 2179 B/op 39 allocs/op
215+
BenchmarkLogrusTextSimple-4 3000000 402 ns/op 312 B/op 14 allocs/op
216+
BenchmarkLog1510Fields-4 200000 10915 ns/op 4362 B/op 91 allocs/op
217+
BenchmarkLog15Simple-4 1000000 1292 ns/op 320 B/op 9 allocs/op
221218
```
222219

223220
Special Thanks
File renamed without changes.
File renamed without changes.

handlers/console/console.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ func defaultFormatFunc(c *Console) Formatter {
317317
b = strconv.AppendUint(b, uint64(f.Value.(uint32)), base10)
318318
case uint64:
319319
b = strconv.AppendUint(b, f.Value.(uint64), base10)
320+
case float32:
321+
b = strconv.AppendFloat(b, float64(f.Value.(float32)), 'f', -1, 32)
322+
case float64:
323+
b = strconv.AppendFloat(b, f.Value.(float64), 'f', -1, 64)
320324
case bool:
321325
b = strconv.AppendBool(b, f.Value.(bool))
322326
default:

handlers/console/console_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,10 +820,12 @@ func getConsoleLoggerColorTests() []test {
820820
log.F("key", uint16(3)),
821821
log.F("key", uint32(4)),
822822
log.F("key", uint64(5)),
823+
log.F("key", float32(5.33)),
824+
log.F("key", float64(5.34)),
823825
log.F("key", true),
824826
log.F("key", struct{ value string }{"struct"}),
825827
},
826-
want: "UTC [32m DEBUG[0m debug [32mkey[0m=string [32mkey[0m=1 [32mkey[0m=2 [32mkey[0m=3 [32mkey[0m=4 [32mkey[0m=5 [32mkey[0m=1 [32mkey[0m=2 [32mkey[0m=3 [32mkey[0m=4 [32mkey[0m=5 [32mkey[0m=true [32mkey[0m={struct}\n",
828+
want: "UTC [32m DEBUG[0m debug [32mkey[0m=string [32mkey[0m=1 [32mkey[0m=2 [32mkey[0m=3 [32mkey[0m=4 [32mkey[0m=5 [32mkey[0m=1 [32mkey[0m=2 [32mkey[0m=3 [32mkey[0m=4 [32mkey[0m=5 [32mkey[0m=5.33 [32mkey[0m=5.34 [32mkey[0m=true [32mkey[0m={struct}\n",
827829
},
828830
}
829831
}

handlers/http/http.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ func defaultFormatFunc(h HTTP) Formatter {
276276
b = strconv.AppendUint(b, uint64(f.Value.(uint32)), base10)
277277
case uint64:
278278
b = strconv.AppendUint(b, f.Value.(uint64), base10)
279+
case float32:
280+
b = strconv.AppendFloat(b, float64(f.Value.(float32)), 'f', -1, 32)
281+
case float64:
282+
b = strconv.AppendFloat(b, f.Value.(float64), 'f', -1, 64)
279283
case bool:
280284
b = strconv.AppendBool(b, f.Value.(bool))
281285
default:

handlers/http/http_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,12 @@ func getTestHTTPLoggerTests() []test {
235235
log.F("key", uint16(3)),
236236
log.F("key", uint32(4)),
237237
log.F("key", uint64(5)),
238+
log.F("key", float32(5.33)),
239+
log.F("key", float64(5.34)),
238240
log.F("key", true),
239241
log.F("key", struct{ value string }{"struct"}),
240242
},
241-
want: "UTC DEBUG debug key=string key=1 key=2 key=3 key=4 key=5 key=1 key=2 key=3 key=4 key=5 key=true key={struct}",
243+
want: "UTC DEBUG debug key=string key=1 key=2 key=3 key=4 key=5 key=1 key=2 key=3 key=4 key=5 key=5.33 key=5.34 key=true key={struct}",
242244
},
243245
{
244246
lvl: log.TraceLevel,

handlers/syslog/syslog.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ func defaultFormatFunc(s *Syslog) Formatter {
310310
b = strconv.AppendUint(b, uint64(f.Value.(uint32)), base10)
311311
case uint64:
312312
b = strconv.AppendUint(b, f.Value.(uint64), base10)
313+
case float32:
314+
b = strconv.AppendFloat(b, float64(f.Value.(float32)), 'f', -1, 32)
315+
case float64:
316+
b = strconv.AppendFloat(b, f.Value.(float64), 'f', -1, 64)
313317
case bool:
314318
b = strconv.AppendBool(b, f.Value.(bool))
315319
default:

handlers/syslog/syslog_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,10 +961,12 @@ func getSyslogLoggerColorTests() []test {
961961
log.F("key", uint16(3)),
962962
log.F("key", uint32(4)),
963963
log.F("key", uint64(5)),
964+
log.F("key", float32(5.33)),
965+
log.F("key", float64(5.34)),
964966
log.F("key", true),
965967
log.F("key", struct{ value string }{"struct"}),
966968
},
967-
want: "UTC [32m DEBUG[0m debug [32mkey[0m=string [32mkey[0m=1 [32mkey[0m=2 [32mkey[0m=3 [32mkey[0m=4 [32mkey[0m=5 [32mkey[0m=1 [32mkey[0m=2 [32mkey[0m=3 [32mkey[0m=4 [32mkey[0m=5 [32mkey[0m=true [32mkey[0m={struct}\n",
969+
want: "UTC [32m DEBUG[0m debug [32mkey[0m=string [32mkey[0m=1 [32mkey[0m=2 [32mkey[0m=3 [32mkey[0m=4 [32mkey[0m=5 [32mkey[0m=1 [32mkey[0m=2 [32mkey[0m=3 [32mkey[0m=4 [32mkey[0m=5 [32mkey[0m=5.33 [32mkey[0m=5.34 [32mkey[0m=true [32mkey[0m={struct}\n",
968970
},
969971
}
970972
}

log.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,19 @@ func (l *logger) SetCallerInfoLevels(levels ...Level) {
355355
}
356356

357357
// SetCallerSkipDiff adds the provided diff to the caller SkipLevel values.
358-
// This is used when wrapping this library, you can set ths to increase the
358+
// This is used when wrapping this library, you can set this to increase the
359359
// skip values passed to Caller that retrieves the file + line number info.
360360
func (l *logger) SetCallerSkipDiff(diff uint8) {
361361
skipLevel += int(diff)
362362
}
363363

364+
// SetExitFunc sets the provided function as the exit function used in Fatal()
365+
// and Fatalf(). This is primarily used when wrapping this library, you can set
366+
// this to to enable testing (with coverage) of your Fatal() and Fatalf() methods.
367+
func (l *logger) SetExitFunc(fn func(code int)) {
368+
exitFunc = fn
369+
}
370+
364371
// HasHandlers returns if any handlers have been registered.
365372
func (l *logger) HasHandlers() bool {
366373
return len(l.channels) != 0

0 commit comments

Comments
 (0)