Access Properties Defined in Logback programmatically

By default, properties are defined in "local" scope. However, you can force a property to have context scope, in which case it's pretty easy to get the value of the property:

 LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
 String val = lc.getProperty(aString);

Defining properties in "context" scope is considered a little heavy handed. Instead of defining all/many properties in context scope, you could define only a single property in context scope. Here is an example:

<configuration>
  <!-- get many props from a file -->
  <property resource='log.properties'/>
  <-- set only one to be in context scope -->
  <property scope="context" name="log.dir.ctx" value="${log.dir}" />
  ...
</configuration>

You could then obtain the value you are looking for with:

 LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
 String val = lc.getProperty("log.dir.ctx");