uber-go / zap

Blazing fast, structured, leveled logging in Go.
https://pkg.go.dev/go.uber.org/zap
MIT License
21.72k stars 1.42k forks source link

Request for comments about a LTSV encoder #253

Closed hnakamur closed 7 years ago

hnakamur commented 7 years ago

First of all, thanks for a nice logging library for Go!

I created a Labeled Tab-separated Values (LTSV) encoder for zap. https://github.com/hnakamur/zap-ltsv

Could you take a look and give some comments to issues?

Thanks for your time in advance.

akshayjshah commented 7 years ago

Awesome - I'm glad to hear that zap was useful for you! I haven't worked with the LTSV encoding before - from the docs, I can see that it's accepted by a variety of logging tools. Are you aware of any common software that emits LTSV logs by default?

I'm going to defer this until after the 1.0 release, since the encoder API is changing (though nearly all the code you have should still work, it'll just require some find&replace updates). Once we've released 1.0, I'll take a closer look at your code and figure out whether we should include it in zap itself.

hnakamur commented 7 years ago

Thanks for your kind words. I don't know anything that emits LTSV logs by default config. However it is easy to setup Apache or nginx configs to emit LTSV logs.

Apache config example:

LogFormat "host:%h\tident:%l\tuser:%u\ttime:%t\treq:%r\tstatus:%>s\tsize:%b\treferer:\%{Referer}i\tua:%{User-Agent}i" combined_ltsv

nginx config example:

log_format ltsv "time:$time_local"
                "\thost:$remote_addr"
                "\tforwardedfor:$http_x_forwarded_for"
                "\treq:$request"
                "\tstatus:$status"
                "\tsize:$body_bytes_sent"
                "\treferer:$http_referer"
                "\tua:$http_user_agent"
                "\treqtime:$request_time"
                "\tcache:$upstream_http_x_cache"
                "\truntime:$upstream_http_x_runtime"
                "\tvhost:$host";

Also, with Fluentd | Open Source Data Collector | Unified Logging Layer, you can convert logs in other formats to LTSV using Text Formatter Overview | Fluentd.

I understand that you defer this pull request after zap 1.0 release. I'll update the LTSV encoder for API changes.

Thanks!

akshayjshah commented 7 years ago

Hey @hnakamur - the encoder APIs are stable now, so this is a good time to update your encoder. Since I'm not familiar with this encoding and we don't use it internally, let's keep it in a separate package.

330 may be relevant to you, though.

akshayjshah commented 7 years ago

Closing this issue, since there's no active work to do in zap.

hnakamur commented 7 years ago

Sorry for being late. I noticed your mention yesterday. I've updated the LTSV encoder at https://github.com/hnakamur/zap-ltsv/pull/5. Thanks again for a great logging library!