LoginSignup
5
3

More than 3 years have passed since last update.

pythonプログラム起動時に「ValueError: Unable to configure handler 'file_output_handler'」

Posted at

事象

コード自体は問題なさそうなのだが、なぜかエラーになる。

.
..
...
LOG_CONFIG = {
    'version': 1,
    ...
    ..
    .
    'handlers': {
        'console': {
            'formatter': 'default',
            'class': 'logging.StreamHandler',
            'stream': 'ext://sys.stderr',
        },
        'output': {
            'level': 'DEBUG',
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'formatter': 'default',
            'filename': '/path/to/application.log',
            'when': 'MIDNIGHT',
            'interval': 1,
            'backupCount': 5,
        },
    },
    ...
    ..
    .
}
...
..
.
.
..
...
  File "./main.py", line 7, in <module>
    load_log_config()
  File "./configs/log_config.py", line 41, in load_log_config
    dictConfig(LOG_CONFIG)
  File "/root/local/python-3.8.5/lib/python3.8/logging/config.py", line 808, in dictConfig
    dictConfigClass(config).configure()
  File "/root/local/python-3.8.5/lib/python3.8/logging/config.py", line 570, in configure
    raise ValueError('Unable to configure handler '
ValueError: Unable to configure handler 'file_output_handler'

原因

filenameに指定したディレクトリが存在しない(または誤っている)のが原因
エラーメッセージがわかりづらくて少しハマった・・・

.
..
...
LOG_CONFIG = {
    'version': 1,
    ...
    ..
    .
    'handlers': {
        'console': {
            'formatter': 'default',
            'class': 'logging.StreamHandler',
            'stream': 'ext://sys.stderr',
        },
        'output': {
            'level': 'DEBUG',
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'formatter': 'default',
            'filename': '/path/to/application.log', ← コレ
            'when': 'MIDNIGHT',
            'interval': 1,
            'backupCount': 5,
        },
    },
    ...
    ..
    .
}
...
..
.
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3