Re:Tagged Logging in Go
by jzelinskie on Thursday February 12, 2015 @11:50AM
(#9039727)
Wouldn't the signature of the tagged logging function be better if it was something like:
This way you could easily add tags without having to explicitly allocate a []string whenever you wanted to change them.
[ Parent
| on HN ]
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.
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 blakecaldwell on Thursday February 12, 2015 @04:56PM
(#9041629)
It's more consistent with the printf-style counterparts:
func (logger *LoggerImpl) DebugWithTagsf(tags []string, fmt string, args ...interface{}) {
logger.logwithformat(DEBUG, tags, fmt, args...)
}I think that function is meant to set the debug level, not to produce a log output...