BAEL-65 - logging to files
This commit is contained in:
parent
d67f19d9e5
commit
acaa70c66d
|
@ -21,24 +21,24 @@
|
|||
<!--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>-->
|
||||
<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>-->
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.1.7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -4,28 +4,28 @@
|
|||
<!--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" />
|
||||
<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" />
|
||||
<param name="file" value="log4j/target/baeldung-log4j.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" />
|
||||
<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" />
|
||||
<priority value="TRACE"/>
|
||||
</category>
|
||||
|
||||
<root>
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="stdout" />
|
||||
<appender-ref ref="fout" />
|
||||
<level value="DEBUG"/>
|
||||
<appender-ref ref="stdout"/>
|
||||
<appender-ref ref="fout"/>
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
|
@ -8,7 +8,7 @@
|
|||
</Console>
|
||||
|
||||
# File appender
|
||||
<File name="fout" fileName="baeldung.log" immediateFlush="false" append="false">
|
||||
<File name="fout" fileName="log4j/target/baeldung-log4j2.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>
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
<Loggers>
|
||||
# Override log level for specified package
|
||||
<Logger name="com.baeldung.log4j" level="TRACE"/>
|
||||
<Logger name="com.baeldung.log4j2" level="ERROR"/>
|
||||
|
||||
<Root level="DEBUG">
|
||||
<AppenderRef ref="stdout" />
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
# File appender
|
||||
<appender name="fout" class="ch.qos.logback.core.FileAppender">
|
||||
# Name of a log file
|
||||
<file>baeldung.log</file>
|
||||
<file>log4j/target/baeldung-logback.log</file>
|
||||
<append>false</append>
|
||||
<encoder>
|
||||
# Pattern of log message for file appender
|
||||
|
@ -19,7 +19,7 @@
|
|||
</appender>
|
||||
|
||||
# Override log level for specified package
|
||||
<logger name="com.baeldung.log4j" level="TRACE"/>
|
||||
<logger name="com.baeldung.logback" level="ERROR"/>
|
||||
|
||||
<root level="DEBUG">
|
||||
<appender-ref ref="stdout" />
|
||||
|
|
Loading…
Reference in New Issue