@@ -3,7 +3,7 @@ use crate::procenv;
3
3
use std:: fmt:: Display ;
4
4
use std:: os:: windows:: ffi:: OsStrExt ;
5
5
use std:: ffi:: OsStr ;
6
- use std:: sync:: RwLock ;
6
+ use std:: sync:: { RwLock , RwLockReadGuard } ;
7
7
use std:: process;
8
8
use std:: env;
9
9
@@ -52,22 +52,33 @@ fn log_dbg(msg: impl Display, level: Level) {
52
52
}
53
53
54
54
pub ( crate ) struct FileLogCfg {
55
-
55
+ level : Level
56
56
}
57
57
58
58
pub ( crate ) struct DbgLogCfg {
59
-
59
+ level : Level
60
60
}
61
61
62
62
pub ( crate ) struct LoggingCfg {
63
- level : Level
63
+ level : Level ,
64
+ dbg : DbgLogCfg ,
65
+ file : FileLogCfg
64
66
}
65
67
66
68
#[ derive( Default ) ]
67
69
struct PirtLogger {
68
70
cfg : RwLock < Option < LoggingCfg > >
69
71
}
70
72
73
+ impl PirtLogger {
74
+ fn cfg ( & self ) -> RwLockReadGuard < Option < LoggingCfg > > {
75
+ self . cfg . read ( ) . unwrap_or_else ( |_| {
76
+ log_dbg ( "logging lock is poisoned, check logs for further errors" , Level :: Error ) ;
77
+ panic ! ( "logging lock is poisoned, check logs for further errors" ) ;
78
+ } )
79
+ }
80
+ }
81
+
71
82
impl Log for PirtLogger {
72
83
fn enabled ( & self , metadata : & log:: Metadata ) -> bool {
73
84
match self . cfg . read ( ) {
@@ -84,7 +95,16 @@ impl Log for PirtLogger {
84
95
}
85
96
86
97
fn log ( & self , record : & log:: Record ) {
87
- todo ! ( )
98
+ if let Some ( lock) = & * self . cfg ( ) {
99
+ if lock. dbg . level >= record. level ( ) {
100
+ log_dbg ( record. args ( ) , record. level ( ) ) ;
101
+ }
102
+
103
+ if lock. file . level >= record. level ( ) {
104
+ todo ! ( ) ;
105
+ }
106
+ }
107
+ else { log_dbg ( record. args ( ) , record. level ( ) ) ; }
88
108
}
89
109
90
110
fn flush ( & self ) {
0 commit comments