#include <iostream>
#include <random>
#include <thread>
#ifdef _WIN32
#include <conio.h>
#else
#include <curses.h>
#endif
namespace {
thread_local std::mt19937 g_rng{std::random_device{"/dev/urandom"}()};
bool g_stop{};
}
int main()
{
using bux::user::g_paraLog;
g_paraLog.addChild(std::cout, LL_WARNING);
{
logger.configPath(2UL<<20, std::array{
"logs/st{:%Y-%m-%d/%y%m%d}.log",
"logs/st{:%Y-%m-%d/%y%m%d-%H}.log",
"logs/st{:%Y-%m-%d/%y%m%d-%H-%M}.log"});
});
#ifndef _WIN32
initscr();
cbreak();
noecho();
scrollok(stdscr, TRUE);
nodelay(stdscr, TRUE);
#endif
std::list<std::thread> loops;
for (int i = 0; i < 20; ++i)
loops.emplace_back([]{
while (!g_stop)
{
static constinit const struct { bux::E_LogLevel ll; const char *msg; } LOG_SRC[] = {
{LL_FATAL, "fatal"},
{LL_ERROR, "error"},
{LL_WARNING, "warning"},
{LL_INFO, "info"},
{LL_VERBOSE, "verbose"},
};
const auto &src = LOG_SRC[std::uniform_int_distribution<size_t>{0,std::size(LOG_SRC)-1}(g_rng)];
const auto sleep_ms = std::uniform_int_distribution<size_t>{0,19}(g_rng);
LOG(src.ll, "Hello {} and wait for {}ms", src.msg, sleep_ms);
std::this_thread::sleep_for(std::chrono::milliseconds(sleep_ms));
}
});
while (!g_stop)
{
#ifdef _WIN32
if (_kbhit()) switch (_getch())
#else
switch (getch())
#endif
{
case 'Q':
case 'q':
case '\x1b':
g_stop = true;
break;
default:
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
}
#ifndef _WIN32
endwin();
#endif
for (auto &i: loops)
i.join();
}
#define LOGGER_USE_LOCAL_TIME_