Re:Tagged Logging in Go
by tveita on Thursday February 12, 2015 @11:28AM
(#9039525)
SLF4J has two ways to do "tagged logging": markers that are passed per-call, and a thread-local mapped diagnostic context (MDC). The latter is useful because you can set it for an entire request and have it included even for code that isn't explicitly aware of e.g. accounts.
Unfortunately Go doesn't have thread-local storage, so that feature may not be feasable. (Except through ugly hacks: https://github.com/jtolds/gls)
Re:Tagged Logging in Go
by fizzbatter on Thursday February 12, 2015 @02:41PM
(#9040890)
Perhaps it depends on how much content you're putting into the message, normally? Eg, big multi-line strings, followed by more args at the end, is not a syntax i personally prefer.
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.
Re:Tagged Logging in Go
by kornish on Thursday February 12, 2015 @02:56PM
(#9040987)
For the record, if the last argument of a Golang function is variadic, you can still pass an array to it - you just have to transform the array into variadic args by appending `...` to it. So adopting the type signature above could give you the best of both worlds - the ability to use one-off tag combinations inline, but also the ability to pass predefined arrays of tags.
Re:Tagged Logging in Go
by fizzbatter on Thursday February 12, 2015 @03:00PM
(#9041010)
I hadn't actually seen their Code, it looks like they actually use `DebugWithTags([]string, string, ...interface{})`. So the `...interface{}` is the blocker here, as it appears in every logger that they have.
Though, i would agree that the order should be switched. Eg, `DebugWithTags(string, []string, ...interface{})`
Re:Tagged Logging in Go
by rakoo on Thursday February 12, 2015 @11:40AM
(#9039656)
It seems to me FogCreek's tagged logging is a simpler version of logging than what logrus provides and what should actually always be the case: you don't log strings, you log structs with multiple fields and possibly multiple values for each field. It's much more versatile and seems to be enough for most if not all use cases, as logstash shows (really, at some points it starts being much easier to just log a JSON dict and stop fiddling with fancy regexps for analytics)
Re:Tagged Logging in Go
by Omie6541 on Thursday February 12, 2015 @05:39PM
(#9041851)
Please correct me if I have got this wrong or missed some code piece but you are pushing log records to a buffered channel (incomingChannel) without making sure that it has some space left. When that buffer of 2048 gets full, all the next requests are going to get blocked. Even if you call .log() in the background, there will be number of goroutines waiting to get their turn which will lead the system to a state where you have no idea what is pending and where.
Unfortunately Go doesn't have thread-local storage, so that feature may not be feasable. (Except through ugly hacks: https://github.com/jtolds/gls)
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{})`
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