Logging to atlassian-confluence.log with log4j from plug-in running Confluence 7.0.1 from the SDK

Hello , Hi

When using atlas-run the default for the app is to log to console, that is quite ok in most cases, however in the land of builds/infra you generally want to log to a file which you can then extract as artifact.

to achieve that, you need to update your plugin pom file as follow

<plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>confluence-maven-plugin</artifactId>
                <version>${amps.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <containerId>${containerId}</containerId>
                    <jvmArgs>${jvm.args}</jvmArgs>
                    <productVersion>${confluence.version}</productVersion>
                    <productDataVersion>${confluence.data.version}</productDataVersion>
                    <!-- log ouput -->
                    <output>${project.build.directory}/confluence/home/logs/atlassian-confluence.log</output>

The best way to get your classes contributing to the log is to use slf4j as follow

// this is fake java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
...
private static final Logger log = LoggerFactory.getLogger(MyClass.class);
...
log.info();
log.error();
log.debug();

Now, to get your plugin echo things to the log file automatically, I can think of few ways but I still don’t know how I feel about them; and it is generally a best practice to let the customer control their logging and profiling.

That said, for sake of development you can use <log4jProperties/> tag in your plugin configuration to provide your custom logging during development , see https://developer.atlassian.com/server/framework/atlassian-sdk/amps-build-configuration-reference/#log4jproperties for details

I hope this helps.

2 Likes