我正在使用YAML日志记录配置-python(无框架) 要登录到控制台和文件,我的脚本可以在pycharm和python控制台中正常运行,但不能在Windows终端中使用,我的项目需要使用此命令(使用日志日期登录到文件) 请问我还能做些什么才能使其在Windows终端中正常工作?
handlers:
console:
class: logging.StreamHandler
level: DEBUG
formatter: simple
stream: ext://sys.stdout
file:
class: logging.handlers.TimedRotatingFileHandler
level: DEBUG
formatter: standard
filename: ../results/errors.log
when: midnight
backupCount: 20
encoding: utf8
class setupLogging:
path='../resources/log_config.yaml'
with open(path, 'rt') as f:
try:
config = yaml.safe_load(f.read())
logging.config.dictConfig(config)
except Exception as e:
print(e)
当它起作用时,结果是(pycharm和python控制台):
2019-07-11 16:34:30 | __main__ | INFO | ******Hello*****
2019-07-11 16:24:49 | classes.frames.frameHome | INFO | version is up-to-date
2019-07-11 16:24:49 | classes.frames.frameHome | INFO | Connection OK
2019-07-11 16:24:49 | classes.frames.frameHome | INFO | ====== Test passed ======
[控制台-cmd] (我必须在yaml文件和setupLoging.py中指定绝对路径),但毕竟无法正常工作
?[32m2019-07-17 13:12:23?[0m | ?[34mclasses.frames.frameHome?[0m | ?[30mINFO?[0m | ====== Test passed ======
[文件] 日志文件未显示任何内容
有什么想法吗?