Log4jFrom Libzter
Log4j
[edit] OverviewLog4j is a simple and highly configurable logging library for Java projects. Log4j is governed by the apache foundation official site. One of the biggest asset off using Log4j is that you can configure different appenders which enables you to get the your logging as it may fit you (ex. File, Database, JMS and so on). With Log4j you are also able to specify the layout of your logging. Log4j is an open source project and comes with an apache license. [edit] SpecificationsLog4j requires you to run JDK1.3 or greater. [edit] Features
[edit] Log LevelsLog levels are a number of levels that log4j is able to log to. The levels are DEBUG, INFO, WARN, ERROR, FATAL. When a program that implements log4j runs it defines on what specific level that it wants to log on and all messages that correspond to that and higher level (DEBUG lowest, FATAL highest) will then be logged to the output. [edit] ConfigurationThe configuration of log4j can be done in a simple property file or an XML file. In the configuration you can configure what Appenders (small program/classes that handle log4j output to different mediums ex file, db) you want, what level they will log on and in some cases how the output will look like. configuration reference [edit] InstallationYou will have to copy the Log4j jar file and make sure it is included in you classpath. You will also have to create a Log4j configuration file that is loaded when your program starts. [edit] Usagepackage com.foo; import org.apache.log4j.Logger; public class Foo { static Logger logger = Logger.getLogger(Foo.class); public void execute() { logger.info("Executing Foo"); } } [edit] Extendabiblity
User comments on this article (Log4j)
MrCode posted this comment [2009-05-18 15:31:39]
1
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Log4j is a great log tool to use for you Java applications. I really like the highly configurable nature of the library. It's good that you after you program is package as a JAR can change its logging capabilities. |
||
At this point you should be using Logback instead. It is intended as a replacement for log4j.