0

I have a plugin that I want to log information to an individual file entirely w/o messing with the main log file. Here's the logback.xml in my resources directory for my plugin:

<?xml version="1.0"?>
<configuration>
<appender name="eventLogger" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${log.dir}/events/events.log</file>
    <encoder>
        <pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
    </encoder>
    <append>true</append>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${log.dir}/events/events-%d.%i.log</fileNamePattern>
        <maxHistory>3</maxHistory>
        <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <maxFileSize>10MB</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
    </rollingPolicy>
</appender>

<logger name="event.logs" level="DEBUG" additivity="false">
    <appender-ref ref="eventLogger" />
</logger>

I then try and use the logger like this:

private static final Logger LOGGER = LoggerFactory.getLogger("event.logs");

Here are my logging deps in my pom.xml:

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.0.11</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</artifactId>
        <version>1.0.6</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>

Seems pretty straight forward but nothing in my plugin is logging. Is it because I haven't specified a root level logger?

Kara
  • 6,115
  • 16
  • 50
  • 57
Scott James Walter
  • 427
  • 1
  • 6
  • 20
  • logback implements the slf4j-api, and if stash is using slf4j it's possible your logs are redirected to stash's log file. Also why do you have that log4j dependency. If that;s the case, just modify stash's logger configuration and add your appender there – Svetlin Zarev Jul 22 '16 at 18:18
  • @SvetlinZarev Not sure how it got there. Quite possibly something that was added by default when I created the plugin through atlassian's SDK. I'd rather keep all the configuration of the plugin within the plugin itself, like its' own logback.xml file. I don't have access to administrative tools/files for the Stash instance so having less reliance on other people is better here. – Scott James Walter Jul 22 '16 at 18:53
  • logback does not work that way - you cant have separate config files for the plugins. – Svetlin Zarev Jul 22 '16 at 19:35
  • @SvetlinZarev Are you sure? Because I placed a logback.xml in my resources dir, and my plugin is now producing log files and rolling them back as well according to my settings above, it's just also putting them in Stash's main log file. It's doing something, that's for sure! – Scott James Walter Jul 22 '16 at 20:34

0 Answers0