/*************************************************************************/ /* 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. */ /*************************************************************************/ // // spdlog usage example // #include #include "spdlog/spdlog.h" int main(int, char* []) { namespace spd = spdlog; try { std::string filename = "spdlog_example"; auto console = spd::stderr_logger_mt("console"); 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!"); spd::set_level(spd::level::INFO); // Change format pattern to all loggers spd::set_pattern(" **** %Y-%m-%d %H:%M:%S.%e %l **** %v"); 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; } return 0; }