Exemplo n.º 1
0
def init_logging(app):
    """Initialize the app's logging mechanisms

    - Configure the sentry client, if a DSN is given
    - Apply the default config dict (`defaults.DEFAULT_CONFIG`)
    - If given and existent, apply the additional config file
    """

    # Configure Sentry client (raven)
    if app.config['SENTRY_DSN']:
        logger.debug("Sentry DSN: %s", app.config['SENTRY_DSN'])
        sentry = Sentry()
        sentry.init_app(app, dsn=app.config['SENTRY_DSN'])

        def register_sentry_handler():
            handler = SentryHandler()

            handler.client = app.extensions['sentry'].client
            setup_logging(handler)

            return handler
    else:
        logger.debug("No sentry DSN specified")

        def register_sentry_handler():
            return logging.NullHandler()

    # Apply default config dict
    config = replace_empty_handler_callables(DEFAULT_CONFIG,
                                             register_sentry_handler)
    logging.config.dictConfig(config)

    if app.config.get('LOG_CONFIG') is not None:
        config = replace_empty_handler_callables(app.config['LOG_CONFIG'],
                                                 register_sentry_handler)
        logging.config.dictConfig(config)

    logger.debug('Initialized logging',
                 extra={
                     'data': {
                         'DEFAULT_CONFIG': DEFAULT_CONFIG,
                         'EXTRA_CONFIG': app.config.get('LOG_CONFIG')
                     }
                 })
Exemplo n.º 2
0
def init_logging(app):
    """Initialize the app's logging mechanisms

    - Configure the sentry client, if a DSN is given
    - Apply the default config dict (`defaults.DEFAULT_CONFIG`)
    - If given and existent, apply the additional config file
    """

    # Configure Sentry client (raven)
    if app.config['SENTRY_DSN']:
        logger.debug("Sentry DSN: %s", app.config['SENTRY_DSN'])
        sentry = Sentry()
        sentry.init_app(app, dsn=app.config['SENTRY_DSN'])

        def register_sentry_handler():
            handler = SentryHandler()

            handler.client = app.extensions['sentry'].client
            setup_logging(handler)

            return handler
    else:
        logger.debug("No sentry DSN specified")

        def register_sentry_handler():
            return logging.NullHandler()

    # Apply default config dict
    config = replace_empty_handler_callables(DEFAULT_CONFIG,
                                             register_sentry_handler)
    logging.config.dictConfig(config)

    if app.config.get('LOG_CONFIG') is not None:
        config = replace_empty_handler_callables(app.config['LOG_CONFIG'],
                                                 register_sentry_handler)
        logging.config.dictConfig(config)

    logger.debug('Initialized logging', extra={'data': {
        'DEFAULT_CONFIG': DEFAULT_CONFIG,
        'EXTRA_CONFIG': app.config.get('LOG_CONFIG')
    }})
Exemplo n.º 3
0
    def test_callable_replaced_correctly(self):
        original = {'handlers': {
            'one': {'()': None, 'param': 'Something_else'}
        }}
        result = replace_empty_handler_callables(original, self.do_nothing)
        self.assertEqual(
            list(dict_diff(result, original)),
            ['handlers'],
        )

        original = original['handlers']
        result = result['handlers']
        self.assertEqual(
            list(dict_diff(result, original)),
            ['one'],
        )

        original = original['one']
        result = result['one']
        self.assertEqual(
            list(dict_diff(result, original)),
            ['()'],
        )
        self.assertEqual(result['()'], self.do_nothing)
Exemplo n.º 4
0
 def assert_untouched(self, data):
     self.assertEqual(
         data,
         replace_empty_handler_callables(data, self.do_nothing)
     )