5

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.

Ankur Chauhan
  • 1,393
  • 2
  • 17
  • 37

1 Answers1

2

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>
East2West
  • 657
  • 1
  • 6
  • 22
  • 3
    I did have that as the output and it looked fine, but outputting a simple log line makes it pretty difficult to search properly. I have noticed that if i output json and have fields such as severity, message, timestamp etc, I can get a much better time with search and aggregation in the log viewer. Is there some guidance as to what all fields are "parsed" by logging service? – Ankur Chauhan Mar 10 '16 at 05:24