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

adds the logger_name and thread_name labels for logback #108

Merged

Conversation

jeantil
Copy link
Contributor

@jeantil jeantil commented Mar 9, 2023

This is a proposal to add logger_name and thread_name as first-class labels in logback appender which fixes #107

A possible alternative with less impact but more hackish could be to include these values as members of the mdc properties ,for example:

    @Override
    protected void append(ILoggingEvent event) {
        String logLevel = event.getLevel().toString();
        ByteBuffer logLine = actualEncoder.apply(event);
        Map<String, String> mdcPropertyMap = event.getMDCPropertyMap();
        
        mdcPropertyMap.put("logback_logger_name", event.getLoggerName());
        mdcPropertyMap.put("logback_thread_name", event.getThreadName());
        
        LabelSerializer labelSerializer = LabelSerializers.threadLocal();
        appendLogLabel(labelSerializer, logLevel);
        appendMdcLogLabels(labelSerializer, mdcPropertyMap);

        logger.log(
                event.getTimeStamp(),
                0L,
                labelSerializer,
                logLine
        );
    }

@tkowalcz tkowalcz merged commit 86eeab2 into tkowalcz:master Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logger and thread name labels for logback appender.
2 participants