Skip to content

Commit 0f850ed

Browse files
authored
Document Logs for Logback and Spring Boot with Logback (#14145)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR *Tell us what you're changing and why. If your PR **resolves an issue**, please link it so it closes automatically.* ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [ ] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent d7a4c55 commit 0f850ed

File tree

9 files changed

+95
-3
lines changed

9 files changed

+95
-3
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,20 @@ Minimum logging levels for `SentryAppender` can be configured in `application.pr
2727
```properties
2828
sentry.logging.minimum-event-level=info
2929
sentry.logging.minimum-breadcrumb-level=debug
30+
sentry.logging.minimum-level=debug
3031
```
3132

3233
The default values are:
3334

3435
- `info` or higher to include a log message as breadcrumb.
35-
- `error` or higher will send an event to Sentry.
36+
- `info` or higher will send a log message to Sentry and will show up in the Logs section.
37+
- `error` or higher will send an event to Sentry and will show up in the Issues section.
38+
39+
To send logs to Sentry and have them show up in the Logs section, you need to enable the feature:
40+
41+
```properties
42+
sentry.logs.enabled=true
43+
```
3644

3745
When `SentryAppender` auto-configuration does not suit your needs, it can be turned off by setting:
3846

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
Available integrations:
2+
- [Logback](/platforms/java/guides/logback/logs/)
3+
- [Spring Boot using Logback](/platforms/java/guides/spring-boot/logging-frameworks/)
4+
15
We're actively working on adding more integration support for Logs. You can follow progress on the following GitHub issues or open a [new one](https://github.com/getsentry/sentry-java/issues/new/choose) for any integration you would like to see.
26

3-
- [Logback](https://github.com/getsentry/sentry-java/issues/4404)
47
- [Log4j2](https://github.com/getsentry/sentry-java/issues/4403)
58
- [JUL](https://github.com/getsentry/sentry-java/issues/4405)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#### beforeSendLog
2+
3+
To filter logs, or update them before they are sent to Sentry, you can expose a bean implementing the `BeforeSendLogCallback`:
4+
5+
```java {tabTitle: Java}
6+
import org.springframework.stereotype.Component;
7+
8+
import io.sentry.SentryLogEvent;
9+
import io.sentry.SentryOptions;
10+
11+
@Component
12+
public class CustomBeforeSendLogCallback implements SentryOptions.Logs.BeforeSendLogCallback {
13+
@Override
14+
public SentryLogEvent execute(SentryLogEvent event) {
15+
// Modify or drop the log event here
16+
if (event.getBody().contains("some PII")) {
17+
// Don't send the log event to Sentry
18+
return null;
19+
}
20+
return event;
21+
}
22+
}
23+
```
24+
25+
```kotlin {tabTitle: Kotlin}
26+
import io.sentry.SentryLogEvent
27+
import io.sentry.SentryOptions.Logs.BeforeSendLogCallback
28+
import org.springframework.stereotype.Component
29+
30+
@Component
31+
class CustomBeforeSendLogCallback : BeforeSendLogCallback {
32+
override fun execute(event: SentryLogEvent): SentryLogEvent? {
33+
// Modify or drop the log event here
34+
if (event.body.contains("some PII")) {
35+
// Don't send the log event to Sentry
36+
return null
37+
}
38+
return event
39+
}
40+
}
41+
```
42+
43+
44+
The `beforeSend` function receives a log object, and should return the log object if you want it to be sent to Sentry, or `null` if you want to discard it.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Logs for Logback are supported in Sentry Java SDK version `8.15.0` and above.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Logs for Spring Boot are supported in Sentry Java SDK version `8.15.0` and above.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
To enable logging, you need to configure the option in the appender configuration. You may also set `minimumLevel` to configure which log messages are sent to Sentry.
2+
3+
```xml {tabTitle: logback.xml} {5-7,15}
4+
<appender name="sentry" class="io.sentry.logback.SentryAppender">
5+
<options>
6+
<!-- NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard -->
7+
<dsn>___PUBLIC_DSN___</dsn>
8+
<logs>
9+
<enabled>true</enabled>
10+
</logs>
11+
</options>
12+
<!-- Demonstrates how to modify the minimum values -->
13+
<!-- Default for Events is ERROR -->
14+
<minimumEventLevel>WARN</minimumEventLevel>
15+
<!-- Default for Breadcrumbs is INFO -->
16+
<minimumBreadcrumbLevel>DEBUG</minimumBreadcrumbLevel>
17+
<!-- Default for Log Events is INFO -->
18+
<minimumLevel>DEBUG</minimumLevel>
19+
</appender>
20+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
To enable logging, you have to enable the feature in your Spring configuration file:
2+
3+
```properties {tabTitle:application.properties}
4+
sentry.logs.enabled=true
5+
```
6+
7+
```yaml {tabTitle:application.yml}
8+
sentry:
9+
logs.enabled: true
10+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Once the appender has been configured with logs enabled any logs equal to or higher than `minimumLevel` will be sent to Sentry as logs.

platform-includes/logs/usage/java.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,8 @@ Sentry.logger().log(
6464
"log message %s",
6565
"param1"
6666
)
67-
```
67+
```
68+
69+
<PlatformSection supported={["java.spring-boot"]}>
70+
It is also possible to use Logback and Spring Boot together to have logs going through Logback sent to Sentry. Take a look at the <PlatformLink to="/logging-frameworks/">Logging Framework Integrations</PlatformLink> page.
71+
</PlatformSection>

0 commit comments

Comments
 (0)