python - Django/Python 应用程序日志记录不起作用

标签 python django logging syslog

我完全是 Python 菜鸟。现在我正在设置一个新项目,有时我不得不调用 ./manage.py syncdb。这是我收到的:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/logging/handlers.py", line 820, in _connect_unixsocket
    self.socket.connect(address)
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/logging/config.py", line 557, in configure
    handler = self.configure_handler(handlers[name])
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/logging/config.py", line 725, in configure_handler
    result = factory(**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/logging/handlers.py", line 803, in __init__
    self._connect_unixsocket(address)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/logging/handlers.py", line 831, in _connect_unixsocket
    self.socket.connect(address)
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./manage.py", line 9, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/krasimir/.virtualenvs/trialreach/lib/python3.4/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/Users/krasimir/.virtualenvs/trialreach/lib/python3.4/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/krasimir/.virtualenvs/trialreach/lib/python3.4/site-packages/django/core/management/__init__.py", line 261, in fetch_command
    commands = get_commands()
  File "/Users/krasimir/.virtualenvs/trialreach/lib/python3.4/site-packages/django/core/management/__init__.py", line 107, in get_commands
    apps = settings.INSTALLED_APPS
  File "/Users/krasimir/.virtualenvs/trialreach/lib/python3.4/site-packages/django/conf/__init__.py", line 54, in __getattr__
    self._setup(name)
  File "/Users/krasimir/.virtualenvs/trialreach/lib/python3.4/site-packages/django/conf/__init__.py", line 50, in _setup
    self._configure_logging()
  File "/Users/krasimir/.virtualenvs/trialreach/lib/python3.4/site-packages/django/conf/__init__.py", line 80, in _configure_logging
    logging_config_func(self.LOGGING)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/logging/config.py", line 789, in dictConfig
    dictConfigClass(config).configure()
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/logging/config.py", line 565, in configure
    '%r: %s' % (name, e))
ValueError: Unable to configure handler 'syslog': [Errno 2] No such file or directory

有什么解决问题的想法吗?

这是我的settings.py

# DJANGO SETTINGS FILE - ideas from http://justcramer.com/2011/01/13/settings-in-django/

import os, sys
import importlib

## Import our defaults (globals)
from .conf.default import *

## Inherit from environment specifics
DJANGO_CONF = os.environ.get('DJANGO_CONF', 'default')
sys.path.insert(0, os.getcwd())
if DJANGO_CONF != 'default':
    module = __import__(DJANGO_CONF, globals(), locals(), ['*'], 1)
    for k in dir(module):
        locals()[k] = getattr(module, k)

## Import local settings
try:
    from .local_settings import *
except ImportError as e:
    pass

## Remove disabled apps
if 'DISABLED_APPS' in locals():
    INSTALLED_APPS = [k for k in INSTALLED_APPS if k not in DISABLED_APPS]

    MIDDLEWARE_CLASSES = list(MIDDLEWARE_CLASSES)
    DATABASE_ROUTERS = list(DATABASE_ROUTERS)
    TEMPLATE_CONTEXT_PROCESSORS = list(TEMPLATE_CONTEXT_PROCESSORS)

    for a in DISABLED_APPS:
        for x, m in enumerate(MIDDLEWARE_CLASSES):
            if m.startswith(a):
                MIDDLEWARE_CLASSES.pop(x)

        for x, m in enumerate(TEMPLATE_CONTEXT_PROCESSORS):
            if m.startswith(a):
                TEMPLATE_CONTEXT_PROCESSORS.pop(x)

        for x, m in enumerate(DATABASE_ROUTERS):
            if m.startswith(a):
                DATABASE_ROUTERS.pop(x)

if 'djcelery' in INSTALLED_APPS:
    import djcelery
    djcelery.setup_loader()

# DONT TOUCH THESE - overwritten by fabfile.py

VERSION = "UNVERSIONED"

DEFAULT_LOG = 'console'

最佳答案

我发现了问题所在。而不是 /dev/log 我的 OS X 版本有 /var/run/syslog。所以:

if DEBUG or not os.path.exists('/dev/log'):
    LOGGING['handlers']['syslog']['address'] = '/var/run/syslog'

关于python - Django/Python 应用程序日志记录不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27211396/

相关文章:

javascript - 未捕获的语法错误 : Unexpected token & while rendering a Django template

python - Django shell 中的奇怪字符,箭头键不起作用

android - 使用 res/raw 文件夹中的 mp3 设置铃声

python - for循环省略了一些列表元素

python - 与 pylint disable=<something> 和/usr/bin/env python 相同的 python 文件

python - 使用 Python 格式化 Excel 中的单元格

python - DRF3 在 m2m 关系上创建嵌套序列化器

flash - Flash CS4崩溃日志在OSX上的哪里?

mysql - 在记录付款交易时,我应该使用表的 ID 还是直接使用值

python - 使用 lambda、python 在 PySpark 中进行元组操作