Log4j: socketappender - How to capture logs in localfile when remotehost is down - java

I have a scenario where we are logging to remote logstash host. Now as per log4j documentation, For SocketAppender, if remote host is down, log events will be simply dropped. I would like to customize socket appender in order to capture those dropped logs in a local log file. So that nothing is missed.
I tried but was unable to.
There were 2 methods in socketappender connect and append(event)
But it seems to me, append is called only if connection is successful. Althought connect method wasn't returning anything
So how do i capture that event in localfile in case remotehost is down
Ref: https://logging.apache.org/log4j/1.2/xref/org/apache/log4j/net/SocketAppender.html
I also tried Fallbackerror handler. But it only logs once and then no more logging. So basically it doesnt seems to work

Write to a local log file and use filebeat to ship the logs to logstash. When logstash is unavailable, the logs will spool up locally (a "free" distributed cache).
There's a corner case if logstash is still down when your local log files are rotated...

You can do one thing. Use Two Appenders at a time. One Socket Appender and second File Appender. So, at a time, you logs will go both in Socket Appender to Remote Host , as well as in the file on your local.
Here is an example of this-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="FA" class="org.apache.log4j.FileAppender">
<param name="File" value="c:/logs/log4j/log2.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="conversionPattern" value="%m%n"/>
</layout>
</appender>
<appender name="server" class="org.apache.log4j.net.SocketAppender">
<param name="Port" value="4712"/>
<param name="ReconnectionDelay" value="10000"/>
<param name="RemoteHost" value="localhost"/>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="server"/>
<appender-ref ref="FA"/>
</root>
</log4j:configuration>
You can use FA for Appending into file and Server for Remote.
UPDATE
You can try Log4j 2.7 Failover Apppender. Once, the socket Appender fails, the application will use secondary file appender.
Example-
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp" packages="">
<Appenders>
<RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/app-%d{MM-dd-yyyy}.log.gz"
ignoreExceptions="false">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<TimeBasedTriggeringPolicy />
</RollingFile>
<Console name="STDOUT" target="SYSTEM_OUT" ignoreExceptions="false">
<PatternLayout pattern="%m%n"/>
</Console>
<Failover name="Failover" primary="RollingFile">
<Failovers>
<AppenderRef ref="Console"/>
</Failovers>
</Failover>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="Failover"/>
</Root>
</Loggers>
</Configuration>

Related

Log4j 2 not logging with correct time in JAVA

I have written a basic Server that receives data from Client and processes the received messages. Whenever I am receiving I am logging the received messages into a log file. Now the problem is : all messages sent to the Server are logged at the Client side. Suppose a message sent from Client to Server at "18:32:23:345" then at my Server side when I am logging it is showing received at "18:32:23:300". Please observe the Milli-seconds time at the Server side. It is showing that the message is received before the message is sent. I am using Asynchronous logging with log4j2. Can anyone please help me.
This is my XML file of Log4j2 configuration at Server side:
<Configuration status="warn">
<Appenders>
<File name="my_file_appender" fileName="Errors.log" immediateFlush="false" append="false">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} - %msg%n</Pattern>
</PatternLayout>
</File>
<Async name="async_appender">
<AppenderRef ref="my_file_appender" />
</Async>
<!-- file appender -->
<RollingFile name="Error-log" fileName="MESSAGES.log"
filePattern="MESSAGES-%d{yyyy-MM-dd}.log">
<!-- log pattern -->
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} - %msg%n</Pattern>
</PatternLayout>
<!-- set file size policy -->
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="50 MB" />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="Error-log" level="info" additivity="false">
<appender-ref ref="Error-log" level="debug"/>
</Logger>
<Root level="info" includeLocation="false">
<AppenderRef ref="async_appender"/>
</Root>
</Loggers>
As per my view the Client side logging is working perfectly. Is there any problem with my configuration? I have tried implementing the same configuration with .properties file. But it is not working. Can anyone also tell me how to change the above configuration to .properties file as loading XML every time makes my application to slow down. Thanks in advance.

Performance of log4j2 compared to log4j1

