views:

1352

answers:

2
+1  Q: 

log4j category

I have the following on my log4j.properties

log4j.rootLogger = debug, stdout, fileLog

log4j.appender.stdout = org.apache.log4j.ConsoleAppender

log4j.appender.fileLog = org.apache.log4j.RollingFileAppender
log4j.appender.fileLog.File = C:/logs/services.log
log4j.appender.fileLog.MaxFileSize = 256MB
log4j.appender.fileLog.MaxBackupIndex = 32
#Category: ConsultaDados
log4j.category.ConsultaDados=ConsultaDados
log4j.appender.ConsultaDados=org.apache.log4j.DailyRollingFileAppender
log4j.appender.ConsultaDados.layout=org.apache.log4j.PatternLayout
log4j.appender.ConsultaDados.layout.ConversionPattern={%t} %d - [%p] %c: %m %n
log4j.appender.ConsultaDados.file=C:/logs/consulta.log
log4j.appender.ConsultaDados.DatePattern='.' yyyy-MM-dd-HH-mm

And im creating my logger with :

myLogger = Logger.getLogger("ConsultaDados");

But this doesnt log my calls to the file. they get thrown into the rootLogger

Any ideas?

+4  A: 

First, your category is not mapped to an appender, second ConsultaDadosEORI doesn't match any category.

Here is a sample :

log4j.appender.YOUR_APPENDER=org.apache.log4j.RollingFileAppender
log4j.appender.YOUR_APPENDER.File=${SYSTEM_PROPEY_WITH_LOGGER_FOLDER}/log_file.log
log4j.appender.YOUR_APPENDER.Append=true
log4j.appender.YOUR_APPENDER.MaxFileSize=20MB
log4j.appender.YOUR_APPENDER.MaxBackupIndex=2
log4j.appender.YOUR_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.YOUR_APPENDER.layout.ConversionPattern=%d [%t] %p %c - %m %n
log4j.category.**YOUR_PACKAGE**=**INFO,YOUR_APPENDER** 
log4j.additivity.**YOUR_PACKAGE**=true or false
adrian.tarau
That was a misstype, only thing i dont understand is why do you say my category isn't mapped to an appender. since i have :log4j.category.ConsultaDados=ConsultaDados
Nuno Furtado
Ups, my mistake. I was confused by the fact that you defined a category before you defined the appender. Maybe this is the problem, I've always declared the appender and then use it.
adrian.tarau
well it worked =D, but i think the real trick was to put the LEVEL in it too
Nuno Furtado
+1  A: 

Just to finish this thread, the real issue was that the first value on your category line should of been a log level. So, as you correctly discovered, changing :

log4j.category.ConsultaDados=ConsultaDados

to

log4j.category.ConsultaDados=info,ConsultaDados

worked properly. As an FYI, you could of also changed the line to

log4j.category.ConsultaDados=,ConsultaDados

which would of caused you to inherit the logging level from the root logger.

haotten