Simple Log4j ConfigurationLog4j is a simple logging framework. you can download the latest version of log4j ( Download ). After download finished add jar in class path log4j-x.x.x.jar. Create a new HelloLogger.java file. package com.abc.helloworld; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Logger; public class HelloLogger { static final Logger logger = Logger.getLogger(HelloLogger.class); public static void main(String[] args) { BasicConfigurator.configure(); logger.debug("Hello World!"); } } Log4j available methods are info(), warn(), error() and fatal() , logger levels are DEBUG, INFO, WARN, ERROR, FATAL . Following example shows usage of method. package com.abc.helloworld; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Logger; public class HelloLogger { static final Logger logger = Logger.getLogger(HelloLogger.class); public static void main(String[] args) { BasicConfigurator.configure(); logger.debug("debug message"); logger.info("info message"); logger.warn("warn message"); logger.error("error message"); logger.fatal("fatal message"); } }Output of the above code. 0 [main] DEBUG com.abc.helloworld.HelloLogger - debug message 0 [main] INFO com.abc.helloworld.HelloLogger - info message 0 [main] WARN com.abc.helloworld.HelloLogger - warn message 0 [main] ERROR com.abc.helloworld.HelloLogger - error message 0 [main] FATAL com.abc.helloworld.HelloLogger - fatal message Enjoy log4j in you web application. |
Wednesday, February 29, 2012
Subscribe to:
Post Comments (Atom)
AWS EC2 - SSH locked with UFW
Need to update the instance's user data: 1. Stop the instance 2. Right click (windows) or ctrl + click (Mac) on the instance to open a c...
-
Cross-Origin Resource Sharing (CORS) response headers to Camunda REST engine in wildfly (standalone.xml) distribution. <subsystem xmln...
-
It's batter to configure bind9 (DNS) before installing zimbra. First let's install some prerequisites for Zimbra ...
-
Install and Configure the IBR Step 1) Connect to the Inbound Refinery at http://yourhostname:16250/ibr as the weblogic user, and the fir...
No comments:
Post a Comment