java - How to create different files for logger hierarchy in tomcat? -
in tomcat application, want use 2 loggers log general event informations , errors 2 different files.
logger eventlogger = logger.getlogger("event"); logger errorlogger = logger.getlogger("error");
now want following: logs of eventlogger should written "events.log" file, , errorlogger logs should written in "errors.log" file. logs other logger (e.g. tomcat logs) should written catalina.out (or other default file).
how can achive juli? or need third party lib?
this can't achieved juli. might use log4j.
basically need appenders. manage logs go separate files. example configuration in xml
:
<?xml version="1.0"?> <!doctype log4j:configuration system "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="console" class="org.apache.log4j.consoleappender"> <layout class="org.apache.log4j.enhancedpatternlayout"> <param name="conversionpattern" value="%d{absolute} %-5p [%t][%c{1}:%l] %m%n" /> </layout> </appender> <appender name="eventfile" class="org.apache.log4j.dailyrollingfileappender"> <param name="file" value="@tomcat.home@/logs/event.log" /> <param name="datepattern" value="'.'yyyy-mm-dd" /> <layout class="org.apache.log4j.patternlayout"> <param name="conversionpattern" value="%d{yyyy-mm-dd hh:mm:ss} %-5p %c{1}:%l - %m%n"/> </layout> </appender> <appender name="errorfile" class="org.apache.log4j.dailyrollingfileappender"> <param name="file" value="@tomcat.home@/logs/error.log" /> <param name="datepattern" value="'.'yyyy-mm-dd" /> <layout class="org.apache.log4j.patternlayout"> <param name="conversionpattern" value="%d{yyyy-mm-dd hh:mm:ss} %-5p %c{1}:%l - %m%n"/> </layout> </appender> <logger name="event" additivity="false"> <level value="info" /> <appender-ref ref="eventfile" /> </logger> <logger name="error" additivity="false"> <level value="info" /> <appender-ref ref="errorfile" /> </logger> <root> <priority value="info" /> <appender-ref ref="file" /> </root> </log4j:configuration>
Comments
Post a Comment