Cosmos-sdk: Output logs as JSON format

Created on 5 Sep 2018  Â·  8Comments  Â·  Source: cosmos/cosmos-sdk

Summary

I am working on Cosmos logs monitor with ELK. It's almost work perfect except some challenges in founding a pattern to extract useful information from plain text logs, particularly multi-line logs which contain many "\n". such as "block log"

Problem Definition

It's very difficult to parse a log which is consists of multi plain text lines, particularly in following scenarios:
1, Using tcp/udp input, one log will split in to several logs.

  1. Multi cosmos-nodes, multi-line logs will mixed up.

What benefits does the SDK stand to gain by including this feature?
1, Easy parsing
2, Better performance.
3, Reducing Disc spaces for log server

Proposal


We need a better log format (JSON) than plain-text for log parsing.


For Admin Use

  • [ ] Not duplicate issue
  • [ ] Appropriate labels applied
  • [ ] Appropriate contributors tagged
  • [ ] Contributor assigned/self-assigned
good first issue help wanted

All 8 comments

For what it's worth, the Uber zap logger does this automatically and is lightning fast/low allocs, and I've had great results with it:

https://github.com/uber-go/zap

I love the zap library and have used it extensively in the past...I think this would be too much of an overhaul right now though. Ideally the log formatting (text vs JSON) should be configurable based on some parameter/config.

thanks strotter.

Ideally the log formatting (text vs JSON) should be configurable based on some parameter/config.

I agree with you. and don't put "\n" in togs when output as JSON format.

I'm concerned about the performance hit this may have. We want logs, and we want them to be cheap. I think parsing non-json will likely be faster despite being less convenient. I worry about slowing down the state machine for json encoding. (IIRC its kinda slow) This concern could be alleviated if we had some concrete benchmarks for how many log messages we expect to output per unit time, and how long JSON encoding would take.

@ValarDragon structured JSON logging is pretty standard for production systems -- tools like zap should alleviate your concerns.

Thanks for pointing that out, it does seem sufficiently fast!

parsing non-json will likely be faster despite being less convenient.

Yes, it's true if logs are simple text,
Cosmos logs are complex, and it's difficult to parse and extract useful information.
I think that each log should be a single JSON. such as: {k1:v1, k2:v2}. without "\n".
here are some references:
https://www.baeldung.com/java-log-json-output
https://logging.apache.org/log4j/2.x/manual/layouts.html#JSONLayout

I believe this is already resolved now.

Was this page helpful?
0 / 5 - 0 ratings