Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve jul sample for easier debugging inside IDE #2058

Merged
merged 2 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be a comment that this is made only for the purpose of running it from an IDE.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment for an alternative way of providing the logging.properties file.

.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