Ejemplo n.º 1
0
    def test_record_none_exc_info(self):
        # sys.exc_info can return (None, None, None) if no exception is being
        # handled anywhere on the stack. See:
        #  http://docs.python.org/library/sys.html#sys.exc_info
        record = logging.LogRecord(
            "foo", logging.INFO, pathname=None, lineno=None, msg="test", args=(), exc_info=(None, None, None)
        )
        handler = SentryHandler()
        handler.emit(record)

        self.assertEquals(len(self.raven.events), 1)
        event = self.raven.events.pop(0)
        self.assertEquals(event["message"], "test")
Ejemplo n.º 2
0
    def test_request_kwarg(self):
        handler = SentryHandler()

        logger = self.logger
        logger.handlers = []
        logger.addHandler(handler)

        logger.error('This is a test error',
                     extra={
                         'request':
                         WSGIRequest(
                             environ={
                                 'wsgi.input': StringIO(),
                                 'REQUEST_METHOD': 'POST',
                                 'SERVER_NAME': 'testserver',
                                 'SERVER_PORT': '80',
                                 'CONTENT_TYPE': 'application/octet-stream',
                                 'ACCEPT': 'application/json',
                             })
                     })

        self.assertEquals(len(self.raven.events), 1)
        event = self.raven.events.pop(0)
        self.assertTrue('sentry.interfaces.Http' in event)
        http = event['sentry.interfaces.Http']
        self.assertEquals(http['method'], 'POST')
Ejemplo n.º 3
0
    def test_request_kwarg(self):
        handler = SentryHandler()

        logger = self.logger
        logger.handlers = []
        logger.addHandler(handler)

        logger.error('This is a test error',
                     extra={
                         'request':
                         WSGIRequest(
                             environ={
                                 'wsgi.input': StringIO(),
                                 'REQUEST_METHOD': 'POST',
                                 'SERVER_NAME': 'testserver',
                                 'SERVER_PORT': '80',
                                 'CONTENT_TYPE': 'application/octet-stream',
                                 'ACCEPT': 'application/json',
                             })
                     })

        assert len(self.raven.events) == 1
        event = self.raven.events.pop(0)
        assert 'request' in event
        http = event['request']
        assert http['method'] == 'POST'
Ejemplo n.º 4
0
def log_configure():
    """You have to explicitly call this to configure logging."""
    for key, value in settings.LOGGING.items():
        if isinstance(cfg[key], dict):
            cfg[key].update(value)
        else:
            cfg[key] = value

    USE_SYSLOG = settings.HAS_SYSLOG and not settings.DEBUG

    if USE_SYSLOG:
        cfg['loggers']['z.timer'] = {'handlers': ['syslog2']}

    # Set the level and handlers for all loggers.
    for logger in cfg['loggers'].values() + [cfg['root']]:
        if 'handlers' not in logger:
            logger['handlers'] = ['syslog' if USE_SYSLOG else 'console']
        if 'level' not in logger:
            logger['level'] = settings.LOG_LEVEL
        if logger is not cfg['root'] and 'propagate' not in logger:
            logger['propagate'] = False

    dictconfig.dictConfig(cfg)

    # logging.getLogger() accesses a singleton, this just binds
    # in the SentryHandler to error level messages
    tastypie = logging.getLogger('django.request.tastypie')
    tastypie.addHandler(SentryHandler())
Ejemplo n.º 5
0
    def test_record_none_exc_info(self):
        # sys.exc_info can return (None, None, None) if no exception is being
        # handled anywhere on the stack. See:
        #  http://docs.python.org/library/sys.html#sys.exc_info
        record = logging.LogRecord(
            'foo',
            logging.INFO,
            pathname=None,
            lineno=None,
            msg='test',
            args=(),
            exc_info=(None, None, None),
        )
        handler = SentryHandler()
        handler.emit(record)

        assert len(self.raven.events) == 1
        event = self.raven.events.pop(0)
        assert event['message'] == 'test'
Ejemplo n.º 6
0
    def test_record_none_exc_info(self):
        # sys.exc_info can return (None, None, None) if no exception is being
        # handled anywhere on the stack. See:
        #  http://docs.python.org/library/sys.html#sys.exc_info
        record = logging.LogRecord(
            'foo',
            logging.INFO,
            pathname=None,
            lineno=None,
            msg='test',
            args=(),
            exc_info=(None, None, None),
        )
        handler = SentryHandler()
        handler.emit(record)

        assert len(self.raven.events) == 1
        event = self.raven.events.pop(0)
        assert event['message'] == 'test'
