P113305A009D8M
P113305A009D8M

Reputation: 374

OSError:[Errno 22] Invalid argument When reading python logging config file

Here is my config file and this config file will be read by python script.

 [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,)

And following python script have to read config file and to output log file

  #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()))

And I got this error OSError:[Errno 22] Invalid argument : 'D:\\home\\site\\wwwroot\\App_data\\jobs\triggered\\Logs\\test.log What is wrong here? Please teach me. Thanks.

Upvotes: 0

Views: 1096

Answers (1)

Seems like you have unescaped backslash in your path which messes up the windows - \triggered.

See https://github.com/Pylons/pyramid/issues/708 for more related info.

Upvotes: 1

Related Questions