How to change the Bitbucket application log format

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

The content on this page relates to platforms which are supported, however are 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.

目的

If standard log formatting is insufficient for your business needs you need to may need to modify the 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)


ソリューション

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
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>

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

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.






最終更新日 2020 年 9 月 7 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.