Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log format for google cloud logging

I am try to figure out if it's possible to use log4j appender to output messages (log lines) in my google container engine application so that they can be properly handled by the google cloud logging agent that runs of the box.

Is there a place where the log format is documented or something similar.

like image 542
Ankur Chauhan Avatar asked Oct 30 '22 08:10

Ankur Chauhan


1 Answers

All you need is to write your logs to stdout in container. All containers in kubernetes are listened by another container fluentd for STDOUT. Simply put consolappender to the config and logs will appear in

<configuration>

  <!--Daily rolling file appender-->
  <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <File>target/surefire-reports/blah-logback.log</File>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <FileNamePattern>blah-logback.log.%d{yyyy-MM-dd}</FileNamePattern>    
    </rollingPolicy>
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
      <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%-10.10thread] %logger{36} - %msg%n%rEx</Pattern>
      <immediateFlush>true</immediateFlush>
    </encoder>
  </appender>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%msg%n</pattern>
    </encoder>
  </appender>
  <root level="INFO">
    <appender-ref ref="FILE"/>  
    <appender-ref ref="STDOUT"/>
  </root>
</configuration>
like image 79
East2West Avatar answered Nov 15 '22 03:11

East2West