Commit 277a8364 authored by Piergiorgio Pancino's avatar Piergiorgio Pancino Committed by Matias Guijarro

add debugon and debugoff, removed unused functions

parent a7a82607
......@@ -71,7 +71,7 @@ def improve_logger(logger_instance):
def debugoff(self):
"""Activates debug on the device"""
self.setLevel(logging.WARNING)
self.setLevel(logging.NOTSET)
def debug_data(self, msg: str, data) -> None:
"""
......@@ -282,20 +282,8 @@ class Log:
Args:
glob: glob style pattern matching
Hints on glob: pattern matching normally used by shells
common operators are * for any number of characters
and ? for one character of any type
Returns:
None
Examples:
>>> log.debugon('*motorsrv')
Set logger [motorsrv] to DEBUG level
Set logger [motorsrv.Connection] to DEBUG level
>>> log.debugon('*rob?')
Set logger [session.device.controller.roby] to DEBUG level
Set logger [session.device.controller.robz] to DEBUG level
"""
strname = self._check_log_name(glob)
loggers = self._find_bliss_logger_by_name(strname)
......@@ -320,10 +308,6 @@ class Log:
Args:
glob: glob style pattern matching
Hints on glob: pattern matching normally used by shells
common operators are * for any number of characters
and ? for one character of any type
"""
strname = self._check_log_name(glob)
loggers = self._find_bliss_logger_by_name(strname)
......
......@@ -9,7 +9,7 @@
Standard bliss macros (:func:`~bliss.common.standard.wa`, \
:func:`~bliss.common.standard.mv`, etc)
"""
from bliss.common import scans
from bliss.common import scans, session
from bliss.common.scans import *
from bliss.common.plot import plot
from bliss.common.soft_axis import SoftAxis
......@@ -18,6 +18,7 @@ from bliss.common.cleanup import cleanup, error_cleanup
from bliss.common import logtools
from bliss.common.logtools import *
from bliss.common.utils import get_counters_iter
from bliss.common import session
import sys
......@@ -33,7 +34,8 @@ __all__ = (
"umvr",
"move",
"prdef",
"set_log_level",
"debugon",
"debugoff",
"sync",
]
+ scans.__all__
......@@ -79,6 +81,58 @@ _FLOAT_FORMAT = ".05f"
_log = logging.getLogger("bliss.standard")
def debugon(glob_logger_pattern_or_obj):
"""
Activates debug-level logging for a specifig logger or an object
Args:
glob_logger_pattern_or_obj: glob style pattern matching for logger name, or instance
Hints on glob: pattern matching normally used by shells
common operators are * for any number of characters
and ? for one character of any type
Returns:
None
Examples:
>>> log.debugon('*motorsrv')
Set logger [motorsrv] to DEBUG level
Set logger [motorsrv.Connection] to DEBUG level
>>> log.debugon('*rob?')
Set logger [session.device.controller.roby] to DEBUG level
Set logger [session.device.controller.robz] to DEBUG level
"""
if isinstance(glob_logger_pattern_or_obj, str):
glob_logger_pattern = glob_logger_pattern_or_obj
return session.get_current().log.debugon(glob_logger_pattern)
else:
obj = glob_logger_pattern_or_obj
return obj._logger.debugon()
def debugoff(glob_logger_pattern_or_obj):
"""
Desactivates debug-level logging for a specifig logger or an object
Args:
glob_logger_pattern_or_obj: glob style pattern matching for logger name, or instance
Hints on glob: pattern matching normally used by shells
common operators are * for any number of characters
and ? for one character of any type
Returns:
None
"""
if isinstance(glob_logger_pattern_or_obj, str):
glob_logger_pattern = glob_logger_pattern_or_obj
return session.get_current().log.debugoff(glob_logger_pattern)
else:
obj = glob_logger_pattern_or_obj
return obj._logger.debugoff()
def _tabulate(data, **kwargs):
kwargs.setdefault("headers", "firstrow")
kwargs.setdefault("floatfmt", _FLOAT_FORMAT)
......@@ -458,28 +512,6 @@ def prdef(obj_or_name):
print(__pyhighlight("".join(lines)))
def _check_log_level(level):
if isinstance(level, int):
rv = level
else:
rv = getattr(logging, level.upper())
return rv
def set_log_level(level=logging.root.level):
"""
Adjusts the log level
Without arguments, resets the level back to the one setup at
beginning of the session.
Args:
level (int or str): new log level can be constant (ex: logging.INFO) or
case insensitive equivalent string (ex: 'Info')
"""
logging.root.setLevel(_check_log_level(level))
def cntdict():
"""
Return a dict of counters
......
......@@ -10,6 +10,7 @@ import logging
import re
from bliss.common.logtools import map_update_loggers, Log, LogMixin
from bliss.common.standard import debugon, debugoff
from bliss.common.mapping import Map
from bliss.common import session
import bliss
......@@ -119,7 +120,7 @@ def test_m0_logger_debugoff(params, caplog):
m0 = beacon.get("m0") # creating a device
m0._logger.debugoff()
assert m0._logger.level == logging.WARNING
assert m0._logger.level == logging.NOTSET
m0._logger.debug(msg)
assert msg not in caplog.text
......@@ -208,3 +209,24 @@ def test_LogMixin(params, caplog):
assert expected in caplog.text
assert hasattr(mc._logger, "debug_data")
def test_standard_debugon_debugoff(session):
roby = session.config.get("roby")
debugon(roby)
assert roby._logger.level == logging.DEBUG
debugoff(roby)
assert roby._logger.level == logging.NOTSET
debugon("*roby")
assert roby._logger.level == logging.DEBUG
debugoff("*roby")
assert roby._logger.level == logging.NOTSET
assert roby._logger.getEffectiveLevel() == logging.WARNING
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment