Tagged Logging in Go
blog.fogcreek.com
blog.fogcreek.com
Unfortunately Go doesn't have thread-local storage, so that feature may not be feasable. (Except through ugly hacks: https://github.com/jtolds/gls)
DebugWithTags(message string, tags ...string)
This way you could easily add tags without having to explicitly allocate a []string whenever you wanted to change them.With that said, i really do wish Go supported `DebugWithTags(tags ...string, message string)` syntax. I've had so many cases where i wanted to use something similar.
Though, i would agree that the order should be switched. Eg, `DebugWithTags(string, []string, ...interface{})`
func (logger *LoggerImpl) DebugWithTagsf(tags []string, fmt string, args ...interface{}) {
logger.logwithformat(DEBUG, tags, fmt, args...)
}Easy to get rolling, easy to make chained loggers, and can do JSON in production or pretty colors when in dev environment.
I have created a desktop app and use 'logrus' for logging locally and have created a 'hook' to send logs to the server. Works pretty neat!
here's a smaller version of the problem, notice how fillFoo() will have to wait to push to the buffer. https://gist.github.com/Omie/52add99f6685dcb340a1
there's also a similar problem (how they solved it) described here: http://pivotallabs.com/a-concurrent-ring-buffer-for-go/
https://godoc.org/gopkg.in/inconshreveable/log15.v2 https://github.com/inconshreveable/log15