Logging in a plugin for Bitbucket server?

I’m having trouble configuring a logger during plugin development for Bitbucket server.
I’m not getting any output to neither the console nor a file.

I have a src/aps/log4j.properties like below,

log4j.rootLogger=INFO, console, filelog

log4j.appender.console.layout.ConversionPattern=%d{HH:mm:ss} %5p [%t] - %m%n

log4j.appender.filelog.layout.ConversionPattern=%d{HH:mm:ss} %5p [%t] - %m%n
# Plugin logging
log4j.logger.com.company.impl = DEBUG, console, filelog

and in the pom.xml (along with dependencies for both slf4j-api, slf4j-simple and log4j under project.build.plugins.plugin.configuation I have


And finally in my JavaClass I have sth like:

package com.company.impl;
public class myclass {
    private static final Logger log = LoggerFactory.getLogger(myclass.class);

    public myclass(){

It feels like I’m missing something incredibly basic, but I can’t put my finger on it and “Bitbucket log4j.properties” is not giving me anything onhere or Google.

Pretty sure bitbucket uses Logback, not log4j?

That’s great! I’m not married to log4j.

How do I get logging with logback?

I tried adding the following to a src/main/resources/logback.xml:

<?xml version="1.0" encoding="UTF-8"?>
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36}
                %X{sourceThread} - %msg%n</Pattern>
    <appender name="filelog" class="ch.qos.logback.core.FileAppender">
            <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
    <!-- default is DEBUG -->
    <root level="DEBUG">
        <appender-ref ref="console" />
        <appender-ref ref="filelog" />

But to no avail :frowning_face:

You can place log4j.properties files in src/main/resources folder and the below dependency

log4j log4j 1.2.17

in your pom.xml file. It worked for me.

To enable debugging of your Bitbucket plugin using Logback:

  1. Create the directory src/test/resources/bitbucket-home
  2. Create a file src/test/resources/bitbucket-home/logback.xml [1] and add logger elements as desired, eg I have:
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
    <!--When starting up Elasticsearch in-process (for dev):
    We need to set the logging level of org.elasticsearch.bootstrap to ERROR because otherwise
    it will log a misleading warning (with a stacktrace) about JNA being unavailable.-->
    <logger name="org.elasticsearch.bootstrap" level="ERROR"/>
    <logger name="com.declarativesystems" level="DEBUG"/>

        <appender-ref ref="console"/>
  1. atlas-clean && atlas-run as normal - you will now be able to see the logs from your plugin on the console.

I’m using Bitbucket 5.16 which uses Logback. I couldn’t get log4j working at all:

Log4j 1.2 in pom.xml causes my whole plugin to fail:

Caused by: org.osgi.framework.BundleException: Unresolved constraint in bundle com.declarativesystems.bitbucket.credentialscanner [126]: Unable to resolve 126.0: missing requirement [126.0] osgi.wiring.package; (osgi.wiring.package=com.ibm.uvm.tools)
        at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3974)
        ... 22 common frames omitted

Using the OSGi version


Doesn’t break anything but doesn’t give any debug output either


[1] This is a homedir override, as discussed in https://ecosystem.atlassian.net/projects/AMPS/issues/AMPS-1505 … I would never have found this workaround without this ticket!

1 Like