bux API Reference 1.11.0
Static library of whatever are seen required in general purpose but not directly supported from Modern C++. Or whatever reusable originated from my side projects.
Loading...
Searching...
No Matches
test/smoke_timelog.cpp
//#define TURN_OFF_LOGGER_
//#define LOGGER_USE_LOCAL_TIME_ false
#include <bux/Logger.h> // DEF_LOGGER_FILES(), DEF_FALLBACK_LOGGER_FILES()
#include <bux/FileLog.h> // bux::C_PathFmtLogSnap
#include <chrono> // std::chrono::system_clock
#include <random> // std::mt19937
#include <stdlib.h> // strtoul()
#include <thread> // std::this_thread::sleep_for()
#define SET_SIZE_LIMIT_
#ifndef SET_SIZE_LIMIT_
DEF_LOGGER_FILES("timelog/{:%y%m%d_%H%M}.log")
#else
constinit const std::array fallbacks{
"timelog/{:%y%m%d-%H}.log",
"timelog/{:%y%m%d-%H-%M}.log",
"timelog/{:%y%m%d-%H-%M-%S}.log"
};
DEF_FALLBACK_LOGGER_FILES(65536, fallbacks)
#endif
thread_local std::mt19937 g_rng{std::random_device{"/dev/urandom"}()};
static const struct { bux::E_LogLevel ll; const char *msg; } LOG_SRC[] = {
{LL_FATAL, "Hello fatal"},
{LL_ERROR, "Hello error"},
{LL_WARNING, "Hello warning"},
{LL_INFO, "Hello info"},
{LL_VERBOSE, "Hello verbose"},
};
int main(int argc, const char *argv[])
{
#ifndef TURN_OFF_LOGGER_
*u <<std::boolalpha <<"LOGGER_USE_LOCAL_TIME_: " <<LOGGER_USE_LOCAL_TIME_ <<"\n";
#endif
if (argc <= 1)
{
for (auto i: LOG_SRC)
LOG(i.ll, "{}", i.msg);
}
else
{
using C_MyClock = std::chrono::system_clock;
const auto deadline = C_MyClock::now() + std::chrono::seconds(strtoul(argv[1],nullptr,0));
while (C_MyClock::now() < deadline)
{
const auto &i = LOG_SRC[std::uniform_int_distribution<size_t>{0,std::size(LOG_SRC)-1}(g_rng)];
LOG(i.ll, "{}", i.msg);
std::this_thread::sleep_for(
#ifdef SET_SIZE_LIMIT_
std::chrono::milliseconds(100)
#else
std::chrono::seconds(1)
#endif
);
}
}
}
@ LL_WARNING
Situation that should be warned but should not have sabotaged anything already.
Definition LogLevel.h:12
@ LL_ERROR
Error not serious enough that the program can continue to run.
Definition LogLevel.h:11
@ LL_INFO
Information worth mentioning about the current status, be it normal or abnormal.
Definition LogLevel.h:13
@ LL_VERBOSE
More detailed or advanced information probably considered too much by some.
Definition LogLevel.h:14
@ LL_FATAL
Error serious enough that the program should shut down immediately after reporting this.
Definition LogLevel.h:10
#define LOGGER_USE_LOCAL_TIME_
Definition Logger.h:80
#define DEF_LOGGER_FILES(pathfmt,...)
Definition Logger.h:115
#define DEF_FALLBACK_LOGGER_FILES(fsize_in_bytes, fallbackPaths)
Definition Logger.h:123
#define LOG(ll, fmtStr,...)
Definition Logger.h:76
E_LogLevel
Definition LogLevel.h:9
I_SyncLog & logger()
Definition Logger.cpp:20