All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vlkan.log4j2.logstash.layout.resolver.SourceLineNumberResolver Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
package com.vlkan.log4j2.logstash.layout.resolver;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.LongNode;
import org.apache.logging.log4j.core.LogEvent;

public class SourceLineNumberResolver implements TemplateResolver {

    private static final SourceLineNumberResolver INSTANCE = new SourceLineNumberResolver();

    private SourceLineNumberResolver() {
        // Do nothing.
    }

    public static SourceLineNumberResolver getInstance() {
        return INSTANCE;
    }

    @Override
    public String getName() {
        return "sourceLineNumber";
    }

    @Override
    public JsonNode resolve(TemplateResolverContext context, LogEvent logEvent) {
        if (!context.isLocationInfoEnabled() || logEvent.getSource() == null) {
            return null;
        }
        int sourceLineNumber = logEvent.getSource().getLineNumber();
        return new LongNode(sourceLineNumber);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy