update Actor6

This commit is contained in:
liangsen committed 2022-05-27 16:23:49 +08:00
1 parent dac314c9a5
commit e9b2b238b2
35 files changed
+1226 -697

No files matched your search

+16 -13
View File
@@ -29,21 +29,24 @@ class Logger(logging.Logger):
def __init__(self, path_output, path_config=None, postfix=None, level=logging.NOTSET ):
logging.Logger.__init__(self, '', level)
# logger filename suffix
suffix = f"{datetime.datetime.now().strftime('%Y%m%d-%HH%MM%SS')}"
if postfix is not None:
suffix += "_" + str(postfix)
# make dir
basename = path_config.name.split(".")[0] if path_config is not None else "log"
if postfix is None:
postfix = f"{datetime.datetime.now().strftime('%Y%m%d-%HH%MM%SS')}"
self.path_output = Path(path_output).joinpath(basename, postfix)
self.path_output.mkdir(parents=True, exist_ok=True)
# copy config
dst = self.path_output.joinpath(path_config.name)
shutil.copyfile(src=path_config, dst=dst)
# make dir & set filename
if path_config is not None:
basename = path_config.name.split(".")[0]
self.path_output = Path(path_output).joinpath(basename, suffix)
self.path_output.mkdir(parents=True, exist_ok=True)
filename = self.path_output.joinpath(f"logger.log")
shutil.copyfile(src=path_config, dst=self.path_output.joinpath(path_config.name))
else:
self.path_output = Path(path_output)
self.path_output.mkdir(parents=True, exist_ok=True)
filename = self.path_output.joinpath(suffix + ".log")
# add file hander
filename = self.path_output.joinpath(f"logger.log")
fHander = logging.FileHandler(filename)
fFormat = logging.Formatter('[%(asctime)s][%(levelname)s] %(message)s')
fHander.setFormatter(fFormat)
@@ -54,6 +57,7 @@ class Logger(logging.Logger):
cFormat = ColoredFormatter( RESET_SEQ+"[%(asctime)s] %(message)s"+RESET_SEQ )
cHander.setFormatter(cFormat)
self.addHandler(cHander)
def setContext(self, key, value):
self.context[key] = value
@@ -72,7 +76,6 @@ class Logger(logging.Logger):
super(Logger, self).error(e[1].message)
class ColoredFormatter(logging.Formatter):
def __init__(self, msg, use_color = True):
logging.Formatter.__init__(self, msg, datefmt='%Y-%m-%d %H:%M:%S')