how to add substitutionProperties in code

Hi, Is it possible to use the substitution property mechanism from code when initializing logback? LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); try { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.shutdownAndReset(); // Can't set the property here because the execution context is null configurator.doConfigure(contextProperties.getProperty(" logging.properties")); configurator.getExecutionContext().addSubstitutionProperty(" service.name", "serviceOne"); // I think this is to late to set the property and it isn't used anymore } catch (JoranException je) { StatusPrinter.print(lc); } with configuration file: <?xml version="1.0" encoding="UTF-8"?> <configuration> <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}.%M [%line] - %msg%n</pattern> </layout> </appender> <appender name="A2" class="ch.qos.logback.core.rolling.RollingFileAppender "> <file>log/${service.name}.log</file> <Append>true</Append> <layout class="ch.qos.logback.classic.PatternLayout"> <pattern>>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M [%line] - %msg%n</pattern> </layout> <triggeringPolicy class=" ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <MaxFileSize>10MB</MaxFileSize> </triggeringPolicy> <rollingPolicy class=" ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> <FileNamePattern>log/${service.name}.%i.log.zip</FileNamePattern> <MinIndex>1</MinIndex> <MaxIndex>10</MaxIndex> </rollingPolicy> </appender> <root> <level value="INFO"/> <appender-ref ref="console"/> </root> </configuration> making every service that reuses this configuration but log to it's own logfile. Thanking you in advance, Tom

Hello Tom, You can put properties into any Context, in particular LoggerContext. So for example, lc.setProperty("service.name", "serviceOne"); will work in logback 0.9.9-SNAPSHOT. I am not so sure about 0.9.8. I hope this helps, Tom Eyckmans wrote:
Hi,
Is it possible to use the substitution property mechanism from code when initializing logback?
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); try { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.shutdownAndReset();
// Can't set the property here because the execution context is null
configurator.doConfigure(contextProperties.getProperty("logging.properties"));
configurator.getExecutionContext().addSubstitutionProperty("service.name <http://service.name>", "serviceOne"); // I think this is to late to set
[snip]
Tom
-- Ceki Gülcü QOS.ch is looking to hire talented developers in Switzerland. If interested, please contact c e k i @ q o s . c h
participants (2)
-
Ceki Gulcu
-
Tom Eyckmans