Skip to content

Commit 74099cc

Browse files
vyppkarwaszadinauer
authored
fix: Log4j configurations and wording (#11395)
* Fix Log4j configurations and improve wording * Remove Log4j schema Co-authored-by: Piotr P. Karwasz <[email protected]> * Remove Log4j schema Co-authored-by: Piotr P. Karwasz <[email protected]> * Remove Log4j schema Co-authored-by: Piotr P. Karwasz <[email protected]> * Apply suggestions from code review --------- Co-authored-by: Piotr P. Karwasz <[email protected]> Co-authored-by: Alexander Dinauer <[email protected]> Co-authored-by: Alexander Dinauer <[email protected]>
1 parent a3f8187 commit 74099cc

File tree

6 files changed

+64
-62
lines changed

6 files changed

+64
-62
lines changed

docs/platforms/java/common/legacy/log4j2/index.mdx

+19-18
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ An [updated Java SDK](/platforms/java/) SDK supersedes this deprecated version.
99

1010
</Alert>
1111

12-
The `sentry-log4j2` library provides [Log4j 2.x](https://logging.apache.org/log4j/2.x/) support for Sentry via an [Appender](https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/Appender.html) that sends logged exceptions to Sentry. Once this integration is configured you can _also_ use Sentry’s static API, [as shown on the usage page](/platforms/java/legacy/usage), in order to do things like record breadcrumbs, set the current user, or manually send events.
12+
The `sentry-log4j2` library provides [Log4j 2](https://logging.apache.org/log4j/2.x/) support for Sentry via an [Appender](https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/Appender.html) that sends logged exceptions to Sentry. Once this integration is configured you can _also_ use Sentry’s static API, [as shown on the usage page](/platforms/java/legacy/usage), in order to do things like record breadcrumbs, set the current user, or manually send events.
1313

1414
The source can be found [on GitHub](https://github.com/getsentry/sentry-java/tree/master/sentry-log4j2).
1515

@@ -41,23 +41,24 @@ Example configuration using the `log4j2.xml` format:
4141

4242
```xml
4343
<?xml version="1.0" encoding="UTF-8"?>
44-
<configuration status="warn" packages="org.apache.logging.log4j.core,io.sentry.log4j2">
45-
<appenders>
46-
<Console name="Console" target="SYSTEM_OUT">
47-
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
48-
</Console>
49-
50-
<Sentry name="Sentry" />
51-
</appenders>
52-
53-
<loggers>
54-
<root level="INFO">
55-
<appender-ref ref="Console" />
56-
<!-- Note that the Sentry logging threshold is overridden to the WARN level -->
57-
<appender-ref ref="Sentry" level="WARN" />
58-
</root>
59-
</loggers>
60-
</configuration>
44+
<Configuration>
45+
46+
<Appenders>
47+
<Console name="CONSOLE" target="SYSTEM_OUT">
48+
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
49+
</Console>
50+
<Sentry name="SENTRY"/>
51+
</Appenders>
52+
53+
<Loggers>
54+
<Root level="INFO">
55+
<AppenderRef ref="CONSOLE"/>
56+
<!-- Note that the Sentry logging threshold is overridden to the WARN level -->
57+
<AppenderRef ref="SENTRY" level="WARN"/>
58+
</Root>
59+
</Loggers>
60+
61+
</Configuration>
6162
```
6263

6364
Next, **you’ll need to configure your DSN** (client key) and optionally other values such as `environment` and `release`. [See the configuration page](/platforms/java/legacy/configuration/#setting-the-dsn) for ways you can do this.

docs/platforms/java/guides/spring-boot/logging-frameworks.mdx

+21-18
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ However, if errors that may appear during startup should to be sent to Sentry, t
6565

6666
</Note>
6767

68-
### Log4j2
68+
### Log4j 2
6969

70-
To use Sentry's Log4j2 integration in Spring Boot application, you must include a dependency to the `sentry-log4j2` module:
70+
To use Sentry's Log4j 2 integration in Spring Boot application, you must include a dependency to the `sentry-log4j2` module:
7171

7272
```xml {tabTitle:Maven}
7373
<dependency>
@@ -87,30 +87,33 @@ libraryDependencies += "io.sentry" % "sentry-log4j2" % "{{@inject packages.versi
8787

8888
For other dependency managers see the [central Maven repository](https://search.maven.org/artifact/io.sentry/sentry-log4j2).
8989

90-
Then [follow the guide on configuring Log4j2 with Spring Boot](https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-configure-log4j-for-logging) and configure `SentryAppender` in the `log4j2.xml` file:
90+
Then [follow the guide on configuring Log4j 2 with Spring Boot](https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-configure-log4j-for-logging) and configure `SentryAppender` in the `log4j2.xml` file:
9191

9292
```xml
9393
<?xml version="1.0" encoding="UTF-8"?>
94-
<Configuration status="warn" packages="org.apache.logging.log4j.core,io.sentry.log4j2">
95-
<Appenders>
96-
<Console name="Console" target="SYSTEM_OUT">
97-
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
98-
</Console>
99-
<Sentry name="Sentry" />
100-
</Appenders>
101-
<Loggers>
102-
<Root level="info">
103-
<AppenderRef ref="Sentry"/>
104-
<AppenderRef ref="Console"/>
105-
</Root>
106-
</Loggers>
94+
<Configuration>
95+
96+
<Appenders>
97+
<Console name="CONSOLE" target="SYSTEM_OUT">
98+
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
99+
</Console>
100+
<Sentry name="SENTRY"/>
101+
</Appenders>
102+
103+
<Loggers>
104+
<Root level="INFO">
105+
<AppenderRef ref="CONSOLE"/>
106+
<AppenderRef ref="SENTRY"/>
107+
</Root>
108+
</Loggers>
109+
107110
</Configuration>
108111
```
109112

110113
<Note>
111114

112-
You do not need to configure your DSN in the Log4j2 configuration file since Sentry is configured from the Spring Boot integration.
115+
You do not need to configure your DSN in the Log4j 2 configuration file since Sentry is configured from the Spring Boot integration.
113116

114-
However, if errors that may appear during startup should to be sent to Sentry, the DSN must be provided to <i>both</i> the Log4j2 and Spring Boot configurations.
117+
However, if errors that may appear during startup should to be sent to Sentry, the DSN must be provided to <i>both</i> the Log4j 2 and Spring Boot configurations.
115118

116119
</Note>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
When used together with one of the logging framework integrations, the Java SDK captures all error logs as events. If you see a particular kind of error very often that has a `logger` tag, you can ignore that particular logger entirely. For more information see our <Link to="/platforms/java/guides/logback/">Logback</Link> or <Link to="/platforms/java/guides/log4j2/">Log4j 2.x</Link> integration.
1+
When used together with one of the logging framework integrations, the Java SDK captures all error logs as events. If you see a particular kind of error very often that has a `logger` tag, you can ignore that particular logger entirely. For more information see our <Link to="/platforms/java/guides/logback/">Logback</Link> or <Link to="/platforms/java/guides/log4j2/">Log4j 2</Link> integration.

platform-includes/getting-started-config/java.log4j2.mdx

+21-23
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,35 @@ The `ConsoleAppender` is provided only as an example of a non-Sentry appender se
66

77
</Note>
88

9-
109
```xml
1110
<?xml version="1.0" encoding="UTF-8"?>
12-
<Configuration status="warn" packages="org.apache.logging.log4j.core,io.sentry.log4j2">
13-
<Appenders>
14-
<Console name="Console" target="SYSTEM_OUT">
15-
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
16-
</Console>
17-
<Sentry name="Sentry"
18-
dsn="___PUBLIC_DSN___" />
19-
</Appenders>
20-
<Loggers>
21-
<Root level="info">
22-
<AppenderRef ref="Sentry"/>
23-
<AppenderRef ref="Console"/>
24-
</Root>
25-
</Loggers>
11+
<Configuration>
12+
13+
<Appenders>
14+
<Console name="CONSOLE" target="SYSTEM_OUT">
15+
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
16+
</Console>
17+
<Sentry name="SENTRY" dsn="___PUBLIC_DSN___"/>
18+
</Appenders>
19+
20+
<Loggers>
21+
<Root level="INFO">
22+
<AppenderRef ref="CONSOLE"/>
23+
<AppenderRef ref="SENTRY" level="ERROR"/>
24+
</Root>
25+
</Loggers>
26+
2627
</Configuration>
2728
```
2829

29-
`SentryAppender` does not support Log4j2's [async mode](https://logging.apache.org/log4j/2.x/manual/async.html). The Sentry Java SDK itself is already asynchronous and does not perform any blocking operation on the calling thread.
30+
`SentryAppender` does not support [Log4j's asynchronous loggers](https://logging.apache.org/log4j/2.x/manual/async.html). The Sentry Java SDK itself is already asynchronous and does not perform any blocking operation on the calling thread.
3031

3132
### DSN Configuration
3233

33-
Note that **you need to configure your DSN** (client key) only if you wish to initialize the SDK through the log4j2 integration. If you're planning to use `Sentry.init` to provide configuration, such as by using the `beforeSend` callback, you **should not** provide the DSN in both `Sentry.init` and the appender configuration; just leave it out of the appender configuration in this case.
34-
34+
Note that **you need to configure your DSN** (client key) only if you wish to initialize the SDK through the Log4j 2 integration. If you're planning to use `Sentry.init` to provide configuration, such as by using the `beforeSend` callback, you **should not** provide the DSN in both `Sentry.init` and the appender configuration; just leave it out of the appender configuration in this case.
3535

3636
```xml
37-
<Sentry name="Sentry"
38-
dsn="___PUBLIC_DSN___" />
37+
<Sentry name="SENTRY" dsn="___PUBLIC_DSN___" />
3938
```
4039

4140
If the DSN is not present in the `log4j2.xml` configuration, Sentry will attempt to read it from the system property `sentry.dsn`, environment variable `SENTRY_DSN` or the `dsn` property in `sentry.properties` file. [See the configuration page](/platforms/java/configuration/) for more details on external configuration.
@@ -59,9 +58,8 @@ Breadcrumbs are kept in memory (by default the last 100 records) and are sent wi
5958
```xml
6059
<!-- Setting minimumBreadcrumbLevel modifies the default minimum level to add breadcrumbs from INFO to DEBUG -->
6160
<!-- Setting minimumEventLevel the default minimum level to capture an event from ERROR to WARN -->
62-
<Sentry name="Sentry"
61+
<Sentry name="SENTRY"
6362
dsn="___PUBLIC_DSN___"
6463
minimumBreadcrumbLevel="DEBUG"
65-
minimumEventLevel="WARN"
66-
/>
64+
minimumEventLevel="WARN"/>
6765
```

public/_platforms/java.json

+1-1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)