How to change the Bitbucket application log format

Still need help?

The Atlassian Community is here for you.

Ask the community

The content on this page relates to platforms which are supported; however, the content is out of scope of our Atlassian Support Offerings. Consequently, Atlassian cannot guarantee support. Please be aware that this material is provided for your information only and you may use it at your own risk.

Purpose

If standard log formatting is insufficient for your business needs you need to may need to modify the default. For instance, you may want to change the timestamp to something like this. 

2016-11-07T18:17:18,889 UTC DEBUG [Caesium-1-4]  c.a.b.s.i.cluster.ClusterJobRunner Job has started: bd25ec43-c982-430d-a5ef-249ea5959c24

Alternatively, you may wish to have the full package name present in the log lines for the purposes of understanding which logger is outputting a given log entry. (The default behavior is to truncate the package listing to 36 characters.)

For example - note how the package names below are no longer abbreviated "c.a.b.i.boot.log.BuildInfoLogger":

2020-09-08 07:53:45,084 INFO  [main]  com.atlassian.bitbucket.internal.boot.log.BuildInfoLogger Starting Bitbucket 7.4.0 (204e35a built on Tue Jul 07 14:31:59 NZST 2020)

Solution

This can be accomplished by modifying the logback XML file located in:

  • Prior to Bitbucket 7.0:
    • BITBUCKET_INSTALLATION/atlassian-bitbucket/WEB-INF/classes/logback.xml
  • Bitbucket 7.0 or greater:
    • BITBUCKET_INSTALLATION/app/WEB-INF/classes/logback-spring.xml

Example Modifications


Change timestamp format...

Change the "pattern" for the logger from:

<appender name="bitbucket.application" class="ch.qos.logback.core.rolling.RollingFileAppender">
                <encoder>
                    <charset>UTF-8</charset>
                    <pattern>${log.format}</pattern>
                </encoder>
                <file>${log.dir}/atlassian-bitbucket.log</file>
                <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                    <fileNamePattern>${log.dir}/atlassian-bitbucket-%d.log</fileNamePattern>
                    <maxHistory>31</maxHistory>
                </rollingPolicy>
            </appender>

To something like this: 

<appender name="bitbucket.application" class="ch.qos.logback.core.rolling.RollingFileAppender">
                <encoder>
                    <charset>UTF-8</charset>
                    <pattern>%d{"yyyy-MM-dd'T'HH:mm:ss,SSS zzz"} %-5level [%thread] %request %logger{36} %m%n%eThrowable</pattern>
                </encoder>
                <file>${log.dir}/atlassian-bitbucket.log</file>
                <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                    <fileNamePattern>${log.dir}/atlassian-bitbucket-%d.log</fileNamePattern>
                    <maxHistory>31</maxHistory>
                </rollingPolicy>
            </appender>
Show full package names...

Change the "pattern" for the logger from:

<appender name="bitbucket.application" class="ch.qos.logback.core.rolling.RollingFileAppender">
                <encoder>
                    <charset>UTF-8</charset>
                    <pattern>${log.format}</pattern>
                </encoder>
                <file>${log.dir}/atlassian-bitbucket.log</file>
                <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                    <fileNamePattern>${log.dir}/atlassian-bitbucket-%d.log</fileNamePattern>
                    <maxHistory>31</maxHistory>
                </rollingPolicy>
            </appender>

To something like this: 

<appender name="bitbucket.application" class="ch.qos.logback.core.rolling.RollingFileAppender">
                <encoder>
                    <charset>UTF-8</charset>
                    <pattern>%date %-5level [%thread] %request %logger %m%n%eThrowable</pattern>
                </encoder>
                <file>${log.dir}/atlassian-bitbucket.log</file>
                <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                    <fileNamePattern>${log.dir}/atlassian-bitbucket-%d.log</fileNamePattern>
                    <maxHistory>31</maxHistory>
                </rollingPolicy>
            </appender>


Log Patterns

For reference, here are the logback patterns used by the following Bitbucket log types:  

The following patterns were taken from Bitbucket version 7.10.0 on   - your version's patterns may vary from these, and the ability to successfully customize these patterns will vary based on your version of Bitbucket.

It's recommended that you back up the default log pattern value before making any changes here.

  • Application log (atlassian-bitbucket.log):
    • %date %-5level [%thread] %request %logger{36} %m%n%eThrowable
  • Profiler log (atlassian-bitbucket-profiler.log):
    • %date | %thread | %dX{a-request-id} | %dX{a-username} | %dX{a-session-id}%n%m%n
  • Access log (atlassian-bitbucket-access.log):
    • %dX{a-remote-address} | %dX{a-protocol} | %m%dX{a-request-id} | %dX{a-username} | %date | %dX{a-request-action} | %dX{a-request-details} | %dX{a-status-code} | %dX{a-request-bytes-read} | %dX{a-response-bytes-written} | %dX{a-request-labels} | %dX{a-request-time} | %dX{a-session-id} | %n

For more information on setting up custom formats for these log appenders, it's recommended to review the full pattern information located in this Apache Log4j knowledge article and the official logback pattern documentation.

Please note that our team is not able to support any issues that arise as a result of changes to this file. Fixing any issues related to these changes are outside the scope of our support offerings. Assistance for these types of issues will be limited to only restoring your team's configuration back to the default values/behavior.

In addition - this change will need to applied after each upgrade, as the contents of these logback xml files will be the default values in the new installation directory.

Last modified on Feb 12, 2021

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.