GKE & Stackdriver: Java logback logging format?

后端 未结 2 900
我寻月下人不归
我寻月下人不归 2020-12-01 19:01

I have a project running Java in a docker image on Kubernetes. Logs are automatically ingested by the fluentd agent and end up in Stackdriver.

However, the format of

2条回答
  •  一生所求
    2020-12-01 19:24

    Google has provided a logback appender for Stackdriver, I have enhanced it abit to include the thread name in the logging label, so that it can be searched more easily.

    pom.xml

    
            com.google.cloud
            google-cloud-logging-logback
            0.116.0-alpha
        
    

    logback-spring.xml

        
        
            clicktrade.log
            com.jimmy.clicktrade.arch.CommonEnhancer
            WARN
        
        
            
        
    
    

    CommonEnhancer.java

        public class CommonEnhancer implements LoggingEventEnhancer {
    
        @Override
        public void enhanceLogEntry(Builder builder, ILoggingEvent e) {
            builder.addLabel("thread", e.getThreadName());
        }
    
    }
    

    Surprisingly, the logback appender in MVN repository doesn't align with the github repo source code. I need to dig into the JAR source code for that. The latest version is 0.116.0-alpha, it seems it has version 0.120 in Github

    https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-contrib/google-cloud-logging-logback

提交回复
热议问题