Last active
April 1, 2016 18:12
-
-
Save rahman99/97ed35be4c10bf09a0574ff06eb424db to your computer and use it in GitHub Desktop.
Log4j with properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //file auto must be detect log4j.properties in source | |
| import org.apache.log4j.Logger; | |
| public class HelloExample{ | |
| final static Logger logger = Logger.getLogger(HelloExample.class); | |
| final static Logger log = Logger.getLogger("logging"); | |
| public static void main(String[] args) { | |
| HelloExample obj = new HelloExample(); | |
| obj.runMe("mkyong"); | |
| } | |
| private void runMe(String parameter){ | |
| if(logger.isDebugEnabled()){ | |
| logger.debug("This is debug : " + parameter); | |
| } | |
| if(logger.isInfoEnabled()){ | |
| logger.info("This is info : " + parameter); | |
| } | |
| logger.info("This is info22 : " + parameter); | |
| logger.warn("This is warn : " + parameter); | |
| logger.error("This is error : " + parameter); | |
| logger.fatal("This is fatal : " + parameter); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #file location in src/main/resources | |
| # Root logger option | |
| log4j.rootLogger=DEBUG, stdout, FILE | |
| #location | |
| log = /media/rahman/DATA/Logging | |
| # Redirect log messages to console | |
| log4j.appender.stdout=org.apache.log4j.ConsoleAppender | |
| log4j.appender.stdout.Target=System.out | |
| log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | |
| log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n | |
| # Rirect log messages to a log file | |
| #log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender | |
| log4j.appender.FILE=org.apache.log4j.FileAppender | |
| log4j.appender.FILE.File=${log}/loging.log | |
| log4j.appender.FILE.layout=org.apache.log4j.PatternLayout | |
| log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment