Skip to content
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

Add use of structured arguments #86

Closed
Jordan-Negreiros opened this issue Dec 23, 2022 · 1 comment
Closed

Add use of structured arguments #86

Jordan-Negreiros opened this issue Dec 23, 2022 · 1 comment
Assignees
Milestone

Comments

@Jordan-Negreiros
Copy link

Hello, It would be very interesting to use the kv method to add new fields to the logs as in the example below:

code:

import static net.logstash.logback.argument.StructuredArguments.kv;

String orderId = "123";
String status = "NEW";
log.info("Order saved", kv("orderId", orderId), kv("status", status)); 

result:

{
    "@timestamp": "2019-04-17T18:29:14.079+02:00",
    "@version": "1",
    "message": "Order saved",
    "logger_name": "MyApplication",
    "thread_name": "main",
    "level": "INFO",
    "level_value": 20000,
    "orderId": "123",
    "status": "NEW"
}
osiegmar added a commit that referenced this issue Dec 23, 2022
@osiegmar
Copy link
Owner

Thanks for bringing this up! As this library has no dependencies to logstash, support for their kv is not possible. But with 82b080f I added support for key value pairs of SLF4J 2.0.0:

org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger("my logger");

String orderId = "123";
String status = "NEW";

log.atInfo().setMessage("Order saved")
    .addKeyValue("orderId", orderId)
    .addKeyValue("status", status)
    .log();

This will be part of version 5.0.0 of this library.

@osiegmar osiegmar self-assigned this Dec 23, 2022
@osiegmar osiegmar added this to the 5.0.0 milestone Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants