log4rs
log4rs copied to clipboard
Support formatting JSON
Currently, I don't believe if you use the JSON encoder, you can format it, it would be awesome if this was the case.
It could possibly look something like this
refresh_rate: 30 seconds
appenders:
stdout:
kind: console
encoder:
kind: json
pattern: "{d(%Y-%m-%d %H:%M:%S)} - {m}{t}{T}{n}"
root:
level: info
appenders:
- stdout
@calvinbrown085 still interested in this?
I am, but my time may be odd the next couple week so if someone wants to pick it up that's fine.
It will be better to support add custom key when using JSON encoder, it will be able to link Filebeat and ELK Stack directly for analysis.
- Thanks. Alex
@Ruijuan-Cao can you give an example?
Firstly, thanks for your reply, and I'm very sorry to see this so late. For example, I need a new customized key-value "type-xxx“ in log for analysis, I didn't find any guidance document to add a new key, so I tried to pretend like that by this
let str = "hello,test\",\"type\":\"xxx";
info!(target:"app", "{}", str);
but all msg including double quotation marks is treated as message by escape character. And the output is shown below:
{
"time":"2020-06-04T20:59:19.946833+08:00",
"message":"hello, test\",\"type\":\"xxx",
"module_path":"spot::statics::clog",
...
}
but what I want is like that:
{
"time":"2020-06-04T20:59:19.946833+08:00",
"message":"hello, test",
"type":"xxx",
"module_path":"spot::statics::clog",
...
}
So, I want to know if there is any way to do this.(Maybe this is a bit stupid requirement🤦♀️) Thank you very much.
Sorry, been away for a while. I still think this would be a great thing to have. Everyone else still interested @estk @Ruijuan-Cao ?
Any update on this feature?
@caoruijuan13 the log
crate does not have a notion of structured logging, I would suggest that you use an empty formatter and serialize the json output yourself. Using a separate log target you can filter out your custom serialized logs to a separate appender.
Hi! I'm finding evidence that json formatting is supported in closed issues and here, yet there is no support for that in docs and code from stackoverflow itself isn't working.