After adding log4j to my application I get the following output every time I execute my application:
log4j:WARN No appenders could be found for logger (slideselector.facedata.FaceDataParser). log4j:WARN Please initialize the log4j system properly.
It seems this means a configuration file is missing. Where should this config file be located and what is a good start content?
I'm using plain java for developing a desktop application. So no webserver etc...
Log4j by default looks for a file called log4j.properties or log4j.xml on the classpath. You can control which file it uses to initialize itself by setting system properties as described here (Look for the "Default Initialization Procedure" section).
For example:
Will cause log4j to look for a file called customName on the classpath.
If you are having problems I find it helpful to turn on the log4j.debug:
It will print to System.out lots of helpful information about which file it used to initialize itself, which loggers / appenders got configured and how etc.
The configuration file can be a java properties file or an xml file. Here is a sample of the properties file format taken from the log4j intro documentation page:
While setting up log4j properly is great for "real" projects you might want a quick-and-dirty solution, e.g. if you're just testing a new library.
If so a call to the static method
will setup basic logging to the console, and the error messages will be gone.
I've created file log4j.properties in resources folder next to hibernate.cfg.xml file and filled it with text below:
now I got rid of warnings and errors
Logging API - The Java Logging API facilitates software servicing and maintenance at customer sites by producing log reports suitable for analysis by end users, system administrators, field service engineers, and software development teams. The Logging APIs capture information such as security failures, configuration errors, performance bottlenecks, and/or bugs in the application or platform. The core package includes support for delivering plain text or XML formatted log records to memory, output streams, consoles, files, and sockets. In addition, the logging APIs are capable of interacting with logging services that already exist on the host operating system.
Package java.util.logging « Provides the classes and interfaces of the Java platform's core logging facilities.
Log4j 1.x « log4j is a popular Java-based logging utility. Log4j is an open source project based on the work of many authors. It allows the developer to control which log statements are output to a variety of locations by using Appenders [console, files, DB and email]. It is fully configurable at runtime using external configuration files.
Configuration files can be written in XML or in Java properties (key=value) format.
MySQL Table structure for table
logdata
To enable
-Dlog4j.debug
, I go to System, Advanced system settings, Environment variables and set system variable_JAVA_OPTIONS
to-Dlog4j.debug
.If you just get rid of everything (e.g. if you are in tests)