How to fix Java warning for log4j ?

Hi,
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?

Thanks,

TolgarAsked:
Who is Participating?

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

x
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.

garypfirstechCommented:
You have not configured your log4j system.  The easiest way is to provide a configuration file as explained in http://logging.apache.org/log4j/1.2/manual.html 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 log4j.properties 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.
tarunwaliaCommented:
put log4j.properties 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 log4j.property file

log4j.rootCategory=info,rolling,error,WARN

log4j.category.your.category.name=WARN
log4j.category.your.category.name=INHERITED
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 log4j.properties file?

@garypfirstech: Here is my log4j.properties 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
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# 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
log4j.appender.A1=org.apache.log4j.ConsoleAppender


# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.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".
log4j.appender.A2=org.apache.log4j.FileAppender
log4j.appender.A2.File=errorLog

# Truncate 'test' if it aleady exists.
log4j.appender.A2.Append=false

# Appender A2 uses the PatternLayout.
log4j.appender.A2.layout=org.apache.log4j.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.

log4j.logger.org.apache.log4j.examples.SortAlgo.INNER=INFO
log4j.logger.org.apache.log4j.examples.SortAlgo.SWAP=INFO

Open in new window


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

into
log4j.rootLogger= A1, A2

remove the , infront of A1
garypfirstechCommented:
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);
	logger.setLevel(Level.WARN);

Open in new window


But when I compile is says:

myFile.java:[30,16] <identifier> expected

Open in new window


How can I fix it?


Thanks,
garypfirstechCommented:
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
to

  log4j.rootLogger=WARN, A1, A2

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

  log4j.logger.fully.qualified.name.batLogData2gecko = 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.

Thanks,
garypfirstechCommented:
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:
log4j.appender.A2.File=errorLog

Open in new window


to
log4j.appender.A2.File=/path/To/File/errorLog

Open in new window


Thanks,

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
Java

From novice to tech pro — start learning today.