#include <atomic>
#include <iostream>
#include <thread>
#include <vector>
void ConfigureLogger()
{
auto sink = std::make_shared<CppLogging::SyncProcessor>(std::make_shared<CppLogging::BinaryLayout>());
sink->appenders().push_back(std::make_shared<CppLogging::RollingFileAppender>(".", "rolling", "bin.log", 4096, 9, true));
}
int main(int argc, char** argv)
{
ConfigureLogger();
std::cout << "Press Enter to stop..." << std::endl;
int concurrency = 4;
std::atomic<bool> stop(false);
std::vector<std::thread> threads;
for (int thread = 0; thread < concurrency; ++thread)
{
threads.push_back(std::thread([&stop]()
{
int index = 0;
while (!stop)
{
++index;
logger.Debug("Debug message {}", index);
logger.Info("Info message {}", index);
logger.Warn("Warning message {}", index);
logger.Error("Error message {}", index);
logger.Fatal("Fatal message {}", index);
CppCommon::Thread::Yield();
}
}));
}
std::cin.get();
stop = true;
for (auto& thread : threads)
thread.join();
return 0;
}
static void ConfigLogger(const std::shared_ptr< Processor > &sink)
Configure default logger with a given logging sink processor.
static void Startup()
Startup the logging infrastructure.
Logger configuration definition.
Logger interface definition.