Configure Bitbucket Server Logging

お困りですか?

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

コミュニティに質問

プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Fisheye および Crucible は除く

要約

Bitbucket Server holds on to atlassian-bitbucket.log for 31 days by default. Similarly, atlassian-bitbucket-access.log files are kept for 10 days and they are also rotated through the day in case they reach 25MB.

It is sometimes useful for Bitbucket Server administrators to change the number of days logs are kept or the size of those individual log files. 

注意:

  • The files you are about to modify are maintained in the <Bitbucket Server Installation> directory, so these changes will need to be re-applied manually when Bitbucket Server is upgraded. Do not copy this modified file into the new installation.
  • A Bitbucket Server restart after these changes have been made is mandatory.
  • For versions of Bitbucket prior to 7.0, the file to modify will be named logback.xml instead of logback-spring.xml.
  • ログ ファイルの場所を変更する場合、サポート zip を生成する際にログ ファイルは含まれなくなります。つまり、サポート リクエストにログを手動で添付する必要があります。
  • These changes may not take effect if another tool is already accessing the log file at the time changes are done, hence the need to perform a bitbucket restart.

ソリューション

These sorts of modifications can be accomplished by editing <Bitbucket Server Installation>/atlassian-bitbucket/WEB-INF/classes/logback-spring.xml (or logback.xml if you are using a Bitbucket version prior to 7.0).

Modify the appenders by adding / editing the maxHistory and maxFileSize attributes and also modifying the rollingPolicy class accordingly.

These are the default settings:

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

...
...
 
<appender name="bitbucket.accesslog" class="ch.qos.logback.core.rolling.RollingFileAppender">
	<encoder>
		<charset>UTF-8</charset>
		<pattern>${accesslog.format}</pattern>
	</encoder>
	<file>${log.dir}/atlassian-bitbucket-access.log</file>
	<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
		<fileNamePattern>${log.dir}/atlassian-bitbucket-access-%d.%i.log</fileNamePattern>
		<maxHistory>10</maxHistory>
		<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
			<maxFileSize>25MB</maxFileSize>
		</timeBasedFileNamingAndTriggeringPolicy>
	</rollingPolicy>
</appender>

If you want to make the atlassian-bitbucket.log rotate not only in a daily basis, but also whenever it reaches 25MB within the same day, and keep the logs from the last 31 days, you need to do these modifications to the bitbucket.application appender:

  • Modify TimeBasedRollingPolicy by SizeAndTimeBasedRollingPolicy (in line #30 by default)
  • Modify the fileNamePattern from atlassian-bitbucket-%d.log to atlassian-bitbucket-%d.%i.log (in line #31 by default)
  • Add the maxFileSize element inside the rollingPolicy element

This is a working example containing the two changes mentioned above:

<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.SizeAndTimeBasedRollingPolicy">
		<fileNamePattern>${log.dir}/atlassian-bitbucket-%d.%i.log</fileNamePattern>
		<maxHistory>31</maxHistory>
		<maxFileSize>25MB</maxFileSize>
	</rollingPolicy>
</appender>

Compressing log files:

If you want to gzip any of the logs automatically on their rotation, you could change the line above and add .gz as an extension:

<fileNamePattern>${log.dir}/atlassian-bitbucket-%d.log.gz</fileNamePattern>

または

<fileNamePattern>${log.dir}/atlassian-bitbucket-access-%d.%i.log.gz</fileNamePattern>

Modifying the output format of log messages

It is possible to adjust the output format of log messages that are written by each individual appender - such as changing the date format, or un-abbreviating the package names in each log entry.

Check out this article for more information relating to these types of modifications.

Overriding log.dir property to change the default location of Bitbucket logs

Not recommended. There are a number of downsides to this change:

  • If you change the location of your log files, they will no longer be included when you generate a support zip and interact with Atlassian Support. This means you'll need to attach your logs to any support requests manually.
  • You lose some programmatic benefit of Bitbucket's log directory validation and error messaging to console output when there are issues logging to that directory.

It's not possible to override the log.dir property easily with something as simple as an environment variable or Java argument without modifying the logback-spring.xml first. The existing property must be commented out and a new property included. Example:

<!--<define name="log.dir" class="com.atlassian.stash.internal.logback.LogDirectoryPropertyDefiner"
                                            scope="context"/>-->
<property name="log.dir" value="/path/to/logs" />

Note, this will not change the location of search logs. It requires additional changes:

最終更新日: 2024 年 2 月 13 日

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

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