spdlog/example/example.cpp

46 lines
1.2 KiB
C++
Raw Normal View History

2014-01-25 08:52:10 -05:00
//
// example.cpp : spdlog usage example
//
2014-10-11 21:40:11 -04:00
#include <iostream>
#include "spdlog/spdlog.h"
2014-10-09 19:46:03 -04:00
2014-03-03 18:23:38 -05:00
2014-10-31 20:12:12 -04:00
int main_(int, char* [])
2014-10-18 12:04:24 -04:00
{
2014-10-09 20:36:50 -04:00
namespace spd = spdlog;
2014-10-31 20:12:12 -04:00
try
{
std::string filename = "spdlog_example";
auto console = spd::stderr_logger_mt("console");
2014-10-31 10:34:48 -04:00
console->info("Welcome to spdlog!") ;
console->info() << "Creating file " << filename << "..";
auto file_logger = spd::rotating_logger_mt("file_logger", filename, 1024 * 1024 * 5, 3);
file_logger->info("Log file message number", 1);
for (int i = 0; i < 100; ++i)
{
auto square = i*i;
file_logger->info() << i << '*' << i << '=' << square << " (" << "0x" << std::hex << square << ")";
}
// Change log level to all loggers to warning and above
spd::set_level(spd::level::WARN);
console->info("This should not be displayed");
console->warn("This should!");
// Change format pattern to all loggers
2014-10-31 20:12:12 -04:00
spd::set_pattern(" **** %Y-%m-%d %H:%M:%S.%e %l **** %v");
spd::get("console")->warn("This is another message with different format");
}
catch (const spd::spdlog_ex& ex)
{
std::cout << "Log failed: " << ex.what() << std::endl;
}
2014-10-31 20:12:12 -04:00
return 0;
}
2014-01-25 08:52:10 -05:00