How to fix Java warning for log4j ?

When I compile my java code I get the following warning:

log4j:WARN No appenders could be found for logger (org.apache.axis.description.OperationDesc).
log4j:WARN Please initialize the log4j system properly.

Open in new window

I use log4j to log the errors. How can I get rid of this error? Or actually, how can I fix it?


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You have not configured your log4j system.  The easiest way is to provide a configuration file as explained in under "Configuration" and "Default Initialization Procedure."

At launch, define the system property log4j.configuration (using the -D option on the command line) to point to your configuration file.  If you don't specify the system property, log4j will look for a file called on your classpath.  It couldn't find such a file so it sent you the message that you received.

Look at the small sample configuration files in the "Configuration" section and post here if you have additional questions.
put on your classpath
Sathish David Kumar NArchitectCommented:
>>>>log4j:WARN No appenders could be found for logger (org.apache.axis.description.OperationDesc).  
log4j:WARN Please initialize the log4j system properly

this not a error just warning only ....

in your file

C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

TolgarAuthor Commented:
@dravidnsr: So what should i change in the file?

@garypfirstech: Here is my file. I use Maven to compile my code. Still getting the same issue. I tried to put this file in the same directory where my code is. It did not work. Then I put it under resources directory and it did not work again. And if I need to put it in the classpath, how can I do it?

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.

# An example log4j configuration file that outputs both to System.out
# and a file named 'test'.

# For the general syntax of property based configuration files see the
# documenation of org.apache.log4j.PropertyConfigurator.

# WARNING: Location information can be useful but is very costly in
# terms of computation.

# The root logger uses the appender called A1. 

# The root logger uses the appenders called A1 and A2. Since no level
# is specified, note the empty string between the comma (",") and the
# equals sign ("="), the level of the root logger remains
# untouched. Log4j always initializes the level for the root logger to
# DEBUG. The root logger is the only logger that has a default
# level. Bu default, all other loggers do not have an assigned level,
# such that they inherit their level instead.

log4j.rootLogger=, A1, A2

# A1 is set to be ConsoleAppender sending its output to System.out

# A1 uses PatternLayout.

# The conversion pattern consists of date in ISO8601 format, level,
# thread name, logger name truncated to its rightmost two components
# and left justified to 17 characters, location information consisting
# of file name (padded to 13 characters) and line number, nested
# diagnostic context, the and the application supplied message

log4j.appender.A1.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n

# Appender A2 writes to the file "errorLog".

# Truncate 'test' if it aleady exists.

# Appender A2 uses the PatternLayout.
log4j.appender.A2.layout.ConversionPattern=%-5r %-5p [%t] %c{2} - %m%n

# In this example, we are not interested in INNER loop or SWAP
# messages.  You might try to set INNER and SWAP to DEBUG for more
# verbose output.

Open in new window

Try setting the log4.debug system property (-Dlog4j.debug) and also set the log4j.configuration system property to the absolute pathname of your file.
Sathish David Kumar NArchitectCommented:
>>>>>change this
log4j.rootLogger=, A1, A2

log4j.rootLogger= A1, A2

remove the , infront of A1
David -  This will cause log4j to interpret A1 as a debugging level, not an appender name and will cause problems.  The initial comma indicates that the debugging level is omitted so it defaults to DEBUG.
TolgarAuthor Commented:
ok. I managed to make it work. But it puts everthing in the log file. I only want the warnings and error messages.

So I did this:

	static final Logger logger = Logger.getLogger(batLogData2gecko.class);

Open in new window

But when I compile is says:[30,16] <identifier> expected

Open in new window

How can I fix it?

Usually, you don't set the level in your code but in your configuration file.  To make WARN the default
level for all loggers, change

  log4j.rootLogger=, A1, A2

  log4j.rootLogger=WARN, A1, A2

To leave the default log level as DEBUG but only change it to WARN for a specific logger, add = WARN

What statement is on line 30 in your compile so I can tell which line the message refers to?  Please attach your whole program if you can and I can try to compile it here.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TolgarAuthor Commented:
ok .I made this change.

Normally if no warnings or errors occur, is this errorLog file created or is it only created when an error or warning occurs?

Because, when I run my code after changing it to warn no errorLog file was generated.

I believe that it's created on the first write of a log message to it.
Sathish David Kumar NArchitectCommented:
your not mention the log file path .
TolgarAuthor Commented:
Well, then I changed this line:

Open in new window


Open in new window


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.