Skip to content

Commit

Permalink
[resotolib][chore] debug -> trace (#1660)
Browse files Browse the repository at this point in the history
* [resotolib][chore] debug -> trace
  • Loading branch information
lloesche committed Jun 13, 2023
1 parent fd17ee3 commit d4f11c4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion resotolib/resotolib/json.py
Expand Up @@ -73,7 +73,7 @@ def register_json(
:param to_json_fn: the function to convert the class to json
:param from_json_fn: the function to convert json to the class
"""
log.debug("Register json structure hooks for class %s", cls.__name__)
log.trace("Register json structure hooks for class %s", cls.__name__)
if from_json_fn is not None:
__converter.register_structure_hook(cls, lambda obj, _: from_json_fn(obj)) # type: ignore
if to_json_fn is not None:
Expand Down
39 changes: 37 additions & 2 deletions resotolib/resotolib/logger.py
Expand Up @@ -4,7 +4,20 @@
import sys
import os
import logging
from logging import basicConfig, getLogger, DEBUG, INFO, WARNING, ERROR, CRITICAL, StreamHandler, Formatter, LogRecord
from logging import (
basicConfig,
getLogger,
setLoggerClass,
DEBUG,
INFO,
WARNING,
ERROR,
CRITICAL,
StreamHandler,
Formatter,
LogRecord,
Logger,
)


from resotolib.args import ArgumentParser
Expand Down Expand Up @@ -193,11 +206,33 @@ def log_to_root(message: str, *args: Any, **kwargs: Any) -> None:
setattr(logging, method_name, log_to_root)


class ResotoLogger(Logger):
def debug2(self, msg: str, *args: Any, **kwargs: Any) -> None:
...

def debug3(self, msg: str, *args: Any, **kwargs: Any) -> None:
...

def debug4(self, msg: str, *args: Any, **kwargs: Any) -> None:
...

def debug5(self, msg: str, *args: Any, **kwargs: Any) -> None:
...

def trace(self, msg: str, *args: Any, **kwargs: Any) -> None:
...


def get_resoto_logger(name: Optional[str] = None) -> ResotoLogger:
return getLogger(name) # type: ignore


add_logging_level("DEBUG2", DEBUG2)
add_logging_level("DEBUG3", DEBUG3)
add_logging_level("DEBUG4", DEBUG4)
add_logging_level("DEBUG5", DEBUG5)
add_logging_level("TRACE", TRACE)

setLoggerClass(ResotoLogger)
setup_logger("resoto", force=False)
log = getLogger("resoto")
log = get_resoto_logger("resoto")

0 comments on commit d4f11c4

Please sign in to comment.