Beispiel #1
0
def test_iterations():
    logger = autodiscover(level=logging.WARN, refresh=True)

    iterations = 100000

    start = measure_clock()
    for i in range(0, iterations):
        logger.info("hello world", extra={"i": i})
    delta_sec = measure_clock() - start
    delta_ms = delta_sec * 1000

    print("time for {:,} iterations: {:,.2f} ms".format(iterations, delta_ms))
    print("time for one log event: {:.2f} ns".format(1000000 * delta_ms /
                                                     iterations))
    print("{:,.0f} logs / sec".format(iterations / delta_sec))

    assert delta_sec < 1
Beispiel #2
0
def test_reserved_key():
    logger = autodiscover(refresh=True)
    assert logger is not None
    logger.info("test_reserved_key", extra={"level": "bobo"})
Beispiel #3
0
def test_flush():
    logger = autodiscover(refresh=True, config={"context": {"xyz": "abc"}})
    assert logger is not None
    logger.info("test_flush", extra={"foo": {"bar": "baz"}})
    flush()
Beispiel #4
0
def test_context_from_env():
    os.environ["LOGTRON_CONTEXT_FOO_BAR"] = "123"
    logger = autodiscover(refresh=True)
    os.environ.pop("LOGTRON_CONTEXT_FOO_BAR")
    logger.info("test_context_from_env", extra={"foo": {"baz": "bar"}})
    assert logger is not None
Beispiel #5
0
def test_config_context():
    logger = autodiscover(refresh=True, config={"context": {"foo": "bar"}})
    assert logger is not None
    logger.info("test_config_context")
Beispiel #6
0
def test_autodiscover():
    logger = autodiscover(refresh=True)
    logger.info("test_autodiscover")
Beispiel #7
0
def test_discover_context():
    logger = autodiscover(refresh=True, discover_context=lambda: {})
    assert logger is not None
Beispiel #8
0
def test_handler_config_full_name():
    logger = autodiscover(refresh=True, config={"logtron.handlers.ConsoleHandler": {}})
    assert logger is not None
Beispiel #9
0
def test_unsupported_env_var():
    os.environ["LOGTRON_CONSOLEHANDLER_FOO"] = "1,2,3.4,bar"
    logger = autodiscover(refresh=True)
    os.environ.pop("LOGTRON_CONSOLEHANDLER_FOO")
    logger.info("test_unsupported_env_var")
Beispiel #10
0
def test_handler_config_short_name():
    logger = autodiscover(refresh=True, config={"ConsoleHandler": {}})
    assert logger is not None
Beispiel #11
0
def test_exception():
    logger = autodiscover(refresh=True)
    try:
        raise Exception("test exception")
    except Exception:
        logger.info("test_exception", extra={"foo": 123}, exc_info=True)
Beispiel #12
0
def test_extra():
    logger = autodiscover(refresh=True)
    logger.info("test_extra", extra={"foo": 123, "bar": "baz", "d": {"e": 5}})
Beispiel #13
0
def test_autodiscover_named():
    logger = autodiscover("name1", refresh=True)
    logger.info("test_autodiscover_named")
Beispiel #14
0
def test_autodiscover_existing():
    logger = autodiscover(refresh=True)
    logger.info("test_autodiscover_existing1")
    logger = autodiscover()
    logger.info("test_autodiscover_existing2")