Logging inside a confluence plugin

I am using confluence 5.10.0 and Atlassian SDK 6.2.14. I am currently making a plugin for the respective confluence server instance and I want to print out some logs from my plugin. Basically, I want to see some returned values.

How can I enable logging inside my plugin and how can I view the logs?

put log4.properties to resourses folder.

log4j.rootLogger=WARN, STDOUT

log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%5p %c{1} (%L) - %m%n

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=confrestextension.log // or any other log file, including standard one
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{dd-MM-yyyy HH:mm:ss} %-5p %c{1}:%L - %m%n

// for every class that you want to log from
log4j.logger.ru.homecredit.confrestextension.web.AttachmentController = INFO, \
  STDOUT, file
log4j.additivity.ru.homecredit.confrestextension.web.AttachmentController = false

add
<log4jProperties>src/main/resources/log4j.properties</log4jProperties>
between configuration tag of <groupId>com.atlassian.maven.plugins</groupId> in pom.xml
and this dependencies in pom.xml

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.6</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
            <scope>provided</scope>
        </dependency>

annotation @Slf4j on class, which youd’like to provide with logger and just use it witch
log.info() etc…

3 Likes

@Ignat1 thank you so much.