没有这样的文件或目录:'/ django_logs/documents_utils.log'

时间:2018-02-08 04:53:04

标签: python django exception

我在两个月之后和经过大量更改之后撤出了存储库,并且在启动项目后我遇到了这个问题,并且不知道如何解决它。请帮助我=(

   Unhandled exception in thread started by <function wrapper at 0x7f5d6c15d578>
    Traceback (most recent call last):
      File "/home/sabo/projects/envs/halyk/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
        fn(*args, **kwargs)
      File "/home/sabo/projects/envs/halyk/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
        autoreload.raise_last_exception()
      File "/home/sabo/projects/envs/halyk/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
        six.reraise(*_exception)
      File "/home/sabo/projects/envs/halyk/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
        fn(*args, **kwargs)
      File "/home/sabo/projects/envs/halyk/local/lib/python2.7/site-packages/django/__init__.py", line 17, in setup
        configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
      File "/home/sabo/projects/envs/halyk/local/lib/python2.7/site-packages/django/utils/log.py", line 71, in configure_logging
        logging_config_func(logging_settings)
      File "/usr/lib/python2.7/logging/config.py", line 794, in dictConfig
        dictConfigClass(config).configure()
      File "/usr/lib/python2.7/logging/config.py", line 576, in configure
        '%r: %s' % (name, e))
    ValueError: Unable to configure handler 'utils_log_file': [Errno 2] No such file or directory: '/django_logs/documents_utils.log'

更新 还有我的settings.py文件,其中Loggins添加了这个路径,路径显示位置到服务器,以及我如何以及在哪里添加它以启动我的项目本地?

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
    'verbose': {
        'format': '%(levelname)s %(asctime)s path: %(pathname)s module: %(module)s method: %(funcName)s  row: %(lineno)d message: %(message)s'
    },
    'simple': {
        'format': '%(levelname)s %(message)s'
    },
},
'filters': {
    'require_debug_true': {
        '()': 'django.utils.log.RequireDebugTrue',
    },
    'require_debug_false': {
        '()': 'django.utils.log.RequireDebugFalse'
    }
},
'handlers': {
    'mail_admins': {
        'level': 'ERROR',
        'filters': ['require_debug_false'],
        'class': 'utils.handlers.MainAdminEmailHandler',
        'formatter': 'verbose',
    },
    'utils_log_file': {
        'level': 'INFO',
        'class': 'logging.handlers.RotatingFileHandler',
        'filename': '/django_logs/documents_utils.log',
        'maxBytes': 1024*1024*15, # 15MB
        'backupCount': 10,
        'formatter': 'verbose'
    },
    'console': {
        'level': 'INFO',
        'filters': ['require_debug_true'],
        'class': 'logging.StreamHandler',
        'formatter': 'simple'
    },
},
'loggers': {
    'django': {
        'handlers': ['console'],
        'propagate': True,
    },
    'django.request': {
        'handlers': ['mail_admins'],
        'level': 'ERROR',
        'propagate': True,
    },
    'utils': {
        'handlers': ['utils_log_file', 'mail_admins'],
        'level': 'INFO',
    },
    'documents': {
        'handlers': ['utils_log_file', 'mail_admins'],
        'level': 'INFO',
    },
}

1 个答案:

答案 0 :(得分:0)

是的,我通过添加这个部分来解决这个问题

if not os.path.exists('/django_logs/documents_utils.log'):
    del LOGGING['handlers']['utils_log_file']
    del LOGGING['loggers']['utils']
    del LOGGING['loggers']['documents']