Beispiel #1
0
class LogdLogHandler(logging.Handler):
    def __init__(self, level=logging.NOTSET, address=None, ident=None):
        super(LogdLogHandler, self).__init__(level)
        self.address = address or 'unix:///var/run/logd.sock'
        self.ident = ident or os.path.basename(sys.executable)
        self.client = Client()
        self.client.connect(self.address)

    def emit(self, record):
        try:
            if not self.client.connected:
                self.client.connect(self.address)

            item = {
                'timestamp': datetime.utcfromtimestamp(record.created),
                'priority': PRIORITY_MAP.get(record.levelno, 'INFO'),
                'message': record.getMessage(),
                'identifier': self.ident,
                'thread': record.threadName,
                'tid': record.thread,
                'module_name': record.name,
                'source_language': 'python',
                'source_file': record.pathname,
                'source_line': record.lineno,
            }

            if record.exc_info:
                item['exception'] = ''.join(
                    traceback.format_exception(*record.exc_info))

            self.client.call_async('logd.logging.push', None, item)
        except:
            self.handleError(record)

    def close(self):
        super(LogdLogHandler, self).close()
        self.client.disconnect()
Beispiel #2
0
class LogdLogHandler(logging.Handler):
    def __init__(self, level=logging.NOTSET, address=None, ident=None):
        super(LogdLogHandler, self).__init__(level)
        self.address = address or 'unix:///var/run/logd.sock'
        self.ident = ident or os.path.basename(sys.executable)
        self.client = Client()
        self.client.connect(self.address)

    def emit(self, record):
        try:
            if not self.client.connected:
                self.client.connect(self.address)

            item = {
                'timestamp': datetime.utcfromtimestamp(record.created),
                'priority': PRIORITY_MAP.get(record.levelno, 'INFO'),
                'message': record.getMessage(),
                'identifier': self.ident,
                'thread': record.threadName,
                'tid': record.thread,
                'module_name': record.name,
                'source_language': 'python',
                'source_file': record.pathname,
                'source_line': record.lineno,
            }

            if record.exc_info:
                item['exception'] = ''.join(traceback.format_exception(*record.exc_info))

            self.client.call_async('logd.logging.push', None, item)
        except:
            self.handleError(record)

    def close(self):
        super(LogdLogHandler, self).close()
        self.client.disconnect()