@@ -38,10 +38,12 @@ pub enum RecordMapping {
3838 /// Captures the [`sentry_core::protocol::Log`] to Sentry.
3939 #[ cfg( feature = "logs" ) ]
4040 Log ( sentry_core:: protocol:: Log ) ,
41- /// Captures multiple items to Sentry.
42- /// Nesting multiple `RecordMapping::Combined` is not supported and will cause the mappings to
43- /// be ignored.
44- Combined ( Vec < RecordMapping > ) ,
41+ }
42+
43+ impl From < RecordMapping > for Vec < RecordMapping > {
44+ fn from ( mapping : RecordMapping ) -> Self {
45+ vec ! [ mapping]
46+ }
4547}
4648
4749/// The default log filter.
@@ -81,7 +83,7 @@ pub struct SentryLogger<L: log::Log> {
8183 dest : L ,
8284 filter : Box < dyn Fn ( & log:: Metadata < ' _ > ) -> LogFilter + Send + Sync > ,
8385 #[ allow( clippy:: type_complexity) ]
84- mapper : Option < Box < dyn Fn ( & Record < ' _ > ) -> RecordMapping + Send + Sync > > ,
86+ mapper : Option < Box < dyn Fn ( & Record < ' _ > ) -> Vec < RecordMapping > + Send + Sync > > ,
8587}
8688
8789impl Default for SentryLogger < NoopLogger > {
@@ -127,13 +129,15 @@ impl<L: log::Log> SentryLogger<L> {
127129 /// Sets a custom mapper function.
128130 ///
129131 /// The mapper is responsible for creating either breadcrumbs or events
130- /// from [`Record`]s.
132+ /// from [`Record`]s. It can return either a single [`RecordMapping`] or
133+ /// a `Vec<RecordMapping>` to send multiple items to Sentry from one log record.
131134 #[ must_use]
132- pub fn mapper < M > ( mut self , mapper : M ) -> Self
135+ pub fn mapper < M , T > ( mut self , mapper : M ) -> Self
133136 where
134- M : Fn ( & Record < ' _ > ) -> RecordMapping + Send + Sync + ' static ,
137+ M : Fn ( & Record < ' _ > ) -> T + Send + Sync + ' static ,
138+ T : Into < Vec < RecordMapping > > ,
135139 {
136- self . mapper = Some ( Box :: new ( mapper) ) ;
140+ self . mapper = Some ( Box :: new ( move |record| mapper ( record ) . into ( ) ) ) ;
137141 self
138142 }
139143}
@@ -162,11 +166,11 @@ impl<L: log::Log> log::Log for SentryLogger<L> {
162166 if filter. contains ( LogFilter :: Log ) {
163167 items. push ( RecordMapping :: Log ( log_from_record ( record) ) ) ;
164168 }
165- RecordMapping :: Combined ( items)
169+ items
166170 }
167171 } ;
168172
169- fn handle_single_mapping ( mapping : RecordMapping ) {
173+ for mapping in items {
170174 match mapping {
171175 RecordMapping :: Ignore => { }
172176 RecordMapping :: Breadcrumb ( breadcrumb) => sentry_core:: add_breadcrumb ( breadcrumb) ,
@@ -177,20 +181,7 @@ impl<L: log::Log> log::Log for SentryLogger<L> {
177181 RecordMapping :: Log ( log) => {
178182 sentry_core:: Hub :: with_active ( |hub| hub. capture_log ( log) )
179183 }
180- RecordMapping :: Combined ( _) => {
181- sentry_core:: sentry_debug!(
182- "[SentryLogger] found nested RecordMapping::Combined, ignoring"
183- )
184- }
185- }
186- }
187-
188- if let RecordMapping :: Combined ( items) = items {
189- for item in items {
190- handle_single_mapping ( item) ;
191184 }
192- } else {
193- handle_single_mapping ( items) ;
194185 }
195186
196187 self . dest . log ( record)
0 commit comments