Demonstrate an alternate approach to the "level" package offered via
the "github.com/go-kit/kit/log/experimental_level" import path,
allowing log event level filtering via instances of the level.leveler
interface, created by functions that specify the filtering threshold.
Features not accommodated here for now:
- Returning an error from log.Log when squelching an event
- Returning an error from log.Log for events that lack a level
- Documentation
Benchmarks demonstrate both run time and allocation reduction for the
disallowed/squelching cases compared to the "experimental_level"
alternate:
name old time/op new time/op delta
NopBaseline-8 459ns ± 0% 130ns ± 0% -71.68%
NopDisallowedLevel-8 509ns ± 0% 136ns ± 0% -73.28%
NopAllowedLevel-8 515ns ± 0% 494ns ± 0% -4.08%
JSONBaseline-8 2.41µs ± 0% 0.13µs ± 0% -94.45%
JSONDisallowedLevel-8 506ns ± 0% 136ns ± 0% -73.12%
JSONAllowedLevel-8 2.49µs ± 0% 2.45µs ± 0% -1.48%
LogfmtBaseline-8 1.08µs ± 0% 0.13µs ± 0% -87.92%
LogfmtDisallowedLevel-8 507ns ± 0% 136ns ± 0% -73.18%
LogfmtAllowedLevel-8 1.13µs ± 0% 1.10µs ± 0% -3.26%
name old alloc/op new alloc/op delta
NopBaseline-8 288B ± 0% 64B ± 0% -77.78%
NopDisallowedLevel-8 288B ± 0% 64B ± 0% -77.78%
NopAllowedLevel-8 288B ± 0% 288B ± 0% +0.00%
JSONBaseline-8 968B ± 0% 64B ± 0% -93.39%
JSONDisallowedLevel-8 288B ± 0% 64B ± 0% -77.78%
JSONAllowedLevel-8 968B ± 0% 968B ± 0% +0.00%
LogfmtBaseline-8 288B ± 0% 64B ± 0% -77.78%
LogfmtDisallowedLevel-8 288B ± 0% 64B ± 0% -77.78%
LogfmtAllowedLevel-8 288B ± 0% 288B ± 0% +0.00%
name old allocs/op new allocs/op delta
NopBaseline-8 9.00 ± 0% 3.00 ± 0% -66.67%
NopDisallowedLevel-8 9.00 ± 0% 3.00 ± 0% -66.67%
NopAllowedLevel-8 9.00 ± 0% 9.00 ± 0% +0.00%
JSONBaseline-8 22.0 ± 0% 3.0 ± 0% -86.36%
JSONDisallowedLevel-8 9.00 ± 0% 3.00 ± 0% -66.67%
JSONAllowedLevel-8 22.0 ± 0% 22.0 ± 0% +0.00%
LogfmtBaseline-8 9.00 ± 0% 3.00 ± 0% -66.67%
LogfmtDisallowedLevel-8 9.00 ± 0% 3.00 ± 0% -66.67%
LogfmtAllowedLevel-8 9.00 ± 0% 9.00 ± 0% +0.00%