print: return if string would be hidden by current log level
This effectively makes printing a no-op when the configured log level
would stop it from being printed anyways.
This speeds up calls to these functions significantly, shown by the
benchmarks this commit also adds:
cpu: Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz
BenchmarkDebugfLogLevelINFO-12 55498520 18.44 ns/op 0 B/op 0 allocs/op
BenchmarkDebugfLogLevelDEBUG-12 1644188 656.5 ns/op 408 B/op 8 allocs/op
logger: store level locally in obj
Allows quickly reading the current level without more function calls.
A map is used to map (heh..) the loglevel to an integer that can be
compared directly to the print's "level".
logger: use rwlock
The vast majority of the time this is reading and not setting anything,
so RLock should help in cases where there are concurrent calls to logger
logger: drop prefix param from print methods
This will need to be handled later when I move other projects to use
this module, perhaps with an option to set a prefix (and only print it
when set), but for now it's not needed
logger: allow disabling timestamps off
Add initial implementation
Basically just copy/pasted from