-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPyLogger.py
32 lines (28 loc) · 1015 Bytes
/
PyLogger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# coding: utf-8
#!/usr/bin/env python
import time
import datetime
import logging
import os
class pyLogger:
def __init__(self, configItems):
self.logfn = configItems['exception_logfile']
self.log_dir = configItems['log_dir']
self.logfile_fullpath = self.log_dir+self.logfn
self.app_name = configItems['app_name']
def setConfig(self):
#open a file to clear log
#fo = open(self.logfile_fullpath, "w")
#fo.close
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(self.app_name)
logger.setLevel(logging.INFO)
# create the logging file handler
fh = logging.FileHandler(self.logfile_fullpath)
#formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
# add handler to logger object
logger.addHandler(fh)
return logger
if __name__ == "__main__":
main()