| 1 | # -*- coding: utf-8 -*- |
| 2 | # |
| 3 | # SPDX-License-Identifier: LGPL-2.1-only |
| 4 | # |
| 5 | # Copyright (C) 2015 Philippe Proulx <pproulx@efficios.com> |
| 6 | # Copyright (C) 2014 David Goulet <dgoulet@efficios.com> |
| 7 | |
| 8 | from __future__ import unicode_literals |
| 9 | import logging |
| 10 | import ctypes |
| 11 | |
| 12 | from .version import __soname_major__ |
| 13 | |
| 14 | class _Handler(logging.Handler): |
| 15 | _LIB_NAME = 'liblttng-ust-python-agent.so.' + __soname_major__ |
| 16 | |
| 17 | def __init__(self): |
| 18 | super(self.__class__, self).__init__(level=logging.NOTSET) |
| 19 | self.setFormatter(logging.Formatter('%(asctime)s')) |
| 20 | |
| 21 | # will raise if library is not found: caller should catch |
| 22 | self.agent_lib = ctypes.cdll.LoadLibrary(_Handler._LIB_NAME) |
| 23 | |
| 24 | def emit(self, record): |
| 25 | self.agent_lib.py_tracepoint(self.format(record).encode(), |
| 26 | record.getMessage().encode(), |
| 27 | record.name.encode(), |
| 28 | record.funcName.encode(), |
| 29 | record.lineno, record.levelno, |
| 30 | record.thread, |
| 31 | record.threadName.encode()) |