Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to suppress warnings thrown by log4j?

 
joydeep sarkar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
joydeep sarkar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simply comment out the entire RollingFileAppender section, I assume you have a separate ConsoleAppender?
 
joydeep sarkar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Huh? I'm confused now. How does your RollingFileAppender work if you don't give it a <param name="File"... entry?
 
joydeep sarkar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh OK, that explains that behaviour then. Sorry I can't think of anything off the top of my head
 
joydeep sarkar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks mate. I appreciate your help.

Regards,
Joydeep
 
Paul Clapham
Sheriff
Posts: 21319
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic