Merge pull request #470 from aborkov/master

Added log4j project
This commit is contained in:
slavisa-baeldung 2016-07-08 09:58:20 +02:00 committed by GitHub
commit c9d51d3e60
8 changed files with 199 additions and 0 deletions

64
log4j/pom.xml Normal file
View File

@ -0,0 +1,64 @@
<?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>
<!--disruptor for log4j2 async logging-->
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.3.4</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>

View File

@ -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");
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.log4j2;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
public class Log4j2Example {
private static final Logger logger = LogManager.getLogger(Log4j2Example.class);
public static void main(String[] args) {
logger.debug("Debug log message");
logger.info("Info log message");
logger.error("Error log message");
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.logback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LogbackExample {
private static final Logger logger = LoggerFactory.getLogger(LogbackExample.class);
public static void main(String[] args) {
logger.debug("Debug log message");
logger.info("Info log message");
logger.error("Error log message");
}
}

View File

@ -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} %p %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>

View File

@ -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} %p %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} %p %m%n"/>
</File>
</Appenders>
<Loggers>
# Override log level for specified package
<Logger name="com.baeldung.log4j2" level="TRACE"/>
<AsyncRoot level="DEBUG">
<AppenderRef ref="stdout" />
<AppenderRef ref="fout"/>
</AsyncRoot>
</Loggers>
</Configuration>

View File

@ -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} %p %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} %p %m%n</pattern>
</encoder>
</appender>
# Override log level for specified package
<logger name="com.baeldung.logback" level="TRACE"/>
<root level="DEBUG">
<appender-ref ref="stdout" />
<appender-ref ref="fout" />
</root>
</configuration>

View File

@ -36,6 +36,7 @@
<!-- <module>raml</module> -->
<module>rest-testing</module>
<module>resteasy</module>
<module>log4j</module>
<module>spring-all</module>
<module>spring-apache-camel</module>