spdlog/example/example.cpp

34 lines
1.0 KiB
C++
Raw Normal View History

2019-03-24 06:40:27 +08:00
//
// Copyright(c) 2015 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
2019-05-12 22:05:14 +08:00
2019-03-24 06:40:27 +08:00
// spdlog usage example
2019-05-12 05:34:55 +08:00
#include <cstdio>
2019-08-23 00:48:11 +08:00
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
2019-05-12 05:32:57 +08:00
#include "spdlog/spdlog.h"
2019-05-12 05:34:55 +08:00
#include "spdlog/async.h"
2019-08-23 00:48:11 +08:00
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/backtrace-sink.h"
2019-05-12 05:34:55 +08:00
2019-08-23 00:48:11 +08:00
#include <vector>
2019-05-12 05:34:55 +08:00
2019-08-23 00:48:11 +08:00
using namespace spdlog::details;
using namespace spdlog::sinks;
2019-05-12 05:34:55 +08:00
2019-08-23 00:48:11 +08:00
int main(int, char *[]) {
auto backtrack_sink = std::make_shared<backtrace_sink_mt >(spdlog::level::debug, 10);
backtrack_sink ->add_sink(std::make_shared<stdout_color_sink_mt>());
spdlog::logger l("loggername", backtrack_sink);
l.set_level(spdlog::level::trace);
//spdlog::set_backtrace(spdlog::level::warn, 16)
for(int i = 0; i < 100; i++)
2019-05-12 05:34:55 +08:00
{
2019-08-23 00:48:11 +08:00
//l.log(spdlog::source_loc{__FILE__, __LINE__, "main"}, spdlog::level::debug, "Debug message #{}", i);
SPDLOG_LOGGER_TRACE((&l), "Debug message #{}", i);
2019-05-12 05:34:55 +08:00
}
2019-08-23 00:48:11 +08:00
l.warn("This will trigger the log of all prev messages in the queue");
2019-05-12 05:34:55 +08:00
}