LinuxTeam-teilar / cronos.teilar.gr

cronos.teilar.gr website
http://cronos.teilar.gr
GNU Affero General Public License v3.0
5 stars 1 forks source link

Logger does not find handler #1

Closed tampakrap closed 12 years ago

tampakrap commented 12 years ago

For unknown reason, the logger is NOT able to find a handler unless a settings.VARIABLE is called! In some cronjobs, this was done through imports of other modules that reside inside django/, most commonly the import of django.db which contains (in the __init__.py file) the variable settings.DATABASES. In cronos, in order to work around it, I added settings.DEBUG in apps/__init__.py Steps to reproduce: 1) Comment out settings.DEBUG from apps/__init__.py 2) Put the following script under apps/teilar/handlerbug.py:

import os
import sys
from proj_root import PROJECT_ROOT
sys.path.append(PROJECT_ROOT)
os.environ['DJANGO_SETTINGS_MODULE'] = 'apps.settings'
from apps import log_extra_data
import logging

logger = logging.getLogger('cronos')
print logger.__dict__

try:
    import sldkfjsfj
except Exception as error:
    logger.error(error, extra = log_extra_data())

3) Run the script: python apps/teilar/handlerbug.py

{'name': 'cronos', 'parent': <logging.RootLogger object at 0x9e17d0>, 'handlers': [], 'level': 0, 'disabled': 0, 'manager': <logging.Manager object at 0x9e1890>, 'propagate': 1, 'filters': []}
No handlers could be found for logger "cronos"
{'name': 'cronos', 'parent': <logging.RootLogger object at 0x9eb090>, 'handlers': [<logging.StreamHandler object at 0xe5c1d0>], 'level': 10, 'disabled': 0, 'manager': <logging.Manager object at 0x9eb150>, 'propagate': 1, 'filters': []}
cronos: ERROR    Message: No module named sldkfjsfj                     
cronos: File: test Function: <module> Line: 15
tampakrap commented 12 years ago

This could be a bug (or feature) in django itself, but the proper solution is to get rid of the cronjobs and move to celery

Drakevr commented 12 years ago

I'd go with Celery being more "Django-ish" in choice rather than dirty hacking stuff around with cronjobs to circumvent said problem.

However Celery requires a broker of its own for communication which increases the set of deps by 2 (Celery + your broker of choice)

if deps are not a problem though then yeah think of a move to that.

NOTE: if you are handling critical data.. you better avoid redis here , even if its feature complete it tends to barf with power failures

tampakrap commented 12 years ago

the migration to celery is still needed though, the wiki entry will stay there