ATLAS Offline Software
Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
RootUtils::PyLogger Class Reference

A concrete implementation of ILogger that calls back to Python. More...

#include <PyLogger.h>

Inheritance diagram for RootUtils::PyLogger:
Collaboration diagram for RootUtils::PyLogger:

Public Member Functions

 PyLogger (PyObject *debugfn, PyObject *errorfn)
 Constructor. More...
 
 ~PyLogger ()
 Destructor. More...
 
virtual void debug (const char *msg)
 Log a debugging message. More...
 
virtual void error (const char *msg)
 Log an error message. More...
 

Static Private Member Functions

static void call (PyObject *fn, const char *msg)
 Common code to call Python callback. More...
 

Private Attributes

PyObjectm_debugfn
 The debug message function. More...
 
PyObjectm_errorfn
 The error message function. More...
 

Detailed Description

A concrete implementation of ILogger that calls back to Python.

Definition at line 35 of file PyLogger.h.

Constructor & Destructor Documentation

◆ PyLogger()

RootUtils::PyLogger::PyLogger ( PyObject debugfn,
PyObject errorfn 
)

Constructor.

Parameters
debugfnFunction to call for a debug message.
errorfnFunction to call for an error message.

The functions should take a single string parameter. Passing None means to skip the call.

Definition at line 27 of file PyLogger.cxx.

28  : m_debugfn (debugfn),
29  m_errorfn (errorfn)
30 {
31  Py_INCREF (debugfn);
32  Py_INCREF (errorfn);
33 }

◆ ~PyLogger()

RootUtils::PyLogger::~PyLogger ( )

Destructor.

Definition at line 39 of file PyLogger.cxx.

40 {
41  Py_DECREF (m_debugfn);
42  Py_DECREF (m_errorfn);
43 }

Member Function Documentation

◆ call()

void RootUtils::PyLogger::call ( PyObject fn,
const char *  msg 
)
staticprivate

Common code to call Python callback.

Parameters
fnThe Python function to call (or None).
msgThe string to pass to it.

May raise an exception, if the Python code does.

Definition at line 73 of file PyLogger.cxx.

74 {
75  if (!fn || fn == Py_None)
76  return;
77 
78  PyObject* res = PyObject_CallFunction (fn, (char*)"s", msg);
79  if (res == 0)
80  throw RootUtils::PyException();
81  Py_DECREF (res);
82 }

◆ debug()

void RootUtils::PyLogger::debug ( const char *  msg)
virtual

Log a debugging message.

Parameters
msgThe message to log.

Implements RootUtils::ILogger.

Definition at line 50 of file PyLogger.cxx.

51 {
52  call (m_debugfn, msg);
53 }

◆ error()

void RootUtils::PyLogger::error ( const char *  msg)
virtual

Log an error message.

Parameters
msgThe message to log.

Implements RootUtils::ILogger.

Definition at line 60 of file PyLogger.cxx.

61 {
62  call (m_errorfn, msg);
63 }

Member Data Documentation

◆ m_debugfn

PyObject* RootUtils::PyLogger::m_debugfn
private

The debug message function.

Definition at line 80 of file PyLogger.h.

◆ m_errorfn

PyObject* RootUtils::PyLogger::m_errorfn
private

The error message function.

Definition at line 83 of file PyLogger.h.


The documentation for this class was generated from the following files:
RootUtils::PyException
CPyCppyy::PyException PyException
Definition: Utility.h:24
RootUtils::PyLogger::m_debugfn
PyObject * m_debugfn
The debug message function.
Definition: PyLogger.h:80
RootUtils::PyLogger::m_errorfn
PyObject * m_errorfn
The error message function.
Definition: PyLogger.h:83
python.getCurrentFolderTag.fn
fn
Definition: getCurrentFolderTag.py:65
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
RootUtils::PyLogger::call
static void call(PyObject *fn, const char *msg)
Common code to call Python callback.
Definition: PyLogger.cxx:73
PyObject
_object PyObject
Definition: IPyComponent.h:26
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7