Posted on

How to use log4j in Java

How to use log4j - Java:

package com.javadoc;

import org.apache.log4j.Logger;

 * This class is used to show how to use log4j with javadoc.
 * @author javadoc
 * @version 1.0
 * @since 1.8
public class Log4jExample {

   /* Get actual class name to be printed on */
   static Logger log = Logger.getLogger(Log4jExample.class.getName());

    * This is the main method which makes use of debug, info, warn, error and fatal methods.
    * @param args Unused.
    * @return Nothing.
    * @exception IOException On input error.
    * @see IOException
   public static void main(String[] args) {

      log.debug("Hello this is a debug message");
      log.info("Hello this is an info message");
      log.warn("Hello this is a warn message");
      log.error("Hello this is an error message");
      log.fatal("Hello this is a fatal message");


Enter fullscreen mode Exit fullscreen mode

Top comments (0)