File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ import logging
2
+
3
+ logging .basicConfig (
4
+ filename = 'HISTORYlistener.log' ,
5
+ level = logging .DEBUG ,
6
+ format = '%(asctime)s.%(msecs)03d %(levelname)s %(module)s - %(funcName)s: %(message)s' ,
7
+ datefmt = '%Y-%m-%d %H:%M:%S' ,
8
+ )
9
+
10
+ ####################################################################################################
11
+
12
+ import logging
13
+
14
+ class MyFormatter (logging .Formatter ):
15
+ def format (self , record ):
16
+ record .message2 = ""
17
+ if (record .args ):
18
+ record .func_name = record .args .get ("func_name" , "Fallback Value" )
19
+ return super ().format (record )
20
+
21
+ logger = logging .getLogger ()
22
+ fh = logging .FileHandler (filename = 'log.txt' , mode = 'a' )
23
+ fh .setFormatter (MyFormatter ('%(asctime)s --- %(func_name)s --- %(message)s' , datefmt = '%Y-%m-%d %H:%M:%S' ))
24
+ logging .basicConfig (level = logging .INFO , handlers = [fh ])
25
+
26
+ def write_log (func_name , message ):
27
+ logger .info (message , {"func_name" : func_name })
28
+
Original file line number Diff line number Diff line change
1
+ import logging
2
+ logging .basicConfig (filename = 'example.log' ,level = logging .DEBUG )
3
+ logging .debug ('This message should go to the log file' )
4
+ logging .info ('So should this' )
5
+ logging .warning ('And this, too' )
You can’t perform that action at this time.
0 commit comments