Skip to content

Commit 6464044

Browse files
authored
feat: Update snippet to use logger.X (#13657)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR Based on feedback from slack after merging in #13603 ## 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 --> - [x] 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 a0617e3 commit 6464044

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

includes/logs/javascript-usage.mdx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,34 @@ 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-
Aside from the primary logging methods, we've provided a format text function, `fmt`, that you can use to add insert properties into to your log entries.
5+
Aside from the primary logging methods, we've provided a format text function, `Sentry.logger.fmt`, that you can use to add insert properties into to your log entries.
6+
67
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.
78

89
```js
9-
const { info, warn, fmt } = Sentry.logger;
10+
const { logger } = Sentry;
1011

11-
error(fmt`Uh on, something broke, here's the error: '${error}'`);
12-
info(fmt`User '${user.username}' added item '${product.name}' to cart.`);
12+
logger.error(logger.fmt`Uh on, something broke, here's the error: '${error}'`);
13+
logger.info(logger.fmt`'${user.username}' added '${product.name}' to cart.`);
1314
```
1415

1516
You can also pass additional attributes directly to the logging functions, avoiding the need to use the `fmt` function.
1617

1718
```js
18-
const { trace, debug, info, warn, error, fatal } = Sentry.logger;
19+
const { logger } = Sentry;
1920

20-
trace("Starting database connection", { database: "users" });
21-
debug("Cache miss for user", { userId: 123 });
22-
info("Updated profile", { profileId: 345 });
23-
warn("Rate limit reached for endpoint", {
21+
logger.trace("Starting database connection", { database: "users" });
22+
logger.debug("Cache miss for user", { userId: 123 });
23+
logger.info("Updated profile", { profileId: 345 });
24+
logger.warn("Rate limit reached for endpoint", {
2425
endpoint: "/api/results/",
2526
isEnterprise: false,
2627
});
27-
error("Failed to process payment", { orderId: "order_123", amount: 99.99 });
28-
fatal("Database connection pool exhausted", {
28+
logger.error("Failed to process payment", {
29+
orderId: "order_123",
30+
amount: 99.99,
31+
});
32+
logger.fatal("Database connection pool exhausted", {
2933
database: "users",
3034
activeConnections: 100,
3135
});

0 commit comments

Comments
 (0)