[Pax-Logging-Logback] update logger on configuration change (logback.xml)

341 views
Skip to first unread message

Marc Schlegel

unread,
Jun 2, 2016, 7:03:22 AM6/2/16
to OPS4J
Hello everyone

Is there any way to configure pax-logging-logback to pick up changes in the logback.xml? It would be nice to change log-levels for certain packages without restarting the system.

As a workaround I currently misuse felix-fileinstall:

org.ops4j.pax.logging.logback.config.file=${org.osgi.framework.storage}/../../../configuration/logback.xml
  1. start the system
  2. change logback.xml
  3. change the above fileinstall-config to something arbitrary value
  4. wait for fileinstall to pick-up change
  5. revert change in fileinstall-config
  6. new logback.xml is working as expected
These steps work because the changes propagated through configuration-admin cause pax-logging-logback to restart and pick up the updated logback.xml.


regards
-- Marc

Stuart McCulloch

unread,
Jun 2, 2016, 7:14:28 AM6/2/16
to op...@googlegroups.com
If you’re using pax-logging 1.8.0 or later then you can use logback’s auto-scan functionality:


ie. add scan=“true” to the top-level configuration element and it should reload when the file changes

Otherwise just touching the org.ops4j.pax.logging.cfg file should also reload the configuration.
--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marc Schlegel

unread,
Jun 2, 2016, 7:52:03 AM6/2/16
to OPS4J
Thanks for the hint, I was just looking at the configuration in pax-logging-logback but not logback itself.

Unfortunately the changes are not picked up even when specifying a shorter scan-period (default is 1 minute).

<configuration scan="true" scanPeriod="10 seconds">

Marc Schlegel

unread,
Jun 2, 2016, 7:54:59 AM6/2/16
to OPS4J
I forgot: I am using pax-logging 1.8.5

Stuart McCulloch

unread,
Jun 2, 2016, 10:32:09 AM6/2/16
to op...@googlegroups.com
I just tried pax-logging-logback 1.8.5 and it is picking up my changes - if I start with the following file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="10 seconds">

  <appender name="osgi" class="org.ops4j.pax.logging.logback.appender.PaxAppenderDelegate"/>

  <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{"yyyy-MM-dd HH:mm:ss,SSSZ"} %-5p [%thread] %c - %m%n</pattern>
    </encoder>
  </appender>

  <appender name="logfile" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <File>${karaf.data}/log/example.log</File>
    <Append>true</Append>
    <encoder>
      <pattern>%d{"yyyy-MM-dd HH:mm:ss,SSSZ"} %-5p [%thread] %c - %m%n</pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>${karaf.data}/log/example-%d{yyyy-MMdd}.log.gz</fileNamePattern>
      <maxHistory>90</maxHistory>
    </rollingPolicy>
  </appender>

  <root level="${root.level:-INFO}">
    <appender-ref ref="osgi"/>
    <appender-ref ref="console"/>
    <appender-ref ref="logfile"/>
  </root>

</configuration>
then change the file setting to "${karaf.data}/log/test.log" and the root level to TRACE it does start sending TRACE logging to the new file.

What does your logback file look like and what element are you changing?

Marc Schlegel

unread,
Jun 3, 2016, 4:30:01 AM6/3/16
to OPS4J
Ok, it is working now.

I guess I was just to quick with tests :-/
Thanks again for pointing out the logback-solution.

-- Marc
Reply all
Reply to author
Forward
0 new messages