Skip to content

Commit

Permalink
chore: remove logging improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Sébastian Clerson committed Jan 10, 2023
1 parent fb63896 commit d62c63d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
10 changes: 0 additions & 10 deletions docs/whats_new/version_ongoing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,3 @@ Internal creation of proxy auxiliaries
It is no longer necessary to manually defined a ``ProxyAuxiliary`` with
``CCProxy``s yourself. If you simply pass the communication channel to
each auxiliary that has to share it, ``pykiso`` will do the rest for you.


Remove redundancy of activate_log configuration parameter
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In order to activate external loggers, it was previously necessary to
specify their names for each defined auxiliary.

This is no longer the case and specifying them in only one auxiliary
will be enough for the loggers to stay enabled.
19 changes: 5 additions & 14 deletions src/pykiso/logging_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@ class LogOptions(NamedTuple):
verbose: bool


# used to store the selected logging options
# use to store the selected logging options
log_options: Optional[LogOptions] = None

# used to store the loggers that shouldn't be silenced
active_loggers = set()


def get_logging_options() -> LogOptions:
"""Simply return the previous logging options.
Expand Down Expand Up @@ -167,7 +164,7 @@ def add_logging_level(level_name: str, level_num: int):
Example
-------
>>> add_logging_level('KISO', logging.DEBUG - 5)
>>> addLoggingLevel('TRACE', logging.DEBUG - 5)
>>> logging.getLogger(__name__).setLevel("KISO")
>>> logging.getLogger(__name__).trace('that worked')
>>> logging.kiso('so did this')
Expand Down Expand Up @@ -198,17 +195,15 @@ def initialize_loggers(loggers: Optional[List[str]]) -> None:
:param loggers: list of logger names to keep activated
"""
global active_loggers
if loggers is None:
loggers = list()
# keyword 'all' should keep all loggers to the configured level
if "all" in loggers:
logging.internal_warning(
"All loggers are activated, this could lead to performance issues."
)
active_loggers |= set(logging.root.manager.loggerDict.keys())
return
# keep package and auxiliary loggers, store all the others to deactivate them
# keep package and auxiliary loggers
relevant_loggers = {
name: logger
for name, logger in logging.root.manager.loggerDict.items()
Expand All @@ -223,11 +218,7 @@ def initialize_loggers(loggers: Optional[List[str]]) -> None:
if (logger.startswith(parent) or parent.startswith(logger))
]
loggers += childs

# store previous loggers to keep active (union of previous and current loggers)
active_loggers |= set(loggers)

# set the loggers that are not part of active_loggers to level WARNING
loggers_to_deactivate = set(relevant_loggers) - set(active_loggers)
# keep original level for specified loggers
loggers_to_deactivate = set(relevant_loggers) - set(loggers)
for logger_name in loggers_to_deactivate:
logging.getLogger(logger_name).setLevel(logging.WARNING)

0 comments on commit d62c63d

Please sign in to comment.