1010) ]
1111
1212use fern:: { Filter , FormatCallback } ;
13- use log:: { logger, RecordBuilder } ;
1413use log:: { LevelFilter , Record } ;
1514use serde:: Serialize ;
1615use serde_repr:: { Deserialize_repr , Serialize_repr } ;
1716use std:: borrow:: Cow ;
18- use std:: collections:: HashMap ;
1917use std:: {
2018 fmt:: Arguments ,
2119 fs:: { self , File } ,
@@ -30,6 +28,9 @@ use tauri::{AppHandle, Emitter};
3028use time:: { macros:: format_description, OffsetDateTime } ;
3129
3230pub use fern;
31+ pub use log;
32+
33+ mod commands;
3334
3435pub const WEBVIEW_TARGET : & str = "webview" ;
3536
@@ -206,70 +207,6 @@ impl Target {
206207 }
207208}
208209
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-
273210pub struct Builder {
274211 dispatch : fern:: Dispatch ,
275212 rotation_strategy : RotationStrategy ,
@@ -528,7 +465,7 @@ impl Builder {
528465 }
529466
530467 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] )
532469 }
533470
534471 #[ allow( clippy:: type_complexity) ]
0 commit comments