Added log4j project
This commit is contained in:
parent
edabeee9d8
commit
d9240931cf
|
@ -0,0 +1,61 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<!--log4j dependencies-->
|
||||
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--log4j2 dependencies-->
|
||||
|
||||
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.apache.logging.log4j</groupId>-->
|
||||
<!--<artifactId>log4j-api</artifactId>-->
|
||||
<!--<version>2.6</version>-->
|
||||
<!--</dependency>-->
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.apache.logging.log4j</groupId>-->
|
||||
<!--<artifactId>log4j-core</artifactId>-->
|
||||
<!--<version>2.6</version>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
<!--logback dependencies-->
|
||||
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>ch.qos.logback</groupId>-->
|
||||
<!--<artifactId>logback-classic</artifactId>-->
|
||||
<!--<version>1.1.7</version>-->
|
||||
<!--</dependency>-->
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<debug>true</debug>
|
||||
<optimize>true</optimize>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<showWarnings>true</showWarnings>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,17 @@
|
|||
package com.baeldung.log4j;
|
||||
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class Log4jExample {
|
||||
|
||||
private final static Logger logger = Logger.getLogger(Log4jExample.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
logger.trace("Trace log message");
|
||||
logger.debug("Debug log message");
|
||||
logger.info("Info log message");
|
||||
logger.error("Error log message");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
|
||||
<log4j:configuration debug="false">
|
||||
|
||||
<!--Console appender-->
|
||||
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %p %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- File appender-->
|
||||
<appender name="fout" class="org.apache.log4j.FileAppender">
|
||||
<param name="file" value="baeldung.log" />
|
||||
<param name="append" value="false" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!--Override log level for specified package-->
|
||||
<category name="com.baeldung.log4j">
|
||||
<priority value="TRACE" />
|
||||
</category>
|
||||
|
||||
<root>
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="stdout" />
|
||||
<appender-ref ref="fout" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="INFO">
|
||||
<Appenders>
|
||||
# Console appender
|
||||
<Console name="stdout" target="SYSTEM_OUT">
|
||||
# Pattern of log message for console appender
|
||||
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n" />
|
||||
</Console>
|
||||
|
||||
# File appender
|
||||
<File name="fout" fileName="baeldung.log" immediateFlush="false" append="false">
|
||||
# Pattern of log message for file appender
|
||||
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n"/>
|
||||
</File>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
# Override log level for specified package
|
||||
<Logger name="com.baeldung.log4j" level="TRACE"/>
|
||||
|
||||
<Root level="DEBUG">
|
||||
<AppenderRef ref="stdout" />
|
||||
<AppenderRef ref="fout"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
|
@ -0,0 +1,28 @@
|
|||
<configuration>
|
||||
# Console appender
|
||||
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
# Pattern of log message for console appender
|
||||
<Pattern>%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n</Pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
# File appender
|
||||
<appender name="fout" class="ch.qos.logback.core.FileAppender">
|
||||
# Name of a log file
|
||||
<file>baeldung.log</file>
|
||||
<append>false</append>
|
||||
<encoder>
|
||||
# Pattern of log message for file appender
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
# Override log level for specified package
|
||||
<logger name="com.baeldung.log4j" level="TRACE"/>
|
||||
|
||||
<root level="DEBUG">
|
||||
<appender-ref ref="stdout" />
|
||||
<appender-ref ref="fout" />
|
||||
</root>
|
||||
</configuration>
|
Loading…
Reference in New Issue