| 1 | # -*- coding: utf-8 -*- |
| 2 | # |
| 3 | # Copyright (C) 2015 - Philippe Proulx <pproulx@efficios.com> |
| 4 | # Copyright (C) 2014 - David Goulet <dgoulet@efficios.com> |
| 5 | # |
| 6 | # This library is free software; you can redistribute it and/or modify it under |
| 7 | # the terms of the GNU Lesser General Public License as published by the Free |
| 8 | # Software Foundation; version 2.1 of the License. |
| 9 | # |
| 10 | # This library is distributed in the hope that it will be useful, but WITHOUT |
| 11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 12 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 13 | # details. |
| 14 | # |
| 15 | # You should have received a copy of the GNU Lesser General Public License |
| 16 | # along with this library; if not, write to the Free Software Foundation, Inc., |
| 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | |
| 19 | from __future__ import unicode_literals |
| 20 | import logging |
| 21 | import ctypes |
| 22 | |
| 23 | |
| 24 | class _Handler(logging.Handler): |
| 25 | _LIB_NAME = 'liblttng-ust-python-agent.so' |
| 26 | |
| 27 | def __init__(self): |
| 28 | super(self.__class__, self).__init__(level=logging.NOTSET) |
| 29 | self.setFormatter(logging.Formatter('%(asctime)s')) |
| 30 | |
| 31 | # will raise if library is not found: caller should catch |
| 32 | self.agent_lib = ctypes.cdll.LoadLibrary(_Handler._LIB_NAME) |
| 33 | |
| 34 | def emit(self, record): |
| 35 | self.agent_lib.py_tracepoint(self.format(record).encode(), |
| 36 | record.getMessage().encode(), |
| 37 | record.name.encode(), |
| 38 | record.funcName.encode(), |
| 39 | record.lineno, record.levelno, |
| 40 | record.thread, |
| 41 | record.threadName.encode()) |