Skip to content

Commit 695aaeb

Browse files
authored
Merge branch 'master' into lcian/ref/logs-feature-flag
2 parents 102b7bd + 8af23ee commit 695aaeb

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
### Behavioral changes
1313

14+
- ref(log): send logs by default when logs feature flag is enabled ([#915](https://github.com/getsentry/sentry-rust/pull/915)) by @lcian
15+
- If the `logs` feature flag is enabled, the default Sentry `log` logger now sends logs for all events at or above INFO.
1416
- ref(logs): enable logs by default if logs feature flag is used ([#910](https://github.com/getsentry/sentry-rust/pull/910)) by @lcian
1517
- This changes the default value of `sentry::ClientOptions::enable_logs` to `true`.
1618
- This simplifies the setup of Sentry structured logs by requiring users to just add the `log` feature flag to the `sentry` dependency to opt-in to sending logs.

sentry-log/src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@
1111
//! - Records can be captured as traditional [logs](https://docs.sentry.io/product/explore/logs/)
1212
//! Logs can be viewed and queried in the Logs explorer.
1313
//!
14-
//! By default anything above `Info` is recorded as a breadcrumb and
15-
//! anything above `Error` is captured as error event.
16-
//!
17-
//! To capture records as Sentry logs:
18-
//! 1. Enable the `logs` feature of the `sentry` crate.
19-
//! 2. Initialize the SDK with `enable_logs: true` in your client options.
20-
//! 3. Set up a custom filter (see below) to map records to logs (`LogFilter::Log`) based on criteria such as severity.
14+
//! By default anything at or above `Info` is recorded as a breadcrumb and
15+
//! anything at or above `Error` is captured as error event.
16+
//! Additionally, if the `sentry` crate is used with the `logs` feature flag, anything at or above `Info`
17+
//! is captured as a [Structured Log](https://docs.sentry.io/product/explore/logs/).
2118
//!
2219
//! # Examples
2320
//!

sentry-log/src/logger.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ impl From<RecordMapping> for Vec<RecordMapping> {
5252
/// `warning` and `info`, and `debug` and `trace` logs are ignored.
5353
pub fn default_filter(metadata: &log::Metadata) -> LogFilter {
5454
match metadata.level() {
55+
#[cfg(feature = "logs")]
56+
log::Level::Error => LogFilter::Exception | LogFilter::Log,
57+
#[cfg(not(feature = "logs"))]
5558
log::Level::Error => LogFilter::Exception,
59+
#[cfg(feature = "logs")]
60+
log::Level::Warn | log::Level::Info => LogFilter::Breadcrumb | LogFilter::Log,
61+
#[cfg(not(feature = "logs"))]
5662
log::Level::Warn | log::Level::Info => LogFilter::Breadcrumb,
5763
log::Level::Debug | log::Level::Trace => LogFilter::Ignore,
5864
}

0 commit comments

Comments
 (0)