Switched to a logger system instead of System.out

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
Louis Vallat 2020-10-25 14:38:03 +01:00
parent 7b4edc70f1
commit e2f9ca8b8d
3 changed files with 59 additions and 2 deletions

View File

@ -1,13 +1,23 @@
plugins {
id 'java'
id 'application'
}
group 'xyz.vallat.louis'
version '0.1-SNAPSHOT'
apply plugin : 'java'
ext {
javaMainClass = 'xyz.vallat.louis.MovieQuoteBot'
}
application {
mainClassName = javaMainClass
}
jar {
manifest {
attributes 'Main-Class': 'xyz.vallat.louis.MovieQuoteBot'
attributes 'Main-Class': javaMainClass
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
@ -21,4 +31,5 @@ repositories {
}
dependencies {
implementation 'ch.qos.logback:logback-classic:1.2.3'
}

View File

@ -1,9 +1,13 @@
package xyz.vallat.louis;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MovieQuoteBot {
public static void main(String[] args) {
System.out.println("Hello World!");
Logger logger = LoggerFactory.getLogger(MovieQuoteBot.class.getCanonicalName());
logger.debug("Hello World!");
}
}

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">
<!-- You can configure per-logger level at this point -->
<!-- This set of preconfigured loggers is good if you want to have a DEBUG level as baseline -->
<logger name="io.netty" level="INFO"/>
<logger name="reactor" level="INFO"/>
<!-- Display the logs in your console with the following format -->
<!-- You can learn more about this here: https://logback.qos.ch/manual/layouts.html#ClassicPatternLayout -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!-- Log to a file as well, including size and time based rolling -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>logs/d4j.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>90</maxHistory>
</rollingPolicy>
<encoder>
<charset>UTF-8</charset>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %-40.40logger{39} : %msg%n</Pattern>
</encoder>
<prudent>true</prudent>
</appender>
<!-- Avoid blocking while logging to file by wrapping our file appender with async capabilities -->
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>512</queueSize>
<appender-ref ref="FILE"/>
</appender>
<!-- Here you can set the base logger level. If DEBUG is too chatty for you, you can use INFO -->
<!-- Possible options are: ALL, TRACE, DEBUG, INFO, WARN, ERROR, OFF -->
<root level="ALL">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
</configuration>