Skip to content

Commit 46bfce1

Browse files
authored
Basic docs for Java Logging (#13701)
1 parent b7eb3e4 commit 46bfce1

File tree

14 files changed

+250
-10
lines changed

14 files changed

+250
-10
lines changed

develop-docs/sdk/telemetry/logs.mdx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,10 @@ logger()->info('Adding item %s for user %s', [$item_id, $user_id], ['extra' => 1
226226
```java
227227
import io.sentry.Sentry;
228228

229-
// example with MessageFormat based string template
230-
Sentry.logger().info("Adding item {0,string} for user {1,string}", item_id, user_id, log -> {
231-
log.setAttribute("extra", 123);
232-
});
229+
Sentry.logger().info("Adding item %s for user %s", itemId, userId);
233230

234231
// Kotlin
235-
Sentry.Logger.info("Adding item for user") { // fun info(block: LogItem.() -> Unit)
236-
setAttribute("item_id", item_id)
237-
setAttribute("user_id", user_id)
238-
setAttribute("extra", 123)
239-
}
232+
Sentry.logger().info("Adding item %s for user %s", itemId, userId)
240233
```
241234

242235
#### Apple
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: Set Up Logs
3+
sidebar_title: Logs
4+
description: "Structured logs allow you to send, view and query logs sent from your applications within Sentry."
5+
sidebar_order: 5755
6+
---
7+
8+
<Include name="feature-stage-beta-logs.mdx" />
9+
10+
With Sentry Structured Logs, you can send text based log information from your applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes.
11+
12+
## Requirements
13+
14+
<PlatformContent includePath="logs/requirements" />
15+
16+
## Setup
17+
18+
<PlatformContent includePath="logs/setup" />
19+
20+
## Usage
21+
22+
<PlatformContent includePath="logs/usage" />
23+
24+
## Integrations
25+
26+
<PlatformContent includePath="logs/integrations" />
27+
28+
## Options
29+
30+
<PlatformContent includePath="logs/options" />
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: Set Up Logs
3+
sidebar_title: Logs
4+
description: "Structured logs allow you to send, view and query logs sent from your applications within Sentry."
5+
sidebar_order: 5755
6+
---
7+
8+
<Include name="feature-stage-beta-logs.mdx" />
9+
10+
With Sentry Structured Logs, you can send text based log information from your applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes.
11+
12+
## Requirements
13+
14+
<PlatformContent includePath="logs/requirements" />
15+
16+
## Setup
17+
18+
<PlatformContent includePath="logs/setup" />
19+
20+
## Usage
21+
22+
<PlatformContent includePath="logs/usage" />
23+
24+
## Integrations
25+
26+
<PlatformContent includePath="logs/integrations" />
27+
28+
## Options
29+
30+
<PlatformContent includePath="logs/options" />

docs/product/explore/logs/getting-started/index.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@ To set up Sentry Logs, use the links below for supported SDKs. After it's been s
4747

4848
- [Python](/platforms/python/logs/)
4949

50+
### Android / Java
51+
52+
- [Android](/platforms/android/logs/)
53+
- [Java](/platforms/java/logs/)
54+
5055
## Upcoming SDKs
5156

5257
We're actively working on adding Log functionality to additional SDKs. Check out these GitHub issues for the latest updates:
5358

5459
- [PHP](https://github.com/getsentry/sentry-php/issues/1824)
55-
- [Java](https://github.com/getsentry/sentry-java/issues/4350)
5660
- [Go](https://github.com/getsentry/sentry-go/issues/1000)
5761
- [Ruby](https://github.com/getsentry/sentry-ruby/issues/2600)
5862
- [.NET](https://github.com/getsentry/sentry-dotnet/issues/4132)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
We are still working on Logs. Please open [a new GitHub issue](https://github.com/getsentry/sentry-java/issues/new/choose) for any integration you would like to see.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
We are still working on Logs. You can follow progress on the following GitHub issues or open a new one for any integration you would like to see.
2+
3+
- [Logback](https://github.com/getsentry/sentry-java/issues/4404)
4+
- [Log4j2](https://github.com/getsentry/sentry-java/issues/4403)
5+
- [JUL](https://github.com/getsentry/sentry-java/issues/4405)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#### beforeSendLog
2+
3+
To filter logs, or update them before they are sent to Sentry, you can use the `getLogs().beforeSend` option.
4+
5+
```java {tabTitle: Java} {10-14}
6+
import io.sentry.SentryLevel;
7+
import io.sentry.android.core.SentryAndroid;
8+
import android.app.Application;
9+
10+
public class MyApplication extends Application {
11+
public void onCreate() {
12+
super.onCreate();
13+
SentryAndroid.init(this, options -> {
14+
options.setDsn("___PUBLIC_DSN___");
15+
options.getLogs().setBeforeSend((logEvent) -> {
16+
// Modify the event here:
17+
logEvent.setBody("new message body");
18+
return logEvent;
19+
});
20+
});
21+
}
22+
}
23+
```
24+
25+
```kotlin {tabTitle: Kotlin} {11-15}
26+
import io.sentry.android.core.SentryAndroid
27+
import io.sentry.SentryOptions.BeforeSendCallback
28+
import io.sentry.Hint
29+
import android.app.Application
30+
31+
class MyApplication : Application() {
32+
override fun onCreate() {
33+
super.onCreate()
34+
SentryAndroid.init(this) { options ->
35+
options.dsn = "___PUBLIC_DSN___"
36+
options.logs.beforeSend = BeforeSendLogCallback { logEvent ->
37+
// Modify the event here:
38+
logEvent.body = "new message body"
39+
return logEvent;
40+
}
41+
}
42+
}
43+
}
44+
```
45+
46+
47+
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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#### beforeSendLog
2+
3+
To filter logs, or update them before they are sent to Sentry, you can use the `getLogs().beforeSend` option.
4+
5+
```java {tabTitle: Java} {5-9}
6+
import io.sentry.Sentry;
7+
8+
Sentry.init(options -> {
9+
options.setDsn("___PUBLIC_DSN___");
10+
options.getLogs().setBeforeSend((logEvent) -> {
11+
// Modify the event here:
12+
logEvent.setBody("new message body");
13+
return logEvent;
14+
});
15+
});
16+
```
17+
18+
```kotlin {tabTitle: Kotlin} {6-10}
19+
import io.sentry.Sentry
20+
import io.sentry.SentryOptions.Logs.BeforeSendLogCallback
21+
22+
Sentry.init { options ->
23+
options.dsn = "___PUBLIC_DSN___"
24+
options.logs.beforeSend = BeforeSendLogCallback { logEvent ->
25+
// Modify the event here:
26+
logEvent.body = "new message body"
27+
return logEvent;
28+
}
29+
}
30+
```
31+
32+
33+
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 Android are supported in Sentry Java SDK version `8.12.0` and above.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Logs for Java are supported in Sentry Java SDK version `8.12.0` and above.

0 commit comments

Comments
 (0)