Moving to SLF4J

This commit is contained in:
Bruce Eckel 2016-08-16 18:03:29 -06:00
parent 69dec45d88
commit 0345f21650
5 changed files with 22 additions and 35 deletions

View File

@ -139,6 +139,10 @@ subprojects {
dependencies {
compile 'junit:junit:4.12'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'
// You can also use the JDK's built-in logging as the back end:
// compile group: 'org.slf4j', name: 'slf4j-jdk14', version: '1.7.5'
}
sourceSets {

View File

@ -1,19 +0,0 @@
// verifying/InfoLogging.java
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {ErrorOutputExpected}
import org.apache.logging.log4j.*;
public class InfoLogging {
private static final Logger logger =
LogManager.getLogger(InfoLogging.class);
public static void main(String[] args) {
logger.info("Logging: INFO-level message");
}
}
/* Output:
___[ Error Output ]___
Jul 27, 2016 10:50:39 AM InfoLogging main
INFO: Logging: INFO-level message
*/

View File

@ -0,0 +1,16 @@
// verifying/SLF4JLogging.java
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
import org.slf4j.*;
public class SLF4JLogging {
private static final Logger logger =
LoggerFactory.getLogger(SLF4JLogging.class);
public static void main(String[] args) {
logger.info("hello logging");
}
}
/* Output:
17:58:42.798 [main] INFO SLF4JLogging - hello logging
*/

View File

@ -7,8 +7,8 @@ import java.util.*;
import org.junit.*;
import static org.junit.Assert.*;
// So we can see the list objects being created,
// and keep track of when they are cleaned up:
// Keeps track of list objects as they are
// created and cleaned up:
class CountedList extends ArrayList<String> {
private static int counter = 0;
private int id = counter++;

View File

@ -1,14 +0,0 @@
// verifying/log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{YYYY-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>