import logging
import daemon
Channe = "/python/YueNan/log/"
channl_name = "yuenan"
logging.basicConfig(filename=Channe + channl_name + ".log",level=logging.INFO,format='%(asctime)s:%(levelname)s:%(message)s')
logging.info("开始关服1")
with daemon.DaemonContext():
logging.info("开始开服服")
这样写时, logging.info("开始开服服")这一句始终写不进日志文件中。
这是运行daemon时把日志IO都关闭了。
这样写就ok了。
import logging
import daemon
Channe = "/python/YueNan/log/"
channl_name = "yuenan"
logging.basicConfig(filename=Channe + channl_name + ".log",level=logging.INFO,format='%(asctime)s:%(levelname)s:%(message)s')
logger = logging.getLogger()
#得到io地址:[<_io.TextIOWrapper name='/python/YueNan/log/yuenan.log' mode='a' encoding='UTF-8'>]
logger_io= [handler.stream for handler in logger.handlers]
logging.info("开始关服1")
with daemon.DaemonContext(files_preserve = logger_io):
logging.info("开始开服服")