Commit | Line | Data |
---|---|---|
de4dee04 PP |
1 | # -*- coding: utf-8 -*- |
2 | # | |
c0c0989a | 3 | # SPDX-License-Identifier: LGPL-2.1-only |
de4dee04 | 4 | # |
c0c0989a MJ |
5 | # Copyright (C) 2015 Philippe Proulx <pproulx@efficios.com> |
6 | # Copyright (C) 2014 David Goulet <dgoulet@efficios.com> | |
de4dee04 PP |
7 | |
8 | from __future__ import unicode_literals | |
9 | import logging | |
10 | import ctypes | |
11 | ||
50d2bb48 | 12 | from .version import __soname_major__ |
de4dee04 PP |
13 | |
14 | class _Handler(logging.Handler): | |
50d2bb48 | 15 | _LIB_NAME = 'liblttng-ust-python-agent.so.' + __soname_major__ |
de4dee04 PP |
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()) |