<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">Hello all,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I am trying to figure out why logback is not writing to a file. It creates the file okay, but it is not writing anything to it.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I have the following programmatic configuration in my java code. This just reads a properties file and sets system properties out of the logback values so they can be read from the configuration.xml file.
It also configures the logger from logback_configuration.xml instead of the default logback.xml<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> private static void initLogback() {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> Map<String,String> logbackProperties = new HashMap<>();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> PropertyDeluxe properties = RenoProperties.getProperties();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> for (String key : properties.getKeys())<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> if (key.startsWith(RenoProperties.LOGBACK_PROPERTY_PREFIX))<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> logbackProperties.put(key,properties.getString(key));<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> //set system properties out of the logback values so we can reference them from the configuration file<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> for (String key : logbackProperties.keySet())<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> System.setProperty(key,logbackProperties.get(key));<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> //configure the logger from the logback_configuration.xml. Default is logback.xml<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> LoggerContext lc = new LoggerContext();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> try {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> JoranConfigurator configurator = new JoranConfigurator();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> configurator.setContext(lc);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> lc.reset();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> configurator.doConfigure(properties.getString(RenoProperties.LOGBACK_CONFIG_FILE_PROPERTY));<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> } catch (JoranException je) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> je.printStackTrace();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> StatusPrinter.printInCaseOfErrorsOrWarnings(lc);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Here are the values defined in the property file. Where base.dir is passed in through the command line as "@@base.dir=C:/project_work/reno"<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">@@scenario.dir = base.dir/scenarios/scenario.name<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">@@_outputs.dir = scenario.dir/outputs<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">logback.config.file = base.dir/resource/code/java/logback_configuration.xml<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">logback.file.main = _outputs.dir/logs/java_main.log<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">logback.level = info<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">And here is the logback_configuration.xml<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><configuration scan="true" debug="true"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <appender name="FILE" class="ch.qos.logback.core.FileAppender"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <file>${logback.file.main}</file><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <append>true</append><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <Pattern><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> %d{HH:mm:ss} [%-30.-30thread] %-5level %-25.25logger{25} - %msg%n<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </Pattern><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </encoder><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </appender><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <pattern><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> %d{HH:mm:ss} %green([%-5.-5thread]) %-5level %-25.25logger{25} - %msg%n<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </pattern><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </encoder><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </appender><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <root level="${logback.level}"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <appender-ref ref="FILE" /><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <appender-ref ref="STDOUT" /><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </root><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"></configuration><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I’ve looked everywhere and nothing really stands out. Can anyone see what I’ve missed?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Thank you<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Chryssa</span><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>