• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1107
  • Last Modified:

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,

0
Tolgar
Asked:
Tolgar
  • 5
  • 4
  • 3
  • +1
3 Solutions
 
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.
0
 
tarunwaliaCommented:
put log4j.properties on your classpath
0
 
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
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
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,
0
 
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.
0
 
Sathish David Kumar NArchitectCommented:
>>>>>change this
log4j.rootLogger=, A1, A2

into
log4j.rootLogger= A1, A2

remove the , infront of A1
0
 
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.
0
 
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,
0
 
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.
0
 
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,
0
 
garypfirstechCommented:
I believe that it's created on the first write of a log message to it.
0
 
Sathish David Kumar NArchitectCommented:
your not mention the log file path .
0
 
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,

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now