Logging

Introduction

You can turn on additional logging to diagnose and troubleshoot issues with the GoCD server and agent.

Log location

To change where the GoCD server logs or GoCD agent logs are stored, use the system properties gocd.server.log.dir and gocd.agent.log.dir respectively. Refer to the system properties documentation to find out how to set the system property on the gocd server or agent.

Note: The system property deals with configuring the log location for the GoCD server or agent related logs and not the plugin logs.

GoCD Server

To turn on additional logging on the GoCD server, you must:

  • create/edit the file CONFIG_DIR/logback-include.xml. The config directory is typically /etc/go on Linux and C:\Program Files\Go Server\config on Windows. See the section Log configuration syntax for the log configuration syntax.

The table below describes the various loggers that can be configured with the server:

LoggerAdditivityDescription
com.thoughtworks.go.server.RailstrueThis will enable debugging the rails application server.
com.thoughtworks.studios.shinetrueThis will enable debugging of GoCD’s test report analysis that is shown on the “Tests” tab of the stage details page on the server.
org.springframeworktrueThis will enable debugging of the spring framework.
org.apache.velocitytrueThis will enable debugging of some of the server view templates.
org.eclipse.jetty.server.RequestLogfalseThis will enable http request logging to help diagnose and identify slow page render times.
PerformanceLoggerfalseThis will output performance debug logs for 3 key background jobs: scheduling, material updates, work assignment. It is recommended that you send these logs to a different file using an appender.
com.microsoft.tfs.coretrueThis will turn on debugging for the underlying Microsoft Team Foundation Server library used by GoCD.
com.thoughtworks.go.tfssdk14trueThis will turn on debugging for the GoCD wrapper around Microsoft TFS library.
com.thoughtworks.go.domain.materials.dependencytrueTurn on logging for materials of type dependency.
com.thoughtworks.go.domain.materials.gittrueTurn on logging for materials of type git.
com.thoughtworks.go.domain.materials.mercurialtrueTurn on logging for materials of type mercurial.
com.thoughtworks.go.domain.materials.packagematerialtrueTurn on logging for materials of type packagematerial.
com.thoughtworks.go.domain.materials.perforcetrueTurn on logging for materials of type perforce.
com.thoughtworks.go.domain.materials.scmtrueTurn on logging for materials of type scm.
com.thoughtworks.go.domain.materials.svntrueTurn on logging for materials of type svn.
com.thoughtworks.go.domain.materials.tfstrueTurn on logging for materials of type tfs.

GoCD Agent

To turn on additional logging on the GoCD agent, you must:

  • create/edit the file CONFIG_DIR/agent-logback-include.xml. The config directory is typically /var/lib/go-agent/config on Linux and C:\Program Files\Go Agent\config on Windows. See the section Log configuration syntax for the log configuration syntax.

The table below describes the various loggers that can be configured with the server:

LoggerAdditivityDescription
org.springframeworktrueThis will enable debugging of the spring framework.
org.apache.http.wiretrueThis will enable debugging of http connections between the agent and server.
com.microsoft.tfs.coretrueThis will turn on debugging for the underlying Microsoft Team Foundation Server library used by GoCD.
com.thoughtworks.go.tfssdk14trueThis will turn on debugging for the GoCD wrapper around Microsoft TFS library.
com.thoughtworks.go.domain.materials.dependencytrueTurn on logging for materials of type dependency.
com.thoughtworks.go.domain.materials.gittrueTurn on logging for materials of type git.
com.thoughtworks.go.domain.materials.mercurialtrueTurn on logging for materials of type mercurial.
com.thoughtworks.go.domain.materials.packagematerialtrueTurn on logging for materials of type packagematerial.
com.thoughtworks.go.domain.materials.perforcetrueTurn on logging for materials of type perforce.
com.thoughtworks.go.domain.materials.scmtrueTurn on logging for materials of type scm.
com.thoughtworks.go.domain.materials.svntrueTurn on logging for materials of type svn.
com.thoughtworks.go.domain.materials.tfstrueTurn on logging for materials of type tfs.

Log configuration syntax

To configure logging, you can specify the configuration below. You must tweak the <logger /> and optionally <appender /> to write to specific log files. You can read more about logback configuration in the logback configuration documentation. This file will be reloaded every 5 seconds, so a restart of the GoCD server or agent is not necessary.

Note: It is recommended that you do not set the log level to DEBUG or TRACE for long periods of time since this can significantly affect performance.

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- since this file is included in another file, use `<included />` and not `<configuration />` -->
  3. <included>
  4. <!-- send logs from `com.example.component-b` to the default log file (`go-agent.log` or `go-sever.log`) -->
  5. <logger name="com.example.component-b" level="DEBUG" />
  6. <!--
  7. Uncomment the lines below to redirect specific logs to a file different from the default log file (`go-agent.log` or `go-sever.log`)
  8. The configuration below will:
  9. - rollover daily;
  10. - each log will will be at most 10MB, keep 10 days worth of history, but at most 512 MB
  11. -->
  12. <!--
  13. <appender name="my-appender" class="ch.qos.logback.core.rolling.RollingFileAppender">
  14. <file>logs/example.log</file>
  15. <encoder>
  16. <pattern>%date{ISO8601} %-5level [%thread] %logger{0}:%line - %msg%n</pattern>
  17. </encoder>
  18. <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
  19. <fileNamePattern>logs/example.log.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
  20. <maxFileSize>10 MB</maxFileSize>
  21. <maxHistory>10</maxHistory>
  22. <totalSizeCap>512 MB</totalSizeCap>
  23. </rollingPolicy>
  24. </appender>
  25. <logger name="com.example.component-a" level="DEBUG">
  26. <appender-ref ref="my-appender" />
  27. </logger>
  28. -->
  29. </included>

