-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logging option to format sink as JSON #2869
Comments
We can customize only a few things about the sink logger, things which are exported here: https://golang.org/pkg/log/ -- so basically, the writer, and some "flags." The best way to do this would be to make a log writer module that wraps its output in a JSON string. Depending on how this is implemented, it would have some cost in terms of performance. I bet it could be done without significant buffering and with using pools if necessary, though. |
If possible, it would of course be nice if we could also extract the time and level information. However, I had a short look at the |
Correct: since writers only get an array of bytes to work with, there has to be some parsing (hence the perf overhead). I am also not 100% sure we can guarantee that each call to Write() correlates 1:1 with a log entry. From looking at the implementation of In any case, perhaps we can rest on the assumption that a single call to Write() consists of a single and complete log entry. If we assume that, then this problem is easier, since we can just parse out the timestamp. Level information is definitely not structured -- there's absolutely no guarantee that the text within the Again, just adds performance overhead. But if that's OK, then I guess we can take a stab at it... Want to give it a try? |
@mholt I think this is essentially done? https://caddyserver.com/docs/json/logging/logs/encoder/json/ |
@francislavoie No, unfortunately that's not the sink log. The sink is just an io.Writer and that's about all right now because of the reasons mentioned above. There's not much we can do without structured log messages. |
That PR only formats http.Server logs as JSON; it doesn't change the whole standard lib's default logger to JSON. We can probably do that pretty easily following a similar pattern. Do we feel that is the right thing to do? |
Mmm, guess we'll close this and see if we get any other requests/complaints about sink log formats. |
1. What would you like to have changed?
Currently, the
sink
logger just outputs plain text:It would be nice if there was an option where this could be encapsulated in a simple JSON structure, like
2. Why is this feature a useful, necessary, and/or important addition to this project?
Makes it easier to send the log to Elastic (and probably also similar logging tools)
3. What alternatives are there, or what are you doing in the meantime to work around the lack of this feature?
It's possible to manually configure log line patterns in Elastic, but it's more effort and not very easy / user-friendly to do
4. Please link to any relevant issues, pull requests, or other discussions.
--
The text was updated successfully, but these errors were encountered: