这是我的配置文件,这个配置文件将由python脚本读取。
[loggers]
keys=root
[logger_root]
level=DEBUG
handlers=screen,file
[formatters]
keys=simple,complex
[formatter_simple]
format='%(asctime)s [%(levelname)s] %(message)s'
datefmt=%Y/%m/%d %H:%M:%S
[formatter_complex]
format='%(asctime)s %(process)s %(processName)s [%(levelname)s] %(message)s'
datefmt=%Y/%m/%d %H:%M:%S
[handlers]
keys=file,screen
[handler_file]
class=handlers.TimedRotatingFileHandler
interval=midnight
backupCount=5
formatter=complex
level=NOTSET
args=('%(logfile)s',)
[handler_screen]
class=StreamHandler
formatter=simple
level=NOTSET
args=(sys.stdout,)
以下python脚本必须读取配置文件并输出日志文件
#Make logs folder under current working directory
# and make log file config
def _init_log():
currentTime = datetime.now().strftime('%Y%m%d')
fileName = "ISS-"+str(currentTime)+".txt"
current_directory = os.getcwd()
log_directory = os.path.join(current_directory, r'Logs')
if not os.path.exists(log_directory):
os.makedirs(log_directory)
current_directory = os.path.join(current_directory,"Logs",fileName)
logging.config.fileConfig('logging.config', defaults={'logfile':str(current_directory)}, disable_existing_loggers=False)
logger.info("Current working directory is :"+os.getcwd())
logger.info("real home directory is "+str(Path.home()))
我收到此错误OSError:[Errno 22] Invalid argument : 'D:\\home\\site\\wwwroot\\App_data\\jobs\triggered\\Logs\\test.log
这有什么不对?请教我。感谢。
答案 0 :(得分:1)
好像你的路径中没有未反转的反斜杠会弄乱窗户 - \触发。
有关更多相关信息,请参阅https://github.com/Pylons/pyramid/issues/708。