Skip to content

Commit 8582858

Browse files
adinauerlcian
andauthored
Document Java Log custom attributes (#14128)
<!-- 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/) --------- Co-authored-by: Lorenzo Cian <lorenzo.cian@sentry.io>
1 parent 876dd53 commit 8582858

File tree

2 files changed

+96
-4
lines changed

2 files changed

+96
-4
lines changed

platform-includes/logs/usage/android.mdx

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ Once the feature is enabled on the SDK and the SDK is initialized, you can send
22

33
The `Sentry.logger()` namespace exposes six methods that you can use to log messages at different log levels: `trace`, `debug`, `info`, `warn`, `error`, and `fatal`.
44

5-
For more advanced use cases, use the `Sentry.logger().log()` methods.
6-
75
These properties will be sent to Sentry, and can be searched from within the Logs UI, and even added to the Logs views as a dedicated column.
86

97
```java {tabTitle: Java}
@@ -19,3 +17,51 @@ import io.sentry.Sentry
1917
Sentry.logger().info("A simple log message")
2018
Sentry.logger().error("A %s log message", "formatted")
2119
```
20+
21+
For more advanced use cases, like attaching custom attributes, use the `Sentry.logger().log()` methods:
22+
23+
```java {tabTitle: Java}
24+
import io.sentry.Sentry;
25+
import io.sentry.SentryAttribute;
26+
import io.sentry.SentryAttributes;
27+
import io.sentry.SentryLogLevel;
28+
import io.sentry.logger.SentryLogParameters;
29+
30+
Sentry.logger().log(
31+
SentryLogLevel.FATAL,
32+
SentryLogParameters.create(
33+
SentryAttributes.of(
34+
SentryAttribute.stringAttribute("my.string-attribute", "some-value"),
35+
SentryAttribute.booleanAttribute("my.bool-attribute", true),
36+
SentryAttribute.integerAttribute("my.int-attribute", 42),
37+
SentryAttribute.doubleAttribute("my.double-attribute", 3.12),
38+
SentryAttribute.named("my.attribute", new Point(1, 2))
39+
)
40+
),
41+
"log message %s",
42+
"param1"
43+
);
44+
```
45+
46+
```kotlin {tabTitle: Kotlin}
47+
import io.sentry.Sentry
48+
import io.sentry.SentryAttribute
49+
import io.sentry.SentryAttributes
50+
import io.sentry.SentryLogLevel
51+
import io.sentry.logger.SentryLogParameters
52+
53+
Sentry.logger().log(
54+
SentryLogLevel.FATAL,
55+
SentryLogParameters.create(
56+
SentryAttributes.of(
57+
SentryAttribute.stringAttribute("my.string-attribute", "some-value"),
58+
SentryAttribute.booleanAttribute("my.bool-attribute", true),
59+
SentryAttribute.integerAttribute("my.int-attribute", 42),
60+
SentryAttribute.doubleAttribute("my.double-attribute", 3.12),
61+
SentryAttribute.named("my.attribute", Point(1, 2))
62+
)
63+
),
64+
"log message %s",
65+
"param1"
66+
)
67+
```

platform-includes/logs/usage/java.mdx

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ Once the feature is enabled on the SDK and the SDK is initialized, you can send
22

33
The `Sentry.logger()` namespace exposes six methods that you can use to log messages at different log levels: `trace`, `debug`, `info`, `warn`, `error`, and `fatal`.
44

5-
For more advanced use cases, use the `Sentry.logger().log()` methods.
6-
75
These properties will be sent to Sentry, and can be searched from within the Logs UI, and even added to the Logs views as a dedicated column.
86

97
```java {tabTitle: Java}
@@ -19,3 +17,51 @@ import io.sentry.Sentry
1917
Sentry.logger().info("A simple log message")
2018
Sentry.logger().error("A %s log message", "formatted")
2119
```
20+
21+
For more advanced use cases, like attaching custom attributes, use the `Sentry.logger().log()` methods:
22+
23+
```java {tabTitle: Java}
24+
import io.sentry.Sentry;
25+
import io.sentry.SentryAttribute;
26+
import io.sentry.SentryAttributes;
27+
import io.sentry.SentryLogLevel;
28+
import io.sentry.logger.SentryLogParameters;
29+
30+
Sentry.logger().log(
31+
SentryLogLevel.FATAL,
32+
SentryLogParameters.create(
33+
SentryAttributes.of(
34+
SentryAttribute.stringAttribute("my.string-attribute", "some-value"),
35+
SentryAttribute.booleanAttribute("my.bool-attribute", true),
36+
SentryAttribute.integerAttribute("my.int-attribute", 42),
37+
SentryAttribute.doubleAttribute("my.double-attribute", 3.12),
38+
SentryAttribute.named("my.attribute", new Point(1, 2))
39+
)
40+
),
41+
"log message %s",
42+
"param1"
43+
);
44+
```
45+
46+
```kotlin {tabTitle: Kotlin}
47+
import io.sentry.Sentry
48+
import io.sentry.SentryAttribute
49+
import io.sentry.SentryAttributes
50+
import io.sentry.SentryLogLevel
51+
import io.sentry.logger.SentryLogParameters
52+
53+
Sentry.logger().log(
54+
SentryLogLevel.FATAL,
55+
SentryLogParameters.create(
56+
SentryAttributes.of(
57+
SentryAttribute.stringAttribute("my.string-attribute", "some-value"),
58+
SentryAttribute.booleanAttribute("my.bool-attribute", true),
59+
SentryAttribute.integerAttribute("my.int-attribute", 42),
60+
SentryAttribute.doubleAttribute("my.double-attribute", 3.12),
61+
SentryAttribute.named("my.attribute", Point(1, 2))
62+
)
63+
),
64+
"log message %s",
65+
"param1"
66+
)
67+
```

0 commit comments

Comments
 (0)