Skip to content

richstate

Class info

Classes

Name Children Inherits
RichState
mkdocs_mknodes.cli.richstate
Maintain logging level.

    🛈 DocStrings

    RichState

    Maintain logging level.

    Source code in mkdocs_mknodes/cli/richstate.py
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    class RichState:
        """Maintain logging level."""
    
        LOG_NAME = "mkdocs"
    
        def __init__(self, log_name: str | None = None, level: int = logging.INFO):
            """Constructor.
    
            Args:
                log_name: Logger name
                level: Logging level
            """
            from rich.logging import RichHandler
    
            self.logger = logging.getLogger(log_name or self.LOG_NAME)
            # Don't restrict level on logger; use handler
            self.logger.setLevel(1)
            self.logger.propagate = False
            self.stream = RichHandler(
                level,
                markup=False,
                rich_tracebacks=True,
                omit_repeated_times=False,
            )
            self.stream.name = "MkNodesStreamHandler"
            self.logger.addHandler(self.stream)
    
        def __del__(self):
            self.logger.removeHandler(self.stream)
    

    __init__

    __init__(log_name: str | None = None, level: int = INFO)
    

    Constructor.

    Parameters:

    Name Type Description Default
    log_name str | None

    Logger name

    None
    level int

    Logging level

    INFO
    Source code in mkdocs_mknodes/cli/richstate.py
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    def __init__(self, log_name: str | None = None, level: int = logging.INFO):
        """Constructor.
    
        Args:
            log_name: Logger name
            level: Logging level
        """
        from rich.logging import RichHandler
    
        self.logger = logging.getLogger(log_name or self.LOG_NAME)
        # Don't restrict level on logger; use handler
        self.logger.setLevel(1)
        self.logger.propagate = False
        self.stream = RichHandler(
            level,
            markup=False,
            rich_tracebacks=True,
            omit_repeated_times=False,
        )
        self.stream.name = "MkNodesStreamHandler"
        self.logger.addHandler(self.stream)