Tracing library with json format, adding a "custom" attribute

So here's a small example of some logging output while using the tracing library.

{"timestamp":"2024-03-01T00:00:08.088700Z","level":"DEBUG","fields":{"message":"../cpaasd/src/framework/                EndpointRegistry.cpp(165) Dumping endpoints to: /apps/cpaasd/data/Endpoints.csv"},"target":"log"}
{"timestamp":"2024-03-01T00:00:08.180759Z","level":"DEBUG","fields":{"message":"../../common/network/CommandReactor.    cpp(104) Sending response:\nfile                      {'/apps/cpaasd/data/Endpoints.csv'}\nstatus                       {'ok'}\n"},"target":"log"}

So using error!, warn!, info! etc ... There's the fields : {message: by default. Is there a way for me to add another attribute in the logging message along with logging output?

    info!("hello");
    info!(var, msg = "hello");
//{"timestamp":"2024-03-08T05:29:03.291653Z","level":"INFO","fields":{"message":"hello"},"target":"playground"}
//{"timestamp":"2024-03-08T05:29:03.291703Z","level":"INFO","fields":{"var":1,"msg":"hello"},"target":"playground"}

code

2 Likes

Ah, very simple. It works! Thanks for your help.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.