How to use the loguru.logger.add function in loguru

To help you get started, we’ve selected a few loguru examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Delgan / loguru / tests / test_contextualize.py View on Github external
def test_contextualize(writer):
    logger.add(writer, format="{message} {extra[foo]} {extra[baz]}")

    with logger.contextualize(foo="bar", baz=123):
        logger.info("Contextualized")

    assert writer.read() == "Contextualized bar 123\n"
github Delgan / loguru / tests / test_configure.py View on Github external
def test_configure_after_bind(writer):
    logger_a = logger.bind(a="A")
    logger_b = logger.bind(b="B")

    logger.configure(extra={"a": "default_a", "b": "default_b"})
    logger.add(writer, format="{extra[a]} {extra[b]} {message}")

    logger.debug("init")

    logger_a.debug("aaa")
    logger_b.debug("bbb")

    assert writer.read() == ("default_a default_b init\n" "A default_b aaa\n" "default_a B bbb\n")
github Delgan / loguru / tests / exceptions / source / backtrace / raising_recursion.py View on Github external
import sys
from loguru import logger

logger.remove()
logger.add(sys.stderr, format="", colorize=False, backtrace=True, diagnose=False)


@logger.catch
def a(n):
    if n:
        a(n - 1)
    n / 0


def b(n):
    with logger.catch():
        if n:
            b(n - 1)
        n / 0
github Delgan / loguru / tests / test_add_options.py View on Github external
def test_format(message, format, expected, writer):
    logger.add(writer, format=format)
    logger.debug(message)
    assert writer.read() == expected
github Delgan / loguru / tests / exceptions / source / backtrace / nested.py View on Github external
import sys
from loguru import logger

logger.remove()
logger.add(sys.stderr, format="", colorize=False, backtrace=True, diagnose=False)


def a(x):
    @logger.catch
    def nested(i):
        1 / i

    nested(x)


a(0)


def b(x):
    def nested(i):
        1 / i
github Delgan / loguru / tests / test_multiprocessing.py View on Github external
def test_not_picklable_sinks_inheritance(capsys, tmpdir):
    filepath = tmpdir.join("test.log")
    stream = sys.stderr
    output = []

    logger.add(str(filepath), format="{message}", enqueue=True, catch=False)
    logger.add(stream, format="{message}", enqueue=True, catch=False)
    logger.add(lambda m: output.append(m), format="{message}", enqueue=True, catch=False)

    process = multiprocessing.Process(target=subworker_inheritance)
    process.start()
    process.join()

    assert process.exitcode == 0

    logger.info("Main")
    logger.remove()

    out, err = capsys.readouterr()

    assert filepath.read() == "Child\nMain\n"
    assert out == ""
github Delgan / loguru / tests / test_catch_wrapper.py View on Github external
def test_exception_not_raising(writer, exception):
    logger.add(writer)

    @logger.catch(exception)
    def a():
        1 / 0

    a()
    assert writer.read().endswith("ZeroDivisionError: division by zero\n")
github Delgan / loguru / tests / test_repr.py View on Github external
def test_handler_removed():
    i = logger.add(sys.__stdout__)
    logger.add(sys.__stderr__)
    logger.remove(i)
    assert repr(logger) == ")]>"
github httprunner / httprunner / httprunner / v3 / api.py View on Github external
save_tests (bool): save loaded/parsed tests to JSON file.
            log_level (str): logging level.
            log_file (str): log file path.

        """
        self.exception_stage = "initialize HttpRunner()"
        kwargs = {
            "failfast": failfast,
            "resultclass": report.HtmlTestResult
        }

        logger.remove()
        log_level = log_level.upper()
        logger.add(sys.stdout, level=log_level)
        if log_file:
            logger.add(log_file, level=log_level)

        self.unittest_runner = unittest.TextTestRunner(**kwargs)
        self.test_loader = unittest.TestLoader()
        self.save_tests = save_tests
        self._summary = None
        self.test_path = None
github SubstraFoundation / distributed-learning-contributivity / main.py View on Github external
def init_logger(args):
    logger.remove()

    # Forward logging to standard output
    if args.verbose:
        logger.add(sys.__stdout__, level="DEBUG")
    else:
        logger.add(sys.__stdout__, level="INFO")

    stream = StreamToLogger()

    info_logger_id = logger.add(constants.INFO_LOGGING_FILE_NAME, level="INFO")
    info_debug_id = logger.add(constants.DEBUG_LOGGING_FILE_NAME, level="DEBUG")
    return stream, info_logger_id, info_debug_id