Created
October 29, 2010 02:43
-
-
Save matagus/652785 to your computer and use it in GitHub Desktop.
logbook + json + filehandler for django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import os | |
from logbook import Logger, TimedRotatingFileHandler | |
from logbook.queues import ThreadedWrapperHandler | |
from django.conf import settings | |
from django.core.serializers.json import simplejson | |
def json_formatter(record, handler): | |
return simplejson.dumps(record.message) | |
def get_logger(name="root"): | |
logger = Logger(name) | |
file_path = os.path.join(settings.STATS_LOG_FILEPATH, "%s.log" % name) | |
handler = ThreadedWrapperHandler( | |
TimedRotatingFileHandler(file_path, date_format="%Y-%m-%d-%Hhs") | |
) | |
handler.formatter=json_formatter | |
logger.handlers.append(handler) | |
return logger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment