Skip to content

Commit

Permalink
Improve jul sample for easier debugging inside IDE (#2058)
Browse files Browse the repository at this point in the history
* Improve jul sample for easier debugging inside IDE

* Add comment on how to specify logging.properties file instead of in the code
  • Loading branch information
adinauer authored May 19, 2022
1 parent 3f10556 commit 191ca19
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ object Config {
val androidxRecylerView = "androidx.recyclerview:recyclerview:1.2.1"

val slf4jApi = "org.slf4j:slf4j-api:1.7.30"
val slf4jJdk14 = "org.slf4j:slf4j-jdk14:1.7.30"
val logbackVersion = "1.2.9"
val logbackClassic = "ch.qos.logback:logback-classic:$logbackVersion"

Expand Down
3 changes: 1 addition & 2 deletions sentry-samples/sentry-samples-jul/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ plugins {

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

configure<JavaPluginExtension> {
Expand All @@ -18,5 +17,5 @@ configure<JavaPluginExtension> {

dependencies {
implementation(projects.sentryJul)
implementation(Config.Libs.logbackClassic)
implementation(Config.Libs.slf4jJdk14)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@

import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import org.slf4j.MDC;

public class Main {

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

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

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

// logging arguments are converted to Sentry Event parameters
LOGGER.log(Level.INFO, "User has made a purchase of product: %d", 445);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
io.sentry.jul.SentryHandler.minimumEventLevel=INFO
io.sentry.jul.SentryHandler.minimumEventLevel=DEBUG
io.sentry.jul.SentryHandler.minimumBreadcrumbLevel=CONFIG
io.sentry.jul.SentryHandler.printfStyle=true
io.sentry.jul.SentryHandler.level=CONFIG
io.sentry.samples.jul.Main.handlers=io.sentry.jul.SentryHandler
io.sentry.samples.jul.Main.level=CONFIG
handlers=io.sentry.jul.SentryHandler
level=CONFIG

0 comments on commit 191ca19

Please sign in to comment.