Skip to content

Instantly share code, notes, and snippets.

@tswicegood
Created November 1, 2011 19:34
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tswicegood/1331656 to your computer and use it in GitHub Desktop.
Save tswicegood/1331656 to your computer and use it in GitHub Desktop.
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
Copy link

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