I'm trying to migrate my app into using log4j2. It is currently using log4j 1.2.16. I also have a performance build for my project, and after upgrading to log4j 2, the performance seemed to have improve a lot.
That is, until I read about bridging. According to the doc, I have to exclude log4j1 JAR from the classpath, and include the bridging JAR - which I assume is named 'org.apache.logging.log4j:log4j-1.2-api'. Once I did this, performance dropped again.
So to summarise:
Performance with log4j2 + bridging jar + log4j-1.2-api + log4j1 : good
Performance with log4j2 + bridging jar + log4j-1.2-api : bad (to the point that it drops back to performance of just log4j1)
I have checked that the log4j-1.2-api is earlier in the classpath. So it should have been loaded first.
Any idea what could cause this problem?
Thank you very much in advance!
Oh my complete classpath for logging are:
org.slf4j:slf4j-api
org.slf4j:log4j-over-slf4j
org.slf4j:jcl-over-slf4j
org.apache.logging.log4j:log4j-slf4j-impl
org.apache.logging.log4j:log4j-core
org.apache.logging.log4j:log4j-api
org.apache.logging.log4j:log4j-1.2-api
log4j:log4j (with & without, as described above)
Versions:
Log4j2 : 2.6.2
slf4j: 1.7.20
log4j1: 1.2.16
My config file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration
xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="log4j2-xinclude-appenders.xml" />
<Loggers>
<Root level="info">
<AppenderRef ref="rollingFileAppender"/>
<AppenderRef ref="stdOutAppender"/>
</Root>
</Loggers>
</Configuration>
And the log4j2-xinclude-appenders.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<appenders>
<RollingRandomAccessFile name="_rollingFileAppender" fileName="./logs/foo-${sys:app.name.suffix}.log"
filePattern="./logs/foo-${sys:foo.app.name.suffix}.log.%i">
<PatternLayout>
<Pattern>%d|%X{active.profiles}| %-5p |%X{fcp.session}|%X{StateMachine.key}|%X{StateMachine.currentState}| %m | %t | %c{1.}%n</Pattern>
</PatternLayout>
<Policies>
<OnStartupTriggeringPolicy minSize="0" />
<SizeBasedTriggeringPolicy size="100 MB" />
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingRandomAccessFile>
<Async name="rollingFileAppender" blocking="false" bufferSize="10000">
<AppenderRef ref="_rollingFileAppender"/>
</Async>
<Console name="_stdOutAppender" target="SYSTEM_OUT">
<PatternLayout pattern="%d|%X{active.profiles}| %-5p |%X{fcp.session}|%X{StateMachine.key}|%X{StateMachine.currentState}| %m | %t | %c{1.}%n"/>
</Console>
<Async name="stdOutAppender" blocking="false" bufferSize="10000">
<AppenderRef ref="_stdOutAppender"/>
</Async>
</appenders>
EDIT: This is the log4j 1 xml file that gets included in the classpath
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="false" xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="A1" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<appender name="R" class="com.bar.common.util.RollingFileAppender">
<param name="File" value="./logs/bar.log"/>
<param name="MaxFileSize" value="100MB"/>
<param name="MaxBackupIndex" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<!-- Performance Appender -->
<appender name="OneSecondStatsAppender"
class="com.foo.perf.AggregatedStatisticsAppender">
<param name="TimeSlice" value="1000"/>
<appender-ref ref="OneSecondStatsLogger"/>
</appender>
<appender name="FiveMinuteStatsAppender"
class="com.bar.perf.DatafabricAggregatedStatisticsAppender">
<param name="TimeSlice" value="300000"/>
<appender-ref ref="FiveMinuteStatsLogger"/>
</appender>
<!-- Aggregated Performance Statistics Appender -->
<appender name="OneSecondStatsLogger" class="org.apache.log4j.FileAppender">
<param name="File" value="./logs/bar-performance.log"/>
<layout class="com.bar.perf.AggregatedStatisticsCsvLayout"/>
<filter class="com.bar.perf.CategorisedStatisticExclusionFilter"/>
</appender>
<appender name="FiveMinuteStatsLogger" class="org.apache.log4j.FileAppender">
<param name="File" value="./logs/bar-minutes.log"/>
<layout class="com.bar.perf.AggregatedStatisticsCsvLayout">
<param name="ShowEmptyStatistics" value="true"/>
</layout>
</appender>
<!-- Loggers -->
<logger name="org.perf4j.TimingLogger" additivity="false">
<level value="INFO"/>
<appender-ref ref="OneSecondStatsAppender"/>
<appender-ref ref="FiveMinuteStatsAppender"/>
</logger>
<logger name="com.bar">
<level value="INFO"/>
</logger>
<logger name="com.gemstone.gemfire">
<level value="INFO"/>
</logger>
<logger name="org.springframework.data">
<level value="INFO"/>
</logger>
<!-- Root logger configuration -->
<root>
<priority value="INFO"/>
<appender-ref ref="R"/>
</root>
</log4j:configuration>
EDIT 2:
Classpath order for poor performance:
log4j-1.2-api-2.6.2.jar
jcl-over-slf4j-1.7.20.jar
slf4j-api-1.7.20.jar
log4j-slf4j-impl-2.6.2.jar
log4j-core-2.6.2.jar
log4j-api-2.6.2.jar
log4j-1.2.16.jar
Classpath order for good performance
log4j-1.2-api-2.6.2.jar
jcl-over-slf4j-1.7.20.jar
slf4j-api-1.7.20.jar
log4j-over-slf4j-1.7.20.jar
log4j-slf4j-impl-2.6.2.jar
log4j-core-2.6.2.jar
log4j-api-2.6.2.jar
log4j-1.2.16.jar
I ran into more strange findings. I enabled '-verbose:class' JVM options to see which classes were loaded, and I can confirm that only classes from the following JARs were loaded (in the order):
slf4j-api-1.7.20.jar
log4j-slf4j-impl-2.6.2.jar
log4j-api-2.6.2.jar
log4j-core-2.6.2.jar
log4j-1.2-api-2.6.2.jar
jcl-over-slf4j-1.7.20.jar
Yet, the following two tests yield different result:
Performance test with including log4j-over-slf4j-1.7.20 & log4j-1.2.16 :
GOOD
Performance test with including log4j-over-slf4j-1.7.20 & but excluding log4j-1.2.16 : BAD
Performance test with excluding log4j-over-slf4j-1.7.20 & including log4j-1.2.16 : BAD
Note that these two JARs were not loaded at all.
I there there are two questions here:
Why does log4j 1 get used in certain classpath configurations
Why is log4j 2 not faster than log4j 1
1. Why is log4j 1 used
I suspect that the following slf4j dependencies caused the old log4j 1.2 to be used:
org.slf4j:log4j-over-slf4j
org.slf4j:jcl-over-slf4j
If you use maven these could bring in the old Log4j 1 as a transitive dependency even if you don't explicitly declare it in your POM.
Please remove these. Log4j 2 has log4j-slf4j-impl and log4j-jcl modules that will accomplish the same but use Log4j 2 instead.
You should not have Log4j 1 in the classpath. If your application (or any of the libraries you use) depend on the Log4j 1 API, then add the log4j-1.2-api module.
2. Why is log4j 2 not faster than log4j 1
The configuration you describe does not take advantage of log4j 2 features. It uses AsyncAppender (which is roughly equivalent in log4j 1 and 2) and ConsoleAppender (which is slightly worse in log4j 2). ConsoleAppender is about 60 times slower than file appender. Be extremely careful when logging to the console in production systems.
Here is what I suggest: remove the following (which now seems to give better performance, but bear with me)
log4j-over-slf4j-1.7.20
log4j-1.2.16
the old lo4j.xml configuration
Add the LMAX Disruptor dependency:
<!-- https://mvnrepository.com/artifact/com.lmax/disruptor -->
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.2.0</version>
</dependency>
Use the following log4j2.xml configuration. Temporarily just make it a simple file without includes, you can put that back later. (Notice I added <Configuration status="trace" to the beginning of the file: that will output internal log4j2 debugging statements so you can confirm that configuration completed without problems.)
Note that I made Console logging WARN level as I suspect it is impacting performance.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="TRACE" xmlns:xi="http://www.w3.org/2001/XInclude">
<appenders>
<RollingRandomAccessFile name="_rollingFileAppender"
fileName="./logs/foo-${sys:app.name.suffix}.log"
filePattern="./logs/foo-${sys:foo.app.name.suffix}.log.%i">
<PatternLayout>
<Pattern>%d|%X{active.profiles}| %-5p |%X{fcp.session}|%X{StateMachine.key}|%X{StateMachine.currentState}| %m | %t | %c{1.}%n</Pattern>
</PatternLayout>
<Policies>
<OnStartupTriggeringPolicy minSize="0" />
<SizeBasedTriggeringPolicy size="100 MB" />
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingRandomAccessFile>
<Console name="_stdOutAppender" target="SYSTEM_OUT">
<PatternLayout pattern="%d|%X{active.profiles}| %-5p |%X{fcp.session}|%X{StateMachine.key}|%X{StateMachine.currentState}| %m | %t | %c{1.}%n"/>
</Console>
</appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="_rollingFileAppender"/>
<AppenderRef ref="_stdOutAppender" level="WARN" />
</Root>
</Loggers>
</Configuration>
Now, the final (key) point: enable log4j 2 async loggers by setting system property Log4jContextSelector to org.apache.logging.log4j.core.async.AsyncLoggerContextSelector.
This last bit should make a large performance difference. (Together with disabling Console logging.)