Example: Enable web-request logs

To turn on web request logs, add below content to logback-include.xml.

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <included>
  3. <appender name="web-request-appender" class="ch.qos.logback.core.rolling.RollingFileAppender">
  4. <file>logs/web-requests.log</file>
  5. <!-- Use `C:\Program Files\Go Server\logs\` on windows and `~/Library/Application Support/Go Server/logs/` on Mac OS for log directory path. -->
  6. <encoder>
  7. <pattern>%date{ISO8601} %-5level [%thread] %logger{0}:%line - %msg%n</pattern>
  8. </encoder>
  9. <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
  10. <fileNamePattern>logs/web-requests.log.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
  11. <!-- Use `C:\Program Files\Go Server\logs\` on windows and `~/Library/Application Support/Go Server/logs/` on Mac OS for log directory path. -->
  12. <maxFileSize>10 MB</maxFileSize>
  13. <maxHistory>10</maxHistory>
  14. <totalSizeCap>512 MB</totalSizeCap>
  15. </rollingPolicy>
  16. </appender>
  17. <logger name="org.eclipse.jetty.server.RequestLog" level="DEBUG" additivity="false">
  18. <appender-ref ref="web-request-appender" />
  19. </logger>
  20. </included>

Advanced logging features

If you’d like to send log events to a log aggregator service (like logstash, graylog, splunk) of your choice, you may require additional configuration to be performed:

  • ensure that the relevant java libraries along with their dependencies are present in the libs directory, relative to the working directory of the GoCD server or agent process. The working directory is usually /var/lib/go-{server,agent} on linux, and C:\Program Files\Go {Server,Agent} on windows.
  • configure appenders and encoders in the relevant logback-include.xml file for your agent or server

Example logstash setup

For e.g. to send logs to logstash (using logstash-logback-encoder) one would need to perform the following:

  • download all logstash-logback-encoder jars and dependencies into libs dir:
    • logstash-logback-encoder-4.11.jar
    • jackson-databind-2.9.1.jar
    • jackson-annotations-2.9.1.jar
    • jackson-core-2.9.1.jar

Then follow the instructions on the README to configure your logback-include.xml to setup relevant appenders and encoders:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <included>
  3. <!-- see https://github.com/logstash/logstash-logback-encoder for more examples and configuration -->
  4. <appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
  5. <destination>127.0.0.1:4560</destination>
  6. <encoder class="net.logstash.logback.encoder.LogstashEncoder" />
  7. </appender>
  8. <root level="info">
  9. <appender-ref ref="stash" />
  10. </root>
  11. </included>

Override Existing logback.xml

If you’d like to completely override the packaged logback.xml, create a CONFIG_DIR\logback.xml file. If such a file is present, GoCD will use the loggers and file appender provided in the file for logging. You can read more about logback configuration in the logback configuration documentation

The following is a sample logback.xml users can use to override logging for GoCD root logger. The example uses a user defined directory for writing logs.

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3. <appender name="CustomFileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
  4. <file>logs/production_server/gocd-server.log</file>
  5. <encoder>
  6. <pattern>
  7. %date{ISO8601} %-5level [%thread] %logger{0}:%line - %msg%n
  8. </pattern>
  9. </encoder>
  10. <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
  11. <fileNamePattern>logs/production_server/gocd-server.log.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
  12. <maxFileSize>10 MB</maxFileSize>
  13. <maxHistory>50</maxHistory>
  14. <totalSizeCap>512 MB</totalSizeCap>
  15. </rollingPolicy>
  16. </appender>
  17. <root level="WARN">
  18. <appender-ref ref="CustomFileAppender"/>
  19. </root>
  20. </configuration>
  • Please note while overriding the logging for your GoCD server, redirect all logs to appropriate files in order to avoid any loss of logs.

Example gelf setup

Another example setup using GELF (Graylog Extended Log Format) using logback-gelf:

Download logback-gelf-1.1.0.jar and place it in libs directory. On typical linux server, that can be done with

  1. wget "http://repo1.maven.org/maven2/de/siegmar/logback-gelf/1.1.0/logback-gelf-1.1.0.jar" -O /var/lib/go-server/libs/logback-gelf-1.1.0.jar

Configure logback-include.xml with any of the gelf appenders as defined on project documentation: An example logging over UDP could look like this:

  1. <included>
  2. <appender name="GELF" class="de.siegmar.logbackgelf.GelfUdpAppender">
  3. <graylogHost>graylog.mycompany.com</graylogHost>
  4. <graylogPort>12201</graylogPort>
  5. <layout class="de.siegmar.logbackgelf.GelfLayout">
  6. <includeRawMessage>false</includeRawMessage>
  7. <includeMarker>true</includeMarker>
  8. <includeMdcData>true</includeMdcData>
  9. <includeCallerData>false</includeCallerData>
  10. <includeRootCauseData>false</includeRootCauseData>
  11. <includeLevelName>false</includeLevelName>
  12. <shortPatternLayout class="ch.qos.logback.classic.PatternLayout">
  13. <pattern>%m%nopex</pattern>
  14. </shortPatternLayout>
  15. <fullPatternLayout class="ch.qos.logback.classic.PatternLayout">
  16. <pattern>%m</pattern>
  17. </fullPatternLayout>
  18. <staticField>application:go-server</staticField>
  19. <staticField>environment:production</staticField>
  20. </layout>
  21. </appender>
  22. <root>
  23. <appender-ref ref="GELF"/>
  24. </root>
  25. </included>