* Added missed >m< in github.com
* Added backquotes to denote "code" where appropriate
* Cleanup based on feedback
* Added three examples from README
* Removed Output for 3 examples
* Updated Setting Global Log Level section w/ flags
* Removed unnecessary blank lines
* Moved flags from init into main
* Update log_example_test.go
* Cosmetic change based on Olivier's feedback
* Pushed back to original
* New Examples for Log package
* Removed extra spaces
* Reorganized file and added examples
Low-level optimizations to help the compiler generate better code
when logging is disabled. Measured improvement is ~30% on amd64
(from 21 ns/op to 16 ns/op).
Last optimization was for JSON string with no character to encode. This
version focuses on strings with some chars to encode, trying to apply
the same trick for substrings that do not need encoding.
benchmark old ns/op new ns/op delta
.../NoEncoding-8 60.2 51.3 -14.78%
.../EncodingFirst-8 140 116 -17.14%
.../EncodingMiddle-8 112 86.4 -22.86%
.../EncodingLast-8 62.8 61.1 -2.71%
.../MultiBytesFirst-8 164 129 -21.34%
.../MultiBytesMiddle-8 133 96.9 -27.14%
.../MultiBytesLast-8 81.9 73.5 -10.26%
Performance update to appendJSONString so that it now checks if
the input is a simple string that contains no json delimiters, control
characters, or unicode. If simple then the operation is only three
appends. [double-quote, string, double-quote].
If a non-simple character is encountered then all of the previous
characters are appended and the operation falls back to the original
method for the remaining characters.
Before:
BenchmarkLogEmpty-8 100000000 17.1 ns/op
BenchmarkDisabled-8 500000000 4.12 ns/op
BenchmarkInfo-8 20000000 101 ns/op
BenchmarkContextFields-8 20000000 105 ns/op
BenchmarkLogFields-8 5000000 281 ns/op
After:
BenchmarkLogEmpty-8 100000000 16.7 ns/op
BenchmarkDisabled-8 500000000 3.79 ns/op
BenchmarkInfo-8 30000000 44.8 ns/op
BenchmarkContextFields-8 30000000 67.5 ns/op
BenchmarkLogFields-8 10000000 197 ns/op
When error happen, there is nothing the caller can really do and it is
not practicle to handle logging errors. Print an error on the standard
error instead.