How can I get Log4j2 to log to my log file, I've tried everything I can think of, could it be a configuration issue in linux?

My log4j2.xml is exactly the same as the one I've written for another similar server - which works perfectly well. The only differences are the file/server names and paths.
Log4j1 worked fine too, it's just log4j2 that's causing problems. I'm starting to think I might have missed something in the linux config at this point.
Things I've tried:
Including log4j2.xml in the root directory of the project
Including log4j2.xml in the main.resources folder of my project
Using -Dlog4j.configurationFile="PATH" when running the jar (via systemd)
Verified the folder/log file are owned by the server user and server group
Verified that the server has rw permissions for the file/folder
Verified that the server user is a member of the correct group
Also, when I run systemctl status -l on the server, the resulting output shows the log data as I expect to see it in the firmwareserver.log file.
My other server uses the log4j2.xml file from main.resources in the project without any issues.
EDIT: I should add, I'm developing this in eclipse on a windows machine, and when I run it there the log file saves as expected, even using the linux path it still works.
EDIT 2: I found the following error when I ran the jar file directly instead of as a systemd service:
2016-03-11 14:06:39,601 ERROR Unable to locate appender RollingFile for logger
Here's my Log4j2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG" monitorInterval="30">
<Properties>
<Property name="windows-log-path">C:/log4j/</Property>
<Property name="linux-log-path">/var/log/wsfirmwareserver</Property>
</Properties>
<Appenders>
<RollingFile name="RollingFile" fileName="${linux-log-path}/firmwareserver.log"
filePattern="${linux-log-path}/$${date:yyyy-MM}/firmwareserver-%d{yyyy-MM-dd}-%i.log">
<PatternLayout>
<pattern>%d{dd/MMM/yyyy HH:mm:ss,SSS}{GMT+1} [%-5p] [%t] - %c{1}: %m%n</pattern>
</PatternLayout>
<SizeBasedTriggeringPolicy size="5MB" />
<DefaultRolloverStrategy max="30" />
</RollingFile>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] - %m%n" />
</Console>
<SMTP name="SMTPAppender"
smtpProtocol="smtps"
smtpPort="465"
subject="LOC SERVER:Error"
to="me#myjob.com, me#otheremail.com"
from="notifications#myjob.com"
smtpHost="smtp.gmail.com"
smtpUsername="notifications#myjob.com"
smtpPassword="thepassword"
bufferSize="512">
<PatternLayout>
<pattern>%d{dd/MMM/yyyy HH:mm:ss,SSS}{GMT+1} [%-5p] [%t] - %c{1}: %m%n</pattern>
</PatternLayout>
</SMTP>
</Appenders>
<Loggers>
<Logger name="root" level="info" additivity="false">
<appender-ref ref="RollingFile" level="info" />
</Logger>
<Root level="debug" additivity="false">
<AppenderRef ref="Console" level="debug"/>
<AppenderRef ref="RollingFile" level="debug"/>
<AppenderRef ref="SMTPAppender" level="error"/>
</Root>
</Loggers>
</Configuration>
Anybody got any suggestions?
Ideally I'd like to have the config file located in the same folder as the server jar, but at this point I just want it to log to the file properly.
There was an error in the log4j2.xml file itself.
I haven't located it, but replacing it with a copy from another server fixed the issue.

