Ejemplo n.º 1
0
def robotlogger():
    logger = logging.getLogger("robot_events")
    logger.setLevel(logging.DEBUG)
    rmq_handler = logstash.AMQPLogstashHandler(host='localhost',
                                               version=1,
                                               durable=True)
    rmq_handler.setFormatter(jsonlogger.JsonFormatter())
    logger.addHandler(rmq_handler)
    return logger
Ejemplo n.º 2
0
    def _configure_logging(self, config):
        '''
        Configure the Logstash log handler to the specified level
        '''
        logstash_host = config.get('logstash.host')
        logstash_port = int(config.get('logstash.port') or 5959)
        logstash_kind = config.get('logstash.kind')
        logstash_kind = logstash_kind or ''
        logstash_kind = logstash_kind.lower()
        if logstash_kind == 'tcp':
            handler = logstash.TCPLogstashHandler(
                logstash_host, logstash_port, version=1
            )
        elif logstash_kind == 'udp':
            handler = logstash.LogstashHandler(
                logstash_host, logstash_port, version=1
            )
        elif logstash_kind == 'ampq':
            handler = logstash.AMQPLogstashHandler(
                host=logstash_host,  version=1
            )
        else:
            log.warning('Unknown logstash kind specified (%s)',
                        config.get('logstash.kind'))
            return

        handler.setLevel(logging.NOTSET)
        handler.formatter.host = config.get('ckan.site_url')

        logging.info('Setting up Logstash logger')

        loggers = ['', 'ckan', 'ckanext', 'logstash.errors', __name__]
        logstash_log_level = config.get('logstash.log_level', logging.DEBUG)
        for name in loggers:
            logger = logging.getLogger(name)
            logger.addHandler(handler)
            logger.setLevel(logstash_log_level)

        log.debug('Set-up Logstash logger with level %s', logstash_log_level)
Ejemplo n.º 3
0
    def _setup_handler(self):
        logstash_handler = None

        if self.handler == 'AMQP':
            logstash_handler = logstash.AMQPLogstashHandler(
                version=1,
                host=self.host,
                durable=self.durable,
                username=self.username,
                password=self.password,
                exchange=self.exchange)
        elif self.handler == 'TCP':
            logstash_handler = logstash.TCPLogstashHandler(self.host,
                                                           self.port,
                                                           version=1)
        elif self.handler == "UDP":
            logstash_handler = logstash.UDPLogstashHandler(self.host,
                                                           self.port,
                                                           version=1)

        self.attack_logger = logging.getLogger('python-logstash-handler')
        self.attack_logger.setLevel(logging.INFO)
        self.attack_logger.addHandler(logstash_handler)
Ejemplo n.º 4
0
# AMQP parameters
host = '127.0.0.1'
username = '******'
password = '******'
exchange = 'logstash'

# get a logger and set logging level
test_logger = logging.getLogger('python-logstash-logger')
test_logger.setLevel(logging.INFO)

# add the handler
test_logger.addHandler(
    logstash.AMQPLogstashHandler(version=1,
                                 host=host,
                                 durable=True,
                                 username=username,
                                 password=password,
                                 exchange=exchange))

# log
test_logger.error('python-logstash: test logstash error message.')
test_logger.info('python-logstash: test logstash info message.')
test_logger.warning('python-logstash: test logstash warning message.')

try:
    1 / 0
except:
    test_logger.exception(
        'python-logstash: test logstash exception with stack trace')