You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/platforms/rust/common/logs/index.mdx
+7-27Lines changed: 7 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,22 +19,13 @@ sentry = { version = "{{@inject packages.version('sentry.rust') }}", features =
19
19
20
20
## Setup
21
21
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`.
34
25
35
26
## Usage
36
27
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.
38
29
The `sentry` crate exposes macros that support six different log levels:
39
30
`logger_trace`, `logger_debug`, `logger_info`, `logger_warn`, `logger_error` and `logger_fatal`.
40
31
The macros support logging a simple message, or a message with parameters, with `format` syntax:
@@ -81,7 +72,6 @@ tracing = "0.1.41"
81
72
tracing-subscriber = "0.3.19"
82
73
```
83
74
84
-
Initialize the SDK with `enable_logs` set to `true`.
85
75
Then, use standard `tracing` macros to capture logs.
86
76
87
77
```rust {filename:main.rs}
@@ -119,7 +109,7 @@ fn main() {
119
109
120
110
The fields of `tracing` events are automatically captured as attributes in Sentry logs.
121
111
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.
123
113
124
114
This behavior can be customized by applying a custom `event_filter` when creating the layer.
125
115
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 =
136
126
// Capture everything else as both a breadcrumb and a log
137
127
_=>EventFilter::Breadcrumb|EventFilter::Log,
138
128
});
129
+
```
139
130
140
131
### `log` Integration
141
132
@@ -149,7 +140,6 @@ log = "0.4"
149
140
env_logger = "0.11"
150
141
```
151
142
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.
0 commit comments