spdlog/example/example.cpp

42 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-12-13 22:17:09 +08:00
#include <cstdio>
2020-03-06 21:21:21 +08:00
void load_levels_example();
2019-12-13 22:17:09 +08:00
void stdout_logger_example();
void basic_example();
void rotating_example();
void daily_example();
void async_example();
void binary_example();
void trace_example();
void multi_sink_example();
void user_defined_example();
void err_handler_example();
void syslog_example();
void custom_flags_example();
2019-12-13 22:17:09 +08:00
2019-12-23 02:40:19 +08:00
#include "spdlog/spdlog.h"
2020-03-16 00:56:38 +08:00
#include "spdlog/cfg/env.h" // for loading levels from the environment variable
2019-08-23 00:58:49 +08:00
2019-12-23 02:40:19 +08:00
#include "spdlog/sinks/basic_file_sink.h"
void basic_example()
{
// Create basic file logger (not rotated).
2020-05-02 16:52:26 +08:00
spdlog::file_event_handlers handlers;
handlers.after_open = [](spdlog::filename_t, std::FILE* fstream)
2019-12-23 02:40:19 +08:00
{
2020-05-02 16:52:26 +08:00
fputs("OPEN!\r\n", fstream);
};
auto fsink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("c:\\temp\\test.log", true, handlers);
2019-12-23 02:40:19 +08:00
}
2020-05-02 16:52:26 +08:00
int main(int, char *[])
2020-03-21 21:25:26 +08:00
{
2020-05-02 16:52:26 +08:00
basic_example();
}