rahgadda commited on
Commit
a1ccc46
·
verified ·
1 Parent(s): 50aee6d

Initial Draft

Browse files
Files changed (1) hide show
  1. lib/api/util/LogWrapper.py +36 -0
lib/api/util/LogWrapper.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import traceback
3
+ from pathlib import Path
4
+ import logging
5
+ from logging.handlers import RotatingFileHandler
6
+ import lib.api.util.CONFIG as CONFIG
7
+
8
+ lv_logger = logging.getLogger()
9
+
10
+ def fn_start_logging():
11
+ try:
12
+ # Logger File Path Configuration
13
+ lv_filepath = Path(CONFIG.LOG_FILE)
14
+ lv_filepath.parent.mkdir(exist_ok=True, parents=True)
15
+
16
+ # Logging Level Configuration
17
+ lv_logger.setLevel(CONFIG.DEFAULT_LEVELS[CONFIG.FILE_LOG_LEVEL])
18
+
19
+ # File Handler Configuration
20
+ lv_fileHandler = RotatingFileHandler(CONFIG.LOG_FILE, maxBytes=(1048576*5), backupCount=7)
21
+ lv_fileHandler.setLevel(CONFIG.DEFAULT_LEVELS[CONFIG.FILE_LOG_LEVEL])
22
+ lv_fileHandler.setFormatter(logging.Formatter(CONFIG.FILE_LOG_FORMAT))
23
+ lv_logger.addHandler(lv_fileHandler)
24
+
25
+ # Console Handler Configuration
26
+ lv_consoleHandler = logging.StreamHandler(sys.stdout)
27
+ lv_consoleHandler.setLevel(CONFIG.DEFAULT_LEVELS[CONFIG.CONSOLE_LOG_LEVEL])
28
+ lv_consoleHandler.setFormatter(logging.Formatter(CONFIG.CONSOLE_LOG_FORMAT))
29
+ lv_logger.addHandler(lv_consoleHandler)
30
+
31
+ # Confirmation Message
32
+ lv_logger.info("FlaskServer Logging Started")
33
+ except Exception as e:
34
+ print("Error in fn_start_logging: ", e)
35
+ print("Error in fn_start_logging: ", traceback.format_exc())
36
+ return None