File: loguru.py

package info (click to toggle)
python-utils 3.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 396 kB
  • sloc: python: 2,135; makefile: 19; sh: 5
file content (51 lines) | stat: -rw-r--r-- 1,357 bytes parent folder | download
1
2
3
4
5
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
This module provides a `Logurud` class that integrates the `loguru` logger
with the base logging functionality defined in `logger_module.LoggerBase`.

Classes:
    Logurud: A class that extends `LoggerBase` and uses `loguru` for logging.

Usage example:
    >>> from python_utils.loguru import Logurud
    >>> class MyClass(Logurud):
    ...     def __init__(self):
    ...         Logurud.__init__(self)
    >>> my_class = MyClass()
    >>> my_class.logger.info('This is an info message')
"""

from __future__ import annotations

import typing

import loguru

from . import logger as logger_module

__all__ = ['Logurud']


class Logurud(logger_module.LoggerBase):
    """
    A class that extends `LoggerBase` and uses `loguru` for logging.

    Attributes:
        logger (loguru.Logger): The `loguru` logger instance.
    """

    logger: loguru.Logger

    def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> Logurud:
        """
        Creates a new instance of `Logurud` and initializes the `loguru`
        logger.

        Args:
            *args (typing.Any): Variable length argument list.
            **kwargs (typing.Any): Arbitrary keyword arguments.

        Returns:
            Logurud: A new instance of `Logurud`.
        """
        cls.logger: loguru.Logger = loguru.logger.opt(depth=1)
        return super().__new__(cls)