[logback-user] logging multiple main programs
Palmer, Eric
epalmer at richmond.edu
Wed Oct 2 16:51:23 CEST 2013
Hey,
I have been using logback for some time with monolithic java batch apps (ETL). I am a very part time jave programmer at my job (10% at most)
I now am working on an application that has two main programs but uses 90% of the same code base. So one project, two jar file artifacts.
(two programs labeled people and position)
The logging is pretty simple
* one log file for each run
* log files are denoted with people_timestamp.log or position_timestamp.log
* error logging sends email as well as writes to the log file
this is my problem: When I run the first main program that is working it creates both log files and one is empty. I only want the one log file that is needed created.
I'm sure I'm making this way more complicated than it needs to be.
In the code base for people
PeopleXmlMain.log = LoggerFactory.getLogger("people");
PeopleXmlMain.logErr = LoggerFactory.getLogger("peopleerror");
similar for position main
PositionXmlMain.log = LoggerFactory.getLogger("position");
PositionXmlMain.logErr = LoggerFactory.getLogger("positionerror");
the config file
================================
<configuration debug="true">
<timestamp key="bySecond" datePattern="yyyyMMdd'T'HHmmss"/>
<!-- TODO this needs lot of changes, additions
create a logger called applogger
http://stackoverflow.com/questions/15140935/file-and-stdout-appenders-in-logback-xml
-->
<appender name="ERROREMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
<cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTracker">
<!-- send just one log entry per email -->
<bufferSize>1</bufferSize>
</cyclicBufferTracker>
<smtpHost>autosmtp.richmond.edu</smtpHost>
<to>someone at somedomain.com</to>
<!-- <to>ANOTHER_EMAIL_DESTINATION</to> additional destinations are possible -->
<subject>Error in directory loader: %logger{20}</subject>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%date %-30(%d{HH:mm:ss.SSS} [%M]) %-5level %-33(%C{32}) - %msg%n%n%ex%n%n</pattern>
</layout>
</appender>
<appender name="ERROREMAILPEOPLE" class="ch.qos.logback.classic.net.SMTPAppender">
<cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTracker">
<!-- send just one log entry per email -->
<bufferSize>1</bufferSize>
</cyclicBufferTracker>
<smtpHost>autosmtp.richmond.edu</smtpHost>
<to>someone at somedomain.com</to>
<!-- <to>ANOTHER_EMAIL_DESTINATION</to> additional destinations are possible -->
<subject>Error in People2Xml: %logger{20}</subject>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%date %-30(%d{HH:mm:ss.SSS} [%M]) %-5level %-33(%C{32}) - %msg%n%n%ex%n%n</pattern>
</layout>
</appender>
<appender name="ERROREMAILPOSITION" class="ch.qos.logback.classic.net.SMTPAppender">
<cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTracker">
<bufferSize>1</bufferSize>
</cyclicBufferTracker>
<smtpHost>autosmtp.richmond.edu</smtpHost>
<to>someone at somedomain.com</to>
<subject>Error in Position2Xml: %logger{20}</subject>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%date %-30(%d{HH:mm:ss.SSS} [%M]) %-5level %-33(%C{32}) - %msg%n%n%ex%n%n</pattern>
</layout>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%-40(%d{HH:mm:ss.SSS} [%M]) %-5level %-36(%C{32}) - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILEPEOPLE" class="ch.qos.logback.core.FileAppender">
<file>/somepath/logs/people_${bySecond}.log</file>
<append>true</append>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%-40(%d{HH:mm:ss.SSS} [%M]) %-5level %-36(%C{32}) - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILEPOSITION" class="ch.qos.logback.core.FileAppender">
<file>/somepath/logs/position_${bySecond}.log</file>
<append>true</append>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%-40(%d{HH:mm:ss.SSS} [%M]) %-5level %-36(%C{32}) - %msg%n</pattern>
</encoder>
</appender>
<!-- suppress apache ldap info log messages -->
<logger name="org.apache" level="warn" />
<logger name="Error" level="error">
<appender-ref ref="ERROREMAIL" />
</logger>
<logger name="people" level="info">
<appender-ref ref="FILEPEOPLE" />
<appender-ref ref="ERROREMAIL" />
</logger>
<logger name="position" level="info">
<appender-ref ref="FILEPOSITION" />
<appender-ref ref="ERROREMAIL" />
</logger>
<logger name="peopleerror" level="info">
<appender-ref ref="ERROREMAILPEOPLE" />
</logger>
<logger name="positionerror" level="info">
<appender-ref ref="ERROREMAILPOSITION" />
</logger>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>
--
Eric Palmer
Web Services
U of Richmond
To report technical issues, obtain technical support or make requests for enhancements please visit http://web.richmond.edu/contact/technical-support.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20131002/78ad7115/attachment.html>
More information about the Logback-user
mailing list