Port code from prior PR (#1746), code cleanups

This commit is contained in:
Chris Love
2021-08-25 20:32:35 -07:00
parent 5df9b11141
commit c5fd8a0b97
4 changed files with 303 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ void user_defined_example();
void err_handler_example();
void syslog_example();
void custom_flags_example();
void udp_example();
#include "spdlog/spdlog.h"
#include "spdlog/cfg/env.h" // support for loading levels from the environment variable
@@ -75,6 +76,7 @@ int main(int, char *[])
trace_example();
stopwatch_example();
custom_flags_example();
udp_example();
// Flush all *registered* loggers using a worker thread every 3 seconds.
// note: registered loggers *must* be thread safe for this to work correctly!
@@ -198,6 +200,7 @@ void trace_example()
// stopwatch example
#include "spdlog/stopwatch.h"
#include <thread>
#include "spdlog/sinks/udp_sink.h"
void stopwatch_example()
{
spdlog::stopwatch sw;
@@ -205,6 +208,17 @@ void stopwatch_example()
spdlog::info("Stopwatch: {} seconds", sw);
}
void udp_example()
{
// using spdlog::details::make_unique;
//auto daily_logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30);
spdlog::sinks::udp_sink_config cfg("127.0.0.1", 11091);
auto my_logger = spdlog::udp_logger_mt("udplog", cfg);
my_logger->set_level(spdlog::level::debug);
my_logger->info("hello world");
my_logger->info("are you ok");
}
// A logger with multiple sinks (stdout and file) - each with a different format and log level.
void multi_sink_example()
{