Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple code to hook up Celery and Loggly
LOGGLY_INPUT_KEY = "your key here"
import hoover
import logging
def initialize_loggly(loglevel=logging.WARN, **kwargs):
handler = hoover.LogglyHttpHandler(token=LOGGLY_INPUT_KEY)
log = logging.getLogger('celery')
log.addHandler(handler)
log.setLevel(loglevel)
return log
from celery.signals import setup_logging
setup_logging.connect(initialize_loggly)
@dmitry-saritasa

This comment has been minimized.

Copy link

@dmitry-saritasa dmitry-saritasa commented Feb 11, 2015

thanks. I modified it a little bit just in case

in your celeryconfig.py add at the bottom:

# enable logly
# for central monitoring
import logging
import logging.config
import loggly.handlers

def initialize_loggly(loglevel=logging.WARN, **kwargs):
    logging.config.fileConfig('logly-celery.conf')
    logger = logging.getLogger('celery')
    logger.setLevel(loglevel)
    return logger

and your logly-celery.conf is something like:

replace YOURTOKENHERE and YOURTAGHERE
where YOURTAGHERE is the name of tag you want to mark all celery "log entries" inside logly

[handlers]
keys=HTTPSHandler

[handler_HTTPSHandler]
class=loggly.handlers.HTTPSHandler
args=('https://logs-01.loggly.com/inputs/YOURTOKENHERE/tag/YOURTAGHERE','POST')

[formatters]
keys=

[loggers]
keys=root

[logger_root]
handlers=HTTPSHandler
level=INFO

if you run your celery worker and it crashes with message like 'no formatters found' it means - you put your celery-logly.conf in a place that celery worker doesn't see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment