aspose file tools*
The moose likes Other Open Source Projects and the fly likes How to suppress warnings thrown by log4j? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "How to suppress warnings thrown by log4j?" Watch "How to suppress warnings thrown by log4j?" New topic
Author

How to suppress warnings thrown by log4j?

joydeep sarkar
Greenhorn

Joined: Nov 13, 2008
Posts: 23
Hello All,

I am getting a warning message as following at the time of server start up,

log4j:WARN File option not set for appender
log4j:WARN Are you using FileAppender instead of ConsoleAppender?

The logging mechanism is working fine. I don't want the message to be displayed.
Could anyone suggest how to suppress this warning?

Thanks in advance,
Joydeep
joydp.s@gmail.com
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi there and welcome to Javaranch!

Usually that warning occurs because the logging is not configured properly, e.g. the log4j.properties or log4j.xml cannot be found. But if you say your logging is working....

Can you post the contents of your configuration file, we might be able to spot something


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
joydeep sarkar
Greenhorn

Joined: Nov 13, 2008
Posts: 23
Hi,

Following is the snippet of log4j.xml which is causing the warning message,

<appender name="auditlog" class="org.apache.log4j.RollingFileAppender">
<!-- <param name="File" value="${jboss.server.home.dir}/../../../log/AuditLog.log" /> -->
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %5p %c{1}:%L - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="DEBUG" />
<param name="LevelMax" value="DEBUG" />
</filter>
</appender>

The "File" parameter is commented out. Needed to override the "File" parameter for purpose. The logging mechanism works as desired. But it is causing the server log to show the warnings at start up.

Is there anyway to bypass/supress all the warning messages coming from log4j configuration?

Regards,
Joydeep
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi there,

You've commented out the <param name="File"... line, that's why you are getting the warning. Log4j expects you to give it a file for that appender
joydeep sarkar
Greenhorn

Joined: Nov 13, 2008
Posts: 23
Hi,

You are right about the "File" param. But that was done on purpose.
Since the "File" param is missing, it is throwing the warning message which I don't want to be visible on the server log.

Is there any way so that log4j generated warning messages won't be visible?

Regards,
Joydeep
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Simply comment out the entire RollingFileAppender section, I assume you have a separate ConsoleAppender?
joydeep sarkar
Greenhorn

Joined: Nov 13, 2008
Posts: 23
Hi,

It removes the warning if I use the ConsoleAppender, but that won't roll over the file at the end of the day, which RollingFileAppender does.
That is why I have been looking for a way to disable the log4j warning.
Do you think any server configuration file or anything else could be used for this?


Regards,
Joydeep
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Huh? I'm confused now. How does your RollingFileAppender work if you don't give it a <param name="File"... entry?
joydeep sarkar
Greenhorn

Joined: Nov 13, 2008
Posts: 23
Hi,

The "File" param is to specify the path of the log file to be generated at. I have overridden the path in java code to make it dynamic. The Appenders won't stop working if the path is missing, except it won't know where to place the log files.
Since I am specifying the path through the java code, the logger works fine. But can't get rid of the worning messages.
So any idea?


Regards,
Joydeep
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Oh OK, that explains that behaviour then. Sorry I can't think of anything off the top of my head
joydeep sarkar
Greenhorn

Joined: Nov 13, 2008
Posts: 23
Thanks mate. I appreciate your help.

Regards,
Joydeep
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Originally posted by joydeep sarkar:
Since I am specifying the path through the java code, the logger works fine. But can't get rid of the worning messages.
So any idea?
Then specify the entire appender through the Java code. Don't configure it at all.
joydeep sarkar
Greenhorn

Joined: Nov 13, 2008
Posts: 23
Hi,

Implementing the appender using java may be a solution, but it will cost a lot of code change and time consumption. So I have been looking for a work around...
Do you think this is the only solution?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to suppress warnings thrown by log4j?