Configure Bitbucket Data Center Logging

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

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.

*Except Fisheye and Crucible

Summary

Bitbucket Data Center 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 throughout the day in case they reach 25MB.

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

Please note:

  • The files you are about to modify are maintained in the <Bitbucket Installation directory>, so these changes will need to be re-applied manually when the Bitbucket Data Center is upgraded. Do not copy this modified file into the new installation.
  • A Bitbucket 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.
  • If you change the location of your log files, they will no longer be included when you generate a support zip. This means you'll need to attach your logs to any support requests manually.
  • 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.

Solution

These sorts of modifications can be accomplished by editing <Bitbucket Installation Directory>/app/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>

Or

<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 into 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 that this will not change the location of search logs. It requires additional changes:

Last modified on Apr 17, 2024

Was this helpful?

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