Skip to content

Commit 5c2d340

Browse files
authored
Merge pull request #757 from KyoriPowered/feature/slf4j-logger
text-logger-slf4j: introduce wrapper for formatted logging
2 parents ff95e34 + 916a596 commit 5c2d340

File tree

15 files changed

+3208
-0
lines changed

15 files changed

+3208
-0
lines changed

.checkstyle/suppressions.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
<suppress files="src[\\/](test|jmh)[\\/]java[\\/].*" checks="(FilteringWriteTag|JavadocPackage|MissingJavadoc.*)"/>
99
<suppress files="api[\\/]src[\\/]main[\\/]java[\\/]net[\\/]kyori[\\/]adventure[\\/]internal[\\/].*" checks="(FilteringWriteTag|JavadocPackage|MissingJavadoc.*)"/>
1010
<suppress files="minimessage[\\/]src[\\/]main[\\/]java[\\/]net[\\/]kyori[\\/]adventure[\\/]text[\\/]minimessage[\\/]parser[\\/].*" checks="(FilteringWriteTag|JavadocPackage|MissingJavadoc.*)"/>
11+
12+
<!-- no package JD on multirelease variants -->
13+
<suppress files="src[\\/]main[\\/]java\d+[\\/].*" checks="JavadocPackage"/>
1114

1215
<suppress files=".*[\\/]nbt[\\/](List|Compound)BinaryTag.java" checks="MethodName"/>
1316
</suppressions>

bom/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies {
1818
"nbt",
1919
"serializer-configurate3",
2020
"serializer-configurate4",
21+
"text-logger-slf4j",
2122
"text-minimessage",
2223
"text-serializer-gson",
2324
"text-serializer-gson-legacy-impl",

gradle/libs.versions.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ indra = "2.1.1"
1010
jmh = "1.35"
1111
jmhPlugin = "0.6.6"
1212
junit = "5.8.2"
13+
mockito = "4.5.1"
14+
slf4j = "1.7.36"
1315
truth = "1.1.3"
1416

1517
[libraries]
@@ -28,6 +30,10 @@ kotlin-testJunit5 = { module = "org.jetbrains.kotlin:kotlin-test-junit5" }
2830
configurate-v3 = "org.spongepowered:configurate-core:3.7.3"
2931
configurate-v4 = "org.spongepowered:configurate-core:4.1.2"
3032

33+
# text-logger-slf4j
34+
slf4j = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
35+
slf4jtest = "com.github.valfirst:slf4j-test:2.6.1" # Specific versions are needed for different SLF4J versions
36+
3137
# text-serializer-gson
3238
gson = "com.google.code.gson:gson:2.8.0"
3339

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ sequenceOf(
3434
"nbt",
3535
"serializer-configurate3",
3636
"serializer-configurate4",
37+
"text-logger-slf4j",
3738
"text-minimessage",
3839
"text-serializer-gson",
3940
"text-serializer-gson-legacy-impl",

text-logger-slf4j/build.gradle.kts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
plugins {
2+
id("adventure.common-conventions")
3+
}
4+
5+
dependencies {
6+
api(projects.adventureApi)
7+
api(libs.slf4j)
8+
testImplementation(libs.slf4jtest)
9+
}
10+
11+
sourceSets.main {
12+
multirelease {
13+
alternateVersions(9)
14+
}
15+
}
16+
17+
applyJarMetadata("net.kyori.adventure.text.logger.slf4j")
18+
19+
eclipse {
20+
// Make sure slf4j doesn't end up on the module path until we are actually a module
21+
classpath.file.whenMerged {
22+
(this as org.gradle.plugins.ide.eclipse.model.Classpath).entries.forEach { entry ->
23+
if (entry is org.gradle.plugins.ide.eclipse.model.Library) {
24+
entry.entryAttributes["module"] = false
25+
}
26+
}
27+
}
28+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* This file is part of adventure, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2017-2022 KyoriPowered
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package net.kyori.adventure.text.logger.slf4j;
25+
26+
// Java 8 version, see Java 9 version as well
27+
final class CallerClassFinder {
28+
private CallerClassFinder() {
29+
}
30+
31+
static String callingClassName() {
32+
return callingClassName(2); // this, plus the calling method
33+
}
34+
35+
static String callingClassName(final int elementsToSkip) { // elementsToSkip not counting this method
36+
final StackTraceElement[] elements = Thread.currentThread().getStackTrace(); // includes call to getStackTrace()
37+
if (elements.length <= elementsToSkip) {
38+
throw new IllegalArgumentException("Not enough stack elements to skip " + elementsToSkip + " elements");
39+
} else {
40+
return elements[elementsToSkip + 2].getClassName();
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)