Exemple #1
0
//=======================================================================================================
void log_sample() {
    puts("");
    puts("===============begin log sample==============");

    WLOG_INIT(util::log::log_wrapper::categorize_t::DEFAULT, util::log::log_wrapper::level_t::LOG_LW_DEBUG);

    PSTDERROR("try to print error log.\n");
    PSTDOK("try to print ok log.\n");

    WLOGNOTICE("notice log %d", 0);

    util::log::log_sink_file_backend filed_backend;
    filed_backend.set_max_file_size(256);
    filed_backend.set_rotate_size(3);
    filed_backend.set_file_pattern("%Y-%m-%d/%S/%N.log");
    // filed_backend.set_check_interval(1);

    WLOG_GETCAT(util::log::log_wrapper::categorize_t::DEFAULT)->add_sink(filed_backend);

    for (int i = 0; i < 16; ++i) {
        WLOGDEBUG("first dir test log: %d", i);
    }

    THREAD_SLEEP_MS(1000);
    util::time::time_utility::update();

    for (int i = 0; i < 16; ++i) {
        WLOGDEBUG("second dir log: %d", i);
    }

    unsigned long long ull_test_in_mingw = 64;
    WLOGINFO("%llu", ull_test_in_mingw);
    printf("log are located at %s\n", util::file_system::get_cwd().c_str());
    puts("===============end log sample==============");
}
Exemple #2
0
//=======================================================================================================
void log_sample_func1(int times) {
    if (times > 0) {
        log_sample_func1(times - 1);
        return;
    }

    if (util::log::is_stacktrace_enabled()) {
        std::cout << "----------------test stacktrace begin--------------" << std::endl;
        char buffer[2048] = {0};
        util::log::stacktrace_write(buffer, sizeof(buffer));
        std::cout << buffer << std::endl;
        std::cout << "----------------test stacktrace end--------------" << std::endl;
    }

    WLOG_INIT(util::log::log_wrapper::categorize_t::DEFAULT, util::log::log_wrapper::level_t::LOG_LW_DEBUG);
    WLOG_GETCAT(util::log::log_wrapper::categorize_t::DEFAULT)->set_stacktrace_level(util::log::log_wrapper::level_t::LOG_LW_INFO);

    WLOG_GETCAT(util::log::log_wrapper::categorize_t::DEFAULT)->clear_sinks();

    std::cout << "----------------setup log_wrapper done--------------" << std::endl;

    PSTDERROR("try to print error log.\n");
    PSTDOK("try to print ok log.\n");

    std::cout << "----------------sample for PSTDOK/PSTDERROR done--------------" << std::endl;

    WLOGNOTICE("notice log %d", 0);

    util::log::log_sink_file_backend filed_backend;
    filed_backend.set_max_file_size(256);
    filed_backend.set_rotate_size(3);
    filed_backend.set_file_pattern("%Y-%m-%d/%S/%N.log");

    WLOG_GETCAT(util::log::log_wrapper::categorize_t::DEFAULT)->add_sink(filed_backend);
    std::cout << "----------------setup file system log sink done--------------" << std::endl;

    for (int i = 0; i < 16; ++i) {
        WLOGDEBUG("first dir test log: %d", i);
    }

    THREAD_SLEEP_MS(1000);
    util::time::time_utility::update();

    for (int i = 0; i < 16; ++i) {
        WLOGDEBUG("second dir log: %d", i);
    }

    unsigned long long ull_test_in_mingw = 64;
    WLOGINFO("%llu", ull_test_in_mingw);

    WLOG_GETCAT(util::log::log_wrapper::categorize_t::DEFAULT)
        ->set_sink(WLOG_GETCAT(util::log::log_wrapper::categorize_t::DEFAULT)->sink_size() - 1,
                   util::log::log_wrapper::level_t::LOG_LW_DEBUG, util::log::log_wrapper::level_t::LOG_LW_DEBUG);
    WLOGDEBUG("Debug still available %llu", ull_test_in_mingw);
    WLOGINFO("Info not available now %llu", ull_test_in_mingw);

    std::cout << "log are located at " << util::file_system::get_cwd().c_str() << std::endl;

    WLOG_GETCAT(util::log::log_wrapper::categorize_t::DEFAULT)->pop_sink();
    WLOGERROR("No log sink now");
}