Ejemplo n.º 7
0
def get_and_configure_logger(name: str) -> logging.Logger:
    unconfigure_root_logger()

    global LOG_LEVEL
    if LOG_LEVEL is None:
        LOG_LEVEL = get_env_variable_gracefully("LOG_LEVEL", "INFO")

    # Set level to a environment variable; I think at least
    logger = daiquiri.getLogger(name)
    logger.setLevel(logging.getLevelName(LOG_LEVEL))

    # This is the local handler
    handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(
        daiquiri.formatter.ColorExtrasFormatter(fmt=FORMAT_STRING,
                                                keywords=[]))
    logger.logger.addHandler(handler)

    # This is the Sentry handler
    if settings.RAVEN_DSN:
        from raven.contrib.django.handlers import SentryHandler

        handler = SentryHandler()
        handler.setFormatter(
            daiquiri.formatter.ColorExtrasFormatter(fmt=FORMAT_STRING,
                                                    keywords=[]))
        handler.setLevel(logging.WARNING)
        logger.logger.addHandler(handler)

    return logger
Ejemplo n.º 8
0
    def test_tags(self):
        tags = {'tag1': 'test'}
        handler = SentryHandler(tags=tags)

        logger = self.logger
        logger.handlers = []
        logger.addHandler(handler)

        logger.error('This is a test error')

        assert len(self.raven.events) == 1
        event = self.raven.events.pop(0)
        assert 'tags' in event
        # event['tags'] also contains some other data, like 'site'
        assert 'tag1' in event['tags']
        assert event['tags']['tag1'] == tags['tag1']
Ejemplo n.º 9
0
SENTRY_CACHE_BACKEND = 'default'

EMAIL_SUBJECT_PREFIX = '[Sentry] '

# Configure logging
from raven.conf import setup_logging
from raven.contrib.django.handlers import SentryHandler
import logging

# Configure root logger
logger = logging.getLogger()
logger.setLevel(logging.INFO)

handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
logger.addHandler(handler)

# Disable django.request as it's generally useless
logger = logging.getLogger('django.request')
logger.propagate = False
logger.addHandler(handler)

# Configure default sentry logging
sentry_handler = SentryHandler()
sentry_handler.setLevel(logging.ERROR)
setup_logging(sentry_handler)

# Configure celery
import djcelery
djcelery.setup_loader()
Ejemplo n.º 10
0
SENTRY_CACHE_BACKEND = 'default'

EMAIL_SUBJECT_PREFIX = '[Sentry] '

# Configure logging
from raven.conf import setup_logging
from raven.contrib.django.handlers import SentryHandler
import logging

# Configure root logger
logger = logging.getLogger()
logger.setLevel(logging.INFO)

handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
logger.addHandler(handler)

# Disable django.request as it's generally useless
logger = logging.getLogger('django.request')
logger.propagate = False
logger.addHandler(handler)

# Configure default sentry logging
sentry_handler = SentryHandler()
sentry_handler.setLevel(logging.ERROR)
setup_logging(sentry_handler)

# Configure celery
import djcelery
djcelery.setup_loader()
Ejemplo n.º 11
0
        'PASSWORD': '',
    }
}

COMPRESS_ROOT = "/var/www/capsim/capsim/media/"
DEBUG = False
TEMPLATE_DEBUG = DEBUG
STAGING_ENV = True

STATSD_PREFIX = 'capsim-staging'
SENTRY_SITE = 'capsim-staging'
SENTRY_SERVERS = ['http://sentry.ccnmtl.columbia.edu/sentry/store/']

if 'migrate' not in sys.argv:
    INSTALLED_APPS.append('raven.contrib.django')

    import logging
    from raven.contrib.django.handlers import SentryHandler
    logger = logging.getLogger()
    # ensure we havent already registered the handler
    if SentryHandler not in map(type, logger.handlers):
        logger.addHandler(SentryHandler())
        logger = logging.getLogger('sentry.errors')
        logger.propagate = False
        logger.addHandler(logging.StreamHandler())

try:
    from local_settings import *
except ImportError:
    pass
Ejemplo n.º 12
0
#!/usr/bin/env python
import os
import sys
import logging

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "leela.settings")

    from django.core.management import execute_from_command_line
    from raven import setup_logging
    from raven.contrib.django.handlers import SentryHandler

    setup_logging(SentryHandler(level=logging.WARNING))

    execute_from_command_line(sys.argv)
Ejemplo n.º 13
0
 def __init__(self):
     self.logger = logging.getLogger('task')
     self.logger.setLevel(logging.DEBUG)
     self.logger.addHandler(SentryHandler())
     self.logger.debug('Conversion process ready')
Ejemplo n.º 14
0
    },
}

dictConfig(LOGGING)

RAVEN_CONFIG = {
    'dsn':
    'https://*****:*****@sentry.io/98255',
    # If you are using git, you can also automatically configure the
    # release based on the git info.
    'release':
    raven.fetch_git_sha(os.path.join(os.path.dirname(__file__), '..')),
}

handler = SentryHandler(
    'https://*****:*****@sentry.io/53555'
)
raven.setup_logging(handler)

COPY_START_YEAR = 2016
VERSION = 'v0.0.001'

# Propeller WebIDE settings
WEBIDE_GIT_ROOT = config.get("project", "root")

# Export settings to use in templates
SETTINGS_EXPORT = [
    'USE_CDN',
    'VERSION',
]