Skip to content

Expose Logger's `incrDebug` in the Python bindings

Daniel Joseph Antrim requested to merge dantrim_py_incrdebug into devel

What

This MR adds a new function to the top-level labRemote module: incrDebug. This function calls the incrDebug method of labRemote's underlying logging class. This allows users of the python bindings to set the underlying logger's verbosity to DEBUG. By default the underlying logger's verbosity is INFO and so none of the underlying DEBUG messages from labRemote libraries are reported and this adds a way to at least boost it up to the DEBUG levels.

Usage

With this MR, users can then do the following to activate the DEBUG messages from the underlying labRemote libraries:

import labRemote
...
labRemote.incrDebug()

Notes

There is not an incrLogLevel function that simply steps up the log level nor is there a setLogLevel function. labRemote's logger implementation is such that the level is set during the logger macro call, which is not available to users of the Python bindings.

Notes, 2: Leveraging Python's logging module

@gstark has a nice idea of perhaps implementing a logging module wrapper that streams the messages to labRemote's underlying logger, something like:

import logging
from . import Logger

class LabRemoteHandler(logging.Handler):

  def emit(self, record):
    if record.level > Logger.logIt.loglevel: Logger.logIt.logIt(record.msg)

Which would allow users who may already be using Python's logging module to register it (e.g. logging.addHandler(LabRemoteHandler())). Adding functions for setting the log levels would then be correspondingly wrapped.

Edited by Daniel Joseph Antrim

Merge request reports