Skip to content

Commit ad83515

Browse files
authored
Update index.mdx
1 parent c1347df commit ad83515

File tree

1 file changed

+7
-27
lines changed

1 file changed

+7
-27
lines changed

docs/platforms/rust/common/logs/index.mdx

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,13 @@ sentry = { version = "{{@inject packages.version('sentry.rust') }}", features =
1919

2020
## Setup
2121

22-
To enable logging, you need to initialize the SDK with the `enable_logs` option set to `true`.
23-
24-
```rust
25-
let _guard = sentry::init((
26-
"___PUBLIC_DSN___",
27-
sentry::ClientOptions {
28-
release: sentry::release_name!(),
29-
enable_logs: true,
30-
..Default::default()
31-
}
32-
));
33-
```
22+
To enable logging, just add the `sentry` dependency with the `logs` feature flag.
23+
This will set `enable_logs: true` by default in your `sentry::ClientOptions`.
24+
You can opt-out from sending logs even while using the `logs` feature flag by explicitly initializing the SDK with `enable_logs: false`.
3425

3526
## Usage
3627

37-
Once the feature is enabled on the SDK and the SDK is initialized, you can send logs by using the logging macros.
28+
Once the feature is enabled and the SDK is initialized, you can send logs by using the logging macros.
3829
The `sentry` crate exposes macros that support six different log levels:
3930
`logger_trace`, `logger_debug`, `logger_info`, `logger_warn`, `logger_error` and `logger_fatal`.
4031
The macros support logging a simple message, or a message with parameters, with `format` syntax:
@@ -81,7 +72,6 @@ tracing = "0.1.41"
8172
tracing-subscriber = "0.3.19"
8273
```
8374

84-
Initialize the SDK with `enable_logs` set to `true`.
8575
Then, use standard `tracing` macros to capture logs.
8676

8777
```rust {filename:main.rs}
@@ -119,7 +109,7 @@ fn main() {
119109

120110
The fields of `tracing` events are automatically captured as attributes in Sentry logs.
121111

122-
By default, `tracing` events at info level or above are captured as Sentry logs.
112+
By default, `tracing` events at or above info level are captured as Sentry logs.
123113

124114
This behavior can be customized by applying a custom `event_filter` when creating the layer.
125115
The following snippet shows the default `event_filter` that's applied when using the `sentry` crate with the `logs` feature flag.
@@ -136,6 +126,7 @@ let sentry_layer =
136126
// Capture everything else as both a breadcrumb and a log
137127
_ => EventFilter::Breadcrumb | EventFilter::Log,
138128
});
129+
```
139130

140131
### `log` Integration
141132

@@ -149,7 +140,6 @@ log = "0.4"
149140
env_logger = "0.11"
150141
```
151142

152-
Initialize the SDK with `enable_logs` set to `true`, and configure the `log` integration to map `log` records to logs based on metadata such as severity.
153143
Then, use standard `log` macros to capture logs.
154144

155145
```rust {filename:main.rs}
@@ -168,17 +158,7 @@ fn main() {
168158

169159
let logger = sentry::integrations::log::SentryLogger::with_dest(
170160
env_logger::Builder::from_default_env().build(),
171-
)
172-
.filter(|md| match md.level() {
173-
// Capture error records as Sentry events
174-
// These are grouped into issues, representing high-severity errors to act upon
175-
log::Level::Error => LogFilter::Event,
176-
// Ignore trace level records, as they're too verbose
177-
log::Level::Trace => LogFilter::Ignore,
178-
// Capture everything else as a log
179-
_ => LogFilter::Log,
180-
});
181-
161+
);
182162
log::set_boxed_logger(Box::new(logger)).unwrap();
183163
log::set_max_level(log::LevelFilter::Trace);
184164

0 commit comments

Comments
 (0)