Added default logger handler and made coloredlogs optional

This commit is contained in:
Ilan Steemers
2015-06-26 18:07:44 +02:00
parent f08773f37d
commit 8c4f0110fb
4 changed files with 35 additions and 4 deletions
+19 -2
View File
@@ -27,7 +27,6 @@ except ImportError:
import pickle
# External
import coloredlogs
import redis
import arrow
@@ -43,7 +42,25 @@ from .models import Task, Success, Schedule
SIGNAL_NAMES = dict((getattr(signal, n), n) for n in dir(signal) if n.startswith('SIG') and '_' not in n)
logger = logging.getLogger('django-q')
coloredlogs.install(level=getattr(logging, LOG_LEVEL))
# Optional coloredlogs support
try:
import coloredlogs
coloredlogs.install(level=getattr(logging, LOG_LEVEL))
except ImportError:
coloredlogs = None
# Set up standard logging handler
if not logger.handlers:
logger.setLevel(level=getattr(logging, LOG_LEVEL))
formatter = logging.Formatter(fmt='%(asctime)s [django_q] %(message)s',
datefmt='%H:%M:%S')
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)
Q_LIST = '{}:q'.format(PREFIX)
STARTING = 'Starting'
+15
View File
@@ -81,6 +81,21 @@ USE_L10N = True
USE_TZ = True
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django_q': {
'handlers': ['console'],
'level': 'INFO',
},
},
}
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
-1
View File
@@ -1,6 +1,5 @@
arrow==0.5.4
blessed==1.9.5
coloredlogs==1.0.1
django-picklefield==0.3.1
Django==1.8.2
future==0.14.3
+1 -1
View File
@@ -35,7 +35,7 @@ setup(
license='MIT',
description='A multiprocessing task queue for Django',
long_description=README,
install_requires=['django>=1.7', 'redis', 'coloredlogs', 'django-picklefield', 'blessed', 'arrow'],
install_requires=['django>=1.7', 'redis', 'django-picklefield', 'blessed', 'arrow'],
test_requires=['pytest', 'pytest-django', ],
cmdclass={'test': PyTest},
classifiers=[