10
10
) ]
11
11
12
12
use fern:: { Filter , FormatCallback } ;
13
- use log:: { logger, RecordBuilder } ;
14
13
use log:: { LevelFilter , Record } ;
15
14
use serde:: Serialize ;
16
15
use serde_repr:: { Deserialize_repr , Serialize_repr } ;
17
16
use std:: borrow:: Cow ;
18
- use std:: collections:: HashMap ;
19
17
use std:: {
20
18
fmt:: Arguments ,
21
19
fs:: { self , File } ,
@@ -30,6 +28,9 @@ use tauri::{AppHandle, Emitter};
30
28
use time:: { macros:: format_description, OffsetDateTime } ;
31
29
32
30
pub use fern;
31
+ pub use log;
32
+
33
+ mod commands;
33
34
34
35
pub const WEBVIEW_TARGET : & str = "webview" ;
35
36
@@ -206,70 +207,6 @@ impl Target {
206
207
}
207
208
}
208
209
209
- // Target becomes default and location is added as a parameter
210
- #[ cfg( feature = "tracing" ) ]
211
- fn emit_trace (
212
- level : log:: Level ,
213
- message : & String ,
214
- location : Option < & str > ,
215
- file : Option < & str > ,
216
- line : Option < u32 > ,
217
- kv : & HashMap < & str , & str > ,
218
- ) {
219
- macro_rules! emit_event {
220
- ( $level: expr) => {
221
- tracing:: event!(
222
- target: WEBVIEW_TARGET ,
223
- $level,
224
- message = %message,
225
- location = location,
226
- file,
227
- line,
228
- ?kv
229
- )
230
- } ;
231
- }
232
- match level {
233
- log:: Level :: Error => emit_event ! ( tracing:: Level :: ERROR ) ,
234
- log:: Level :: Warn => emit_event ! ( tracing:: Level :: WARN ) ,
235
- log:: Level :: Info => emit_event ! ( tracing:: Level :: INFO ) ,
236
- log:: Level :: Debug => emit_event ! ( tracing:: Level :: DEBUG ) ,
237
- log:: Level :: Trace => emit_event ! ( tracing:: Level :: TRACE ) ,
238
- }
239
- }
240
-
241
- #[ tauri:: command]
242
- fn log (
243
- level : LogLevel ,
244
- message : String ,
245
- location : Option < & str > ,
246
- file : Option < & str > ,
247
- line : Option < u32 > ,
248
- key_values : Option < HashMap < String , String > > ,
249
- ) {
250
- let level = log:: Level :: from ( level) ;
251
-
252
- let target = if let Some ( location) = location {
253
- format ! ( "{WEBVIEW_TARGET}:{location}" )
254
- } else {
255
- WEBVIEW_TARGET . to_string ( )
256
- } ;
257
-
258
- let mut builder = RecordBuilder :: new ( ) ;
259
- builder. level ( level) . target ( & target) . file ( file) . line ( line) ;
260
-
261
- let key_values = key_values. unwrap_or_default ( ) ;
262
- let mut kv = HashMap :: new ( ) ;
263
- for ( k, v) in key_values. iter ( ) {
264
- kv. insert ( k. as_str ( ) , v. as_str ( ) ) ;
265
- }
266
- builder. key_values ( & kv) ;
267
- #[ cfg( feature = "tracing" ) ]
268
- emit_trace ( level, & message, location, file, line, & kv) ;
269
-
270
- logger ( ) . log ( & builder. args ( format_args ! ( "{message}" ) ) . build ( ) ) ;
271
- }
272
-
273
210
pub struct Builder {
274
211
dispatch : fern:: Dispatch ,
275
212
rotation_strategy : RotationStrategy ,
@@ -528,7 +465,7 @@ impl Builder {
528
465
}
529
466
530
467
fn plugin_builder < R : Runtime > ( ) -> plugin:: Builder < R > {
531
- plugin:: Builder :: new ( "log" ) . invoke_handler ( tauri:: generate_handler![ log] )
468
+ plugin:: Builder :: new ( "log" ) . invoke_handler ( tauri:: generate_handler![ commands :: log] )
532
469
}
533
470
534
471
#[ allow( clippy:: type_complexity) ]
0 commit comments