Django / Python app logging not working

I am a complete noob with Python. I am currently setting up a new project and at some point I had to call ./manage.py syncdb

. This is what I got:

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

      

Any ideas how to fix the problem?

Here is my 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'

      

+3


source to share


3 answers


I found what was the problem. Instead, /dev/log

my OS X version has /var/run/syslog

. So:



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

      

+5


source


Try to set DEFAULT_LOG in your settings.py



if DEBUG or not os.path.exists('/dev/log'):
    DEFAULT_LOG = 'console'
else:
    DEFAULT_LOG = 'syslog'

      

0


source


I have also seen this error where the syslog service itself is down. Running it sudo service syslog-ng start

solved the problem for me.

0


source







All Articles