aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes how to filter log messages while using log4j ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "how to filter log messages while using log4j ?" Watch "how to filter log messages while using log4j ?" New topic
Author

how to filter log messages while using log4j ?

Anuja Piplapure
Greenhorn

Joined: Feb 06, 2005
Posts: 7
Hello,
I have a struts application in which i configured log4j. The application log messages getted logged in the log file, but I also get a lot of unwanted, apparently server generated, log messages. How do i stop these unwanted messages from being logged in my application log file?

my log4j.properties has follwoing configuration::
log4j.rootLogger=debug, haps
log4j.appender.haps=org.apache.log4j.RollingFileAppender
log4j.appender.haps.File=d:/bea/user_projects/mydomain/hapsAppMessages.log
log4j.appender.haps.MaxFileSize=500000KB
log4j.appender.haps.MaxBackupIndex=3
log4j.appender.haps.layout=org.apache.log4j.PatternLayout
log4j.appender.haps.layout.ConversionPattern=%d %-5p %C - %m%n

Do i have to change anything in this file? or do i change anything else in my application server ( BEA WebLogic 8.1) configuration?!
Some advice on this matter would be really helpful.

The non-application related log messages that I get are something like this::
005-09-29 11:22:26,750 INFO org.apache.struts.util.PropertyMessageResources - Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true
2005-09-29 11:22:26,781 INFO org.apache.struts.util.PropertyMessageResources - Initializing, config='org.apache.struts.action.ActionResources', returnNull=true
2005-09-29 11:22:26,843 DEBUG org.apache.commons.digester.Digester - register('-//Apache Software Foundation//DTD Struts Configuration 1.0//EN',
2005-09-29 11:23:58,171 DEBUG org.apache.commons.beanutils.ConvertUtils - Using converter org.apache.commons.beanutils.converters.StringConverter@1f95673
2005-09-29 11:23:58,171 DEBUG org.apache.commons.beanutils.BeanUtils - setProperty(com.au.optus.delphi.web.form.hbu.HBUExistingEquipmentsForm@1716083, model, [1108])
2005-09-29 11:23:58,171 DEBUG org.apache.commons.beanutils.ConvertUtils - Convert string '1108' to class 'java.lang.String'
2005-09-29 11:23:58,171 DEBUG org.apache.commons.beanutils.ConvertUtils - Using converter org.apache.commons.beanutils.converters.StringConverter@1f95673
2005-09-29 11:23:58,171 DEBUG org.apache.struts.action.RequestProcessor - Validating input form properties

Thanks and Regards,
Anuja
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42635
    
  65
I wouldn't be too sure that these are coming from the server - are you using Struts (which is where these are coming from) ?
In log4j you can add something like the following to your setup, in which case you'll only get the more important messages:
log4j.logger.org.apache = WARN, haps
or you can set up a second logger to capture them there.


Ping & DNS - my free Android networking tools app
Anuja Piplapure
Greenhorn

Joined: Feb 06, 2005
Posts: 7
Yes mine is a Struts application, and the log messages are of struts itself.
The suggestion that you made, sure works. But that means all the messages taht I need to log, would be of priority WARN, which is not right.
Is there any way in which my application log messages of all levels - debug, info and so on, be logged in a separate file without any struts messages !?!?
I modified my log4j.properties as follows, but this does not work either, all messages get logged in the root appender with struts + application messages.

log4j.rootLogger=debug,temp
log4j.appender.temp=org.apache.log4j.RollingFileAppender
log4j.appender.temp.File=d:/bea/logs/tempLog.log
log4j.appender.temp.MaxFileSize=500000KB
log4j.appender.temp.MaxBackupIndex=3
log4j.appender.temp.layout=org.apache.log4j.PatternLayout
log4j.appender.temp.layout.ConversionPattern=%d %-5p %C - %m%n

log4j.category.com.optus.au.delphi=info,haps
log4j.appender.haps=org.apache.log4j.RollingFileAppender
log4j.appender.haps.File=d:/bea/user_projects/mydomain/hapsAppMessages.log
log4j.appender.haps.MaxFileSize=500000KB
log4j.appender.haps.MaxBackupIndex=3
log4j.appender.haps.layout=org.apache.log4j.PatternLayout
log4j.appender.haps.layout.ConversionPattern=%d %-5p %C - %m%n

regs,
Anuja
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42635
    
  65
But that means all the messages taht I need to log, would be of priority WARN, which is not right.

No, it does not. It means that all messages coming from classes in the org.apache hierarchy must be of level WARNING or higher to be logged. For all other messages the level you defined is used (which is DEBUG in your example). Thus none of the DEBUG or INFO messages from Struts would be logged.
Chris Casey
Greenhorn

Joined: Oct 09, 2005
Posts: 1
This worked for me:

Log config properties files:

log4j.rootLogger=ERROR, R



log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=C:/Logging_Output.log

log4j.appender.R.MaxFileSize=500000KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=3

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d %-5p %c - %m%n




Initialization and basic logging:


file = (String) properties.get("LOG4J_CONFIG_PROP");
System.out.println("Init log4j:" + dir + file);
PropertyConfigurator.configure(dir+file);

//Turn off apache logging
Logger log = Logger.getLogger("org.apache");
log.setLevel(org.apache.log4j.Level.OFF);

//Turn on my logging
log = Logger.getLogger("org.mypackage");
log.setLevel(org.apache.log4j.Level.ALL);

myLayout = new SimpleLayout();
myAppender = new ConsoleAppender(myLayout); // Appender is
myLogger = Logger.getLogger(StartupPlugIn.class.getName());
myLogger.addAppender(myAppender);
myLogger.setLevel(org.apache.log4j.Level.ALL);

myLogger.info("StartupPluging completed loading successfully.");
myLogger.debug("Opertion completed successfully");
myLogger.error("An error condition was reached.");
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to filter log messages while using log4j ?