假设我有以下配置日志文件:
[loggers]
keys=root,seeker,event
[handlers]
keys=consoleHandler,seekerFileHandler,eventFileHandler
[formatters]
keys=consoleFormatter,logFormatter
[logger_root]
level=DEBUG
handlers=consoleHandler,seekerFileHandler,eventFileHandler
[logger_seeker]
level=DEBUG
handlers=consoleHandler,seekerFileHandler
qualname=seeker
propagate=0
[logger_event]
level=DEBUG
handlers=consoleHandler,eventFileHandler
qualname=event
propagate=0
[handler_consoleHandler]
class=StreamHandler
level=INFO
formatter=consoleFormatter
args=(sys.stdout,)
[handler_seekerFileHandler]
class=FileHandler
level=DEBUG
formatter=logFormatter
args=('seeker.log','a')
[handler_eventFileHandler]
class=FileHandler
level=DEBUG
formatter=logFormatter
args=('event.log','a')
[formatter_consoleFormatter]
format=%(asctime)s - thread:%(thread)d - %(name)s - %(levelname)s | %(message)s
datefmt=%m/%d/%Y %X
[formatter_logFormatter]
format=%(asctime)s | %(message)s
datefmt=%m/%d/%Y %X
通常我会:
import logging
from logging.config import fileConfig
from os import getcwd
fileConfig(''.join([getcwd(),'/logging.conf']))
event_logger = logging.getLogger("event")
seeker_logger = logging.getLogger("seeker")
处理每个记录器。但是,我倾向于在两个不同的平台上运行该软件:Windows 和 Linux,因此如果它们各自将其保存在“公共”位置会更好。我正在寻找的是这样的:
from sys import platform
if 'win' in platform:
#alter the save path to this location
if 'linux' in platform:
#alter save path to this location
但我不知道如何使用配置文件来实现这一点,有什么想法吗?