spdlog/example/example.cpp

69 lines
3.0 KiB
C++
Raw Normal View History

2014-10-31 21:20:54 -04:00
/*************************************************************************/
/* spdlog - an extremely fast and easy to use c++11 logging library. */
/* Copyright (c) 2014 Gabi Melman. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
2014-01-25 08:52:10 -05:00
//
2014-10-31 21:20:54 -04:00
// 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-10-31 20:25:51 -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!");
2014-10-31 20:28:49 -04:00
spd::set_level(spd::level::INFO);
// 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");
2014-10-31 20:28:49 -04:00
spd::get("console")->info("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