Skip to content

Trace support for Java util logging when logging is called from SLF4j #78

@NickWemekamp

Description

@NickWemekamp

Hi,

I'm considering to add a feature that will add trace support for JUL when JUL is called from SLF4J. This can be done using the MDC.getCopyOfContextMap method from SLF4j. This is useful for javaee projects that want to keep using the logging framework of their application server (which is often JUL, unfortunately).

Below is a code snippet that shows how this could be implemented

        Map<String, String> copyOfContextMap = MDC.getCopyOfContextMap();

        copyOfContextMap.forEach((k, v) -> {
            System.out.println("key: " + k + ", value: " + v);
        });

        System.out.println(copyOfContextMap.get("trace.id"));
        System.out.println(copyOfContextMap.get("transaction.id"));

I can implement this by making a new formatter e.g. JuLSlf4jEcsFormatter that extends the JuLEcsFormatter, or I can edit the current JuLEcs formatter.

Which solution do you guys prefer? I prefer the last one but wanted to be sure before I write the code :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions