Esempio n. 1
0
def test_dual(capsys):
    clog = DLogger("main", filename="app_simple.log", log_fmt=FORMATS[Fmt.LEVEL_MSG],
                   cout_enabled=True, cout_level=logging.INFO)

    clog.debug('debug message')

    clog.info('info message')
    out, err = capsys.readouterr()
    assert err == "info message\n"

    clog.warning('warn message')
    _, err = capsys.readouterr()
    assert err == "warn message\n"

    clog.error('error message')
    _, err = capsys.readouterr()
    assert err == "error message\n"

    clog.critical('critical message')
    _, err = capsys.readouterr()
    assert err == "critical message\n"

    if os.getcwd().endswith('tests'):
        assert compare_files(path.join("test_data", "app_simple.log"), path.join("logs", "app_simple.log"))
    else:
        assert compare_files(path.join("tests", "test_data", "app_simple.log"), path.join("logs", "app_simple.log"))
Esempio n. 2
0
def test_info_warn():
    clog1 = DLogger("system", cout_fmt=FORMATS[Fmt.FNAME_LEVEL_MSG], log_level=logging.INFO, cout_level=logging.WARN, cout_enabled=True)
    display_details(clog1)
    clog1.debug('1 - msg debug')
    clog1.info('2 - msg info')
    clog1.warning('3 - msg warn')
    clog1.error('4 - msg error')
    clog1.critical('5 - msg critical')
    expect(no_items_in_log=4, no_items_in_cout=3)
Esempio n. 3
0
def test_propagate_root_stdout():  # error message goes top log file and screen
    print("test_propagate_root_stdout()")
    clog_ = DLogger("root", filename="app_root.log", log_enabled=True)  # root logger if name = ""
    clog0 = DLogger("", filename="app_root.log", log_enabled=True)  # root logger if name = ""
    clog1 = DLogger("main", filename="app_main.log", log_enabled=True, propagate=True)
    clog2 = DLogger("main.sub", filename="sub.log", log_enabled=True, propagate=False)
    clog0.info("clog0 - msg to root")
    clog1.info("clog1 - msg to main")
    clog2.info("clog2 - msg to sub and propagate to main")
    clog2.error("clog2 - error msg goes to file and stdout/stderr")
    print_file_contents(path.join("logs", "app_root.log"))
    print_file_contents(path.join("logs", "app_main.log"))
    print_file_contents(path.join("logs", "sub.log"))

    loggers = get_all_loggers()
    print("len(loggers): ", len(loggers))
    show_all_loggers()