示例#1
0
    def test_handler(self):
        # If the DjangoDatabaseHandler is added to the logging.handlers 
        # namespace, it can be used in file based configurations.
        try:
            from logging.handlers import DjangoDatabaseHandler
        except ImportError:
            self.assert_('The DjangoDatabaseHandler is not present in the logging.handlers namespace after importing it.')

        # Check if our handler was added.
        is_present = False
        for h in logger.handlers:
            if isinstance(h, DjangoDatabaseHandler):
                is_present = True
                break

        self.assertTrue(is_present, 'The DjangoDatabaseHandler was not added to the root logger.')

        # Adding it again should not work.
        add_handler(logger, DjangoDatabaseHandler())

        count = 0
        for h in logger.handlers:
            if isinstance(h, DjangoDatabaseHandler):
                count += 1

        self.assertEqual(count, 1, 'The DjangoDatabaseHandler was added more then once.')
示例#2
0
    def setUp(self):
        # Store logger settings.
        self.old_logger_level = logger.level
        self.old_logger_handlers = copy.copy(logger.handlers)

        # Set up the root logger.
        logger.setLevel(logging.NOTSET)

        # Remove default handlers. Use the copy to prevent early iteration
        # termination.
        for h in self.old_logger_handlers:
            logger.removeHandler(h)

        # Add our handler to the root logger.
        add_handler(logger, DjangoDatabaseHandler())

        # Empty the log table just in case some interfering project, like South
        # added log entries.
        LogEntry.objects.all().delete()
        LogAggregate.objects.all().delete()
示例#3
0
from django.test import TestCase
from django.core.management import call_command

from djangologdb.models import LogEntry, LogAggregate
from djangologdb.handlers import DjangoDatabaseHandler, add_handler

# Set up the root logger.
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger()

# Remove default handlers.
for h in logger.handlers:
    logger.removeHandler(h)

# Add our handler to the root logger.
add_handler(logger, DjangoDatabaseHandler())

class LogTest(TestCase):

    def test_handler(self):
        # If the DjangoDatabaseHandler is added to the logging.handlers 
        # namespace, it can be used in file based configurations.
        try:
            from logging.handlers import DjangoDatabaseHandler
        except ImportError:
            self.assert_('The DjangoDatabaseHandler is not present in the logging.handlers namespace after importing it.')

        # Check if our handler was added.
        is_present = False
        for h in logger.handlers:
            if isinstance(h, DjangoDatabaseHandler):
示例#4
0
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',

    'djangologdb',
)

#
# Django-logdb settings
#
import logging
from djangologdb.handlers import DjangoDatabaseHandler, add_handler

# Configure the logging module
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger()
add_handler(logger, DjangoDatabaseHandler())

# Set django-logdb specific settings
import datetime
LOGDB_INTERVAL = datetime.timedelta(0, 60 * 60 * 12) # 12 hours
LOGDB_HISTORY_DAYS = 7