bugfox
This commit is contained in:
parent
82f214578f
commit
f701dc2fb9
27
appPublic/app_logger.py
Normal file
27
appPublic/app_logger.py
Normal file
@ -0,0 +1,27 @@
|
||||
import sys
|
||||
import logging
|
||||
from functools import partial
|
||||
|
||||
levels={
|
||||
"debug":logging.DEBUG,
|
||||
"info":logging.INFO,
|
||||
"warning":logging.WARNING,
|
||||
"error":logging.error,
|
||||
"critical":logging.CRITICAL
|
||||
}
|
||||
defaultfmt = '%(asctime)s[%(name)s][%(filename)s:%(lineno)s]%(message)s'
|
||||
|
||||
def create_logger(name, formater=defaultfmt, levelname='info', file=None):
|
||||
ret = logging.getLogger(name)
|
||||
level = levels.get(levelname, levels.get('debug'))
|
||||
ret.setLevel(level)
|
||||
format = logging.Formatter(formater)
|
||||
file_handler = None
|
||||
if file is not None:
|
||||
file_handler = logging.FileHandler(file)
|
||||
else:
|
||||
file_handler = logging.StreamHandler()
|
||||
|
||||
file_handler.setFormatter(format)
|
||||
ret.addHandler(file_handler)
|
||||
return ret
|
Loading…
Reference in New Issue
Block a user