log4j2.properties
SampleTest.java
Mylogs.log
name=PropertiesConfig
property.filename = logs
appenders = console, file
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
appender.file.type = File
appender.file.name = LOGFILE
appender.file.fileName=${filename}/myLogs.log
appender.file.layout.type=PatternLayout
appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
loggers=file
logger.file.name=kavoor
logger.file.level = debug
logger.file.appenderRefs = file
logger.file.appenderRef.file.ref = LOGFILE
rootLogger.level = debug
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT
SampleTest.java
package kavoor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class LoggerSample {
private static Logger logger = LogManager.getLogger(LoggerSample.class);
public static void main(String[] args) {
logger.info("Info");
logger.warn("Warn");
logger.debug("Debug");
logger.error("Error");
logger.fatal("Fatal");
}
}
Mylogs.log
[INFO ] 2019-03-27 15:55:06.748 [main] LoggerSample - Info
[WARN ] 2019-03-27 15:55:06.751 [main] LoggerSample - Warn
[DEBUG] 2019-03-27 15:55:06.751 [main] LoggerSample - Debug
[ERROR] 2019-03-27 15:55:06.751 [main] LoggerSample - Error
[FATAL] 2019-03-27 15:55:06.751 [main] LoggerSample - Fatal
No comments:
Post a Comment