Configuration logging in Play Framework at start up auto-test

I configured the logging in my Play Framework application. When I run application in prod or dev mode or run test by comand (play test) - everything works fine, but test can not executes when I run their 'play auto-test'. Please help!
in application.conf:
application.log=INFO
application.log.path=/log4j.xml
log4j.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="file" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${application.path}/logs/application.log"/>
<param name="MaxFileSize" value="1MB"/>
<param name="MaxBackupIndex" value="100"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p ~ %m %n"/>
</layout>
</appender>
<logger name="play">
<level value="error"/>
</logger>
<root>
<priority value="error"/>
<appender-ref ref="file"/>
</root>
</log4j:configuration>
When I use the following log4j.xml file:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n"/>
</layout>
</appender>
<logger name="play">
<level value="debug"/>
</logger>
<root>
<priority value="info"/>
<appender-ref ref="console"/>
</root>
</log4j:configuration>
tests running the command 'play auto-test' successfully executed. Please tell how configure logging in Play (output to file) that run and executes tests in 'play auto-test'!
Thi is pretty much a Play! bug. It's not caused by the fact that you've configured log4j with a separate file, though doing that will hide another error message: "play.tmp is null when it should be play.tmp=none" (something to this liking - you'll get this if you remove your custon log4j.xml file and re-do "play auto-test"). Problem is that even if you set that to play.tmp=none it will still not work. Besides, if you compare their online documentation to Play!'s console output you'll already realize that something's wrong:
The docs say:
"The 'auto-test' command do the same than the 'test' command, but it automatically launch a browser, run all the tests, and stop."
Console sais (when you do "play auto-test"):
ATTENTION: You're running Play! in DEV mode
~
~ Go to http://localhost:9000/#tests to run the tests
~
The answer was very simple
in application.conf:
%test.application.log=INFO
%test.application.log.path=/log4j.xml
application.log=INFO
application.log.path=/log4j.properties
application.log.system.out=off
log4j.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n"/>
</layout>
</appender>
<logger name="play">
<level value="debug"/>
</logger>
<root>
<priority value="info"/>
<appender-ref ref="console"/>
</root>
</log4j:configuration>
log4j.properties:
log4j.rootLogger=ERROR, Rolling
log4j.logger.play=INFO
log4j.appender.Rolling=org.apache.log4j.RollingFileAppender
log4j.appender.Rolling.File=${application.path}/logs/application.log
log4j.appender.Rolling.MaxFileSize=1MB
log4j.appender.Rolling.MaxBackupIndex=100
log4j.appender.Rolling.layout=org.apache.log4j.PatternLayout
log4j.appender.Rolling.layout.ConversionPattern=%d{ABSOLUTE} %-5p ~ %m %n
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p ~ %m%n

How to Write Java server logs to separate log file

Right now we are using a customized logger method for our application but now we have a stand alone code for which we need to write to a separate log file. We have little idea about log4j. I just want to know where to change properties if any so that i don't disturb the existing logger application as well as we write our logs into new log file.
First define a file appender:
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=/mylogfile.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
Then point your package to use this appender:
log4j.logger.mypackage=LOGFILE
log4j.additivity.mypackage=false
The last line is important if you do not want your package to inherit the global appender. Doing so will result in the log messages from mypackage also printed at the default appender.
in log4j you can direct log entries to separate files based upon pacakge name.
log4j.logger.your.package1= LOG,STDOUT
log4j.additivity.your.package1=false
log4j.logger.your.package2= DEBUG, STDOUT
log4j.additivity.your.package2=false
I use XML configuration.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="logfile" class="org.apache.log4j.FileAppender">
<param name="file" value="app.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d-%5p(%F:%L)-%m%n"/>
</layout>
</appender>
<appender name="myLogfile" class="org.apache.log4j.FileAppender">
<param name="file" value="myFile.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d-%5p(%F:%L)-%m%n"/>
</layout>
</appender>
<logger name="org.myApp">
<level value="INFO"/>
<appender-ref ref="myLogfile" />
</logger>
<root>
<level value="ERROR" />
<appender-ref ref="logfile" />
</root>
</log4j:configuration>
Just use FileAppender and specify a new filename in the constructor.

Categories

Resources