spdlog/example/example.cpp

46 lines
1.2 KiB
C++
Raw Normal View History

2014-01-25 21:52:10 +08:00
//
// example.cpp : spdlog usage example
//
2014-10-12 09:40:11 +08:00
#include <iostream>
#include "spdlog/spdlog.h"
2014-10-10 07:46:03 +08:00
2014-03-04 07:23:38 +08:00
2014-11-01 08:25:51 +08:00
int main(int, char* [])
2014-10-19 00:04:24 +08:00
{
2014-10-10 08:36:50 +08:00
namespace spd = spdlog;
2014-11-01 08:12:12 +08:00
try
{
std::string filename = "spdlog_example";
auto console = spd::stderr_logger_mt("console");
2014-10-31 22:34:48 +08: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-11-01 08:12:12 +08: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-11-01 08:12:12 +08:00
return 0;
}
2014-01-25 21:52:10 +08:00