1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-22 20:32:05 +01:00

Improve library usage of slf4j and logback.

Logback-classic is now a test dependency and is additionally declared as OPTIONAL runtime dependency.
Applications that don't want to use logback can now easily disable it by not explicitly depending on it.
This commit is contained in:
Paul Schaub 2021-10-29 20:28:14 +02:00
parent 2d364d0939
commit a9a61bc799
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
9 changed files with 82 additions and 31 deletions

View file

@ -65,6 +65,7 @@ allprojects {
project.ext {
slf4jVersion = '1.7.32'
logbackVersion = '1.2.6'
junitVersion = '5.7.2'
picocliVersion = '4.6.1'
rootConfigDir = new File(rootDir, 'config')

View file

@ -33,16 +33,17 @@ dependencies {
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
// https://todd.ginsberg.com/post/testing-system-exit/
testImplementation 'com.ginsberg:junit5-system-exit:1.1.1'
// We want logback logging in tests
testImplementation 'ch.qos.logback:logback-classic:1.2.5'
// implementation "ch.qos.logback:logback-core:1.2.6"
// We want logback logging in tests and in the app
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
implementation "ch.qos.logback:logback-classic:$logbackVersion"
implementation(project(":pgpainless-sop"))
implementation(project(":sop-java"))
implementation(project(":sop-java-picocli"))
implementation "info.picocli:picocli:$picocliVersion"
// We don't want logging in the application itself
implementation "org.slf4j:slf4j-nop:$slf4jVersion"
// https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'

View file

@ -4,15 +4,23 @@ SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
SPDX-License-Identifier: Apache-2.0
-->
<configuration>
<configuration debug="false">
<appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender">
<target>System.err</target>
<encoder>
<pattern>%blue(%-5level) %green(%logger{35}) - %msg %n</pattern>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.apache" level="INFO ">
<appender-ref ref="STDERR"/>
</logger>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<target>System.out</target>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="error">
<appender-ref ref="STDERR" />
</root>
</configuration>

View file

@ -0,0 +1,25 @@
<!--
SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
SPDX-License-Identifier: Apache-2.0
-->
<configuration debug="false">
<appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender">
<target>System.err</target>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<target>System.out</target>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="error">
<appender-ref ref="STDERR" />
</root>
</configuration>

View file

@ -10,9 +10,11 @@ dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
testImplementation 'ch.qos.logback:logback-classic:1.2.5'
// Logging
api "org.slf4j:slf4j-api:$slf4jVersion"
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
runtime "ch.qos.logback:logback-classic:$logbackVersion"
api "org.bouncycastle:bcprov-jdk15on:$bouncyCastleVersion"
api "org.bouncycastle:bcpg-jdk15on:$bouncyCastleVersion"

View file

@ -1,18 +0,0 @@
<!--
SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
SPDX-License-Identifier: Apache-2.0
-->
<configuration>
<appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender">
<target>System.err</target>
<encoder>
<pattern>%blue(%-5level) %green(%logger{35}) - %msg %n</pattern>
</encoder>
</appender>
<logger name="org.apache" level="INFO ">
<appender-ref ref="STDERR"/>
</logger>
</configuration>

View file

@ -0,0 +1,29 @@
<!--
SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
SPDX-License-Identifier: Apache-2.0
-->
<configuration debug="false">
<appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender">
<target>System.err</target>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<target>System.out</target>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.pgpainless" level="warn" additivity="false">
<appender-ref ref="STDOUT" />
</logger>
<root level="error">
<appender-ref ref="STDERR" />
</root>
</configuration>

View file

@ -13,10 +13,12 @@ repositories {
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
testImplementation 'ch.qos.logback:logback-classic:1.2.5'
// Logging
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
runtime "ch.qos.logback:logback-classic:$logbackVersion"
implementation(project(":pgpainless-core"))
implementation(project(":sop-java"))

View file

@ -9,6 +9,7 @@ plugins {
dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
// https://todd.ginsberg.com/post/testing-system-exit/
testImplementation 'com.ginsberg:junit5-system-exit:1.1.1'
testImplementation "org.mockito:mockito-core:3.11.2"