File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ import logging
2
+
3
+ ##################################### LOGS #####################################
4
+ # Initialize the logger and specify the level of logging. This will log "DEBUG"
5
+ # and higher messages to file and log "WARNING" and higher messages to the console.
6
+
7
+ def create_logger ():
8
+ logging .basicConfig (level = logging .DEBUG ,
9
+ format = '[%(levelname)s][%(name)s][%(asctime)s]: %(message)s' ,
10
+ datefmt = '%d-%m-%y-%H:%M:%S' ,
11
+ filename = 'debug.log' ,
12
+ filemode = 'a' )
13
+
14
+ # Define a "handler" which writes "WARNING" messages or higher to the "sys.stderr".
15
+ console = logging .StreamHandler ()
16
+ console .setLevel (logging .WARNING )
17
+
18
+ # Set a format which is simpler for console messages.
19
+ formatter = logging .Formatter ('[%(levelname)s][%(asctime)s]: %(message)s' , datefmt = '%H:%M:%S' )
20
+
21
+ # Tell the console "handler" to use this format.
22
+ console .setFormatter (formatter )
23
+
24
+ # Add the "handler" to the "root logger".
25
+ log = logging .getLogger (__name__ )
26
+ log .addHandler (console )
27
+
28
+ return log
29
+
30
+ # Example Usage
31
+ #
32
+ # import tkintermd.log as logg
33
+ #
34
+ # logger = log.create_logger()
35
+ # logger.debug("DEBUG")
36
+ # logger.info("INFO")
37
+ # logger.exception("EXCEPTION")
38
+ # logger.warning("WARNING")
39
+ # logger.error("ERROR")
40
+ # logger.critical("CRITICAL")
41
+
42
+ ################################################################################
You can’t perform that action at this time.
0 commit comments