Skip to content

Commit 191ca19

Browse files
authored
Improve jul sample for easier debugging inside IDE (#2058)
* Improve jul sample for easier debugging inside IDE * Add comment on how to specify logging.properties file instead of in the code
1 parent 3f10556 commit 191ca19

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

buildSrc/src/main/java/Config.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ object Config {
5252
val androidxRecylerView = "androidx.recyclerview:recyclerview:1.2.1"
5353

5454
val slf4jApi = "org.slf4j:slf4j-api:1.7.30"
55+
val slf4jJdk14 = "org.slf4j:slf4j-jdk14:1.7.30"
5556
val logbackVersion = "1.2.9"
5657
val logbackClassic = "ch.qos.logback:logback-classic:$logbackVersion"
5758

sentry-samples/sentry-samples-jul/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ plugins {
88

99
application {
1010
mainClass.set("io.sentry.samples.jul.Main")
11-
applicationDefaultJvmArgs = mutableListOf("-Djava.util.logging.config.file=${project.projectDir}/src/main/resources/logging.properties")
1211
}
1312

1413
configure<JavaPluginExtension> {
@@ -18,5 +17,5 @@ configure<JavaPluginExtension> {
1817

1918
dependencies {
2019
implementation(projects.sentryJul)
21-
implementation(Config.Libs.logbackClassic)
20+
implementation(Config.Libs.slf4jJdk14)
2221
}

sentry-samples/sentry-samples-jul/src/main/java/io/sentry/samples/jul/Main.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@
22

33
import java.util.UUID;
44
import java.util.logging.Level;
5+
import java.util.logging.LogManager;
56
import java.util.logging.Logger;
67
import org.slf4j.MDC;
78

89
public class Main {
910

1011
private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
1112

12-
public static void main(String[] args) {
13+
public static void main(String[] args) throws Exception {
14+
// instead of the following line you can also pass
15+
// -Djava.util.logging.config.file=.../logging.properties to the
16+
// java command
17+
LogManager.getLogManager()
18+
.readConfiguration(Main.class.getClassLoader().getResourceAsStream("logging.properties"));
1319
LOGGER.config("Hello Sentry!");
1420

1521
// MDC parameters are converted to Sentry Event tags
1622
MDC.put("userId", UUID.randomUUID().toString());
23+
MDC.put("requestId", UUID.randomUUID().toString());
1724

1825
// logging arguments are converted to Sentry Event parameters
1926
LOGGER.log(Level.INFO, "User has made a purchase of product: %d", 445);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
io.sentry.jul.SentryHandler.minimumEventLevel=INFO
1+
io.sentry.jul.SentryHandler.minimumEventLevel=DEBUG
22
io.sentry.jul.SentryHandler.minimumBreadcrumbLevel=CONFIG
33
io.sentry.jul.SentryHandler.printfStyle=true
44
io.sentry.jul.SentryHandler.level=CONFIG
5-
io.sentry.samples.jul.Main.handlers=io.sentry.jul.SentryHandler
6-
io.sentry.samples.jul.Main.level=CONFIG
5+
handlers=io.sentry.jul.SentryHandler
6+
level=CONFIG

0 commit comments

Comments
 (0)