Log4j - Separate files

J

John

I am trying to have two logs for my app, 1 for auditing and the other
for everything else. I defined to loggers in log4j.properties (see
contents below).
The problem I am having is that all messages are going to both
loggers.

Any suggestions?

============ log4j.properties ============
log4j.rootLogger=error, stdout, audit

log4j.appender.stdout=org.apache.log4j.RollingFileAppender
log4j.appender.stdout.File=/home/nacash/sites-i/regreporting/cotterjo/logs/example.log

log4j.appender.stdout.MaxFileSize=7000KB
# Keep one backup file
log4j.appender.stdout.MaxBackupIndex=6

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p %d %m%n

log4j.appender.audit.Threshold=fatal
log4j.appender.audit=org.apache.log4j.RollingFileAppender
log4j.appender.audit.File=/home/nacash/sites-i/regreporting/cotterjo/logs/audit.log

log4j.appender.audit.MaxFileSize=7000KB
# Keep one backup file
log4j.appender.audit.MaxBackupIndex=6

log4j.appender.audit.layout=org.apache.log4j.PatternLayout
log4j.appender.audit.layout.ConversionPattern=%p %d - %m%n


============ Java Code Segment ============
public abstract class RegRptAbstractAction extends Action {

//static Logger logger =
Logger.getLogger(RegRptAbstractAction.class);
static Logger logger = Logger.getLogger("stdout");
static Logger auditLogger = Logger.getLogger("audit");
public ActionForward execute(...)
throws Exception {

String employeeName="unknown";
auditLogger.fatal("User: " + employeeName + " Request: " +
request.getRequestURI());
logger.error(" Testing error message ");
 
J

jAnO!

John said:
I am trying to have two logs for my app, 1 for auditing and the other
for everything else. I defined to loggers in log4j.properties (see
contents below).
The problem I am having is that all messages are going to both
loggers.

Any suggestions?
I'll get back to you tomorrow.. At work we use Log4j i'll look into the
config ..
That will be in 9 hours or so..
 
J

jAnO!

John said:
I am trying to have two logs for my app, 1 for auditing and the other
for everything else. I defined to loggers in log4j.properties (see
contents below).
The problem I am having is that all messages are going to both
loggers.

Any suggestions?

============ log4j.properties ============
log4j.rootLogger=error, stdout, audit

log4j.appender.stdout=org.apache.log4j.RollingFileAppender
log4j.appender.stdout.File=/home/nacash/sites-i/regreporting/cotterjo/lo
gs/example.log

log4j.appender.stdout.MaxFileSize=7000KB
# Keep one backup file
log4j.appender.stdout.MaxBackupIndex=6

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p %d %m%n

log4j.appender.audit.Threshold=fatal
log4j.appender.audit=org.apache.log4j.RollingFileAppender
log4j.appender.audit.File=/home/nacash/sites-i/regreporting/cotterjo/log
s/audit.log

log4j.appender.audit.MaxFileSize=7000KB
# Keep one backup file
log4j.appender.audit.MaxBackupIndex=6

log4j.appender.audit.layout=org.apache.log4j.PatternLayout
log4j.appender.audit.layout.ConversionPattern=%p %d - %m%n


============ Java Code Segment ============
public abstract class RegRptAbstractAction extends Action {

//static Logger logger =
Logger.getLogger(RegRptAbstractAction.class);
static Logger logger = Logger.getLogger("stdout");
static Logger auditLogger = Logger.getLogger("audit");
public ActionForward execute(...)
throws Exception {

String employeeName="unknown";
auditLogger.fatal("User: " + employeeName + " Request: " +
request.getRequestURI());
logger.error(" Testing error message ");

We have a different implementation. We let log4j (we have a xml
configfile) do the splitting into different files..
And it goes a litte something like this:

<category name="org.apache.cactus" additivity="false">
<level value="WARN"/>
<appender-ref ref="STDOUT"/>
</category>

<category name="webwork.util" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="AUDIT"/>
</category>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top