Created
February 26, 2017 23:41
-
-
Save jiahaowu/34950d8fa49ab2dc63d30e2d3a6a1666 to your computer and use it in GitHub Desktop.
example of using boost log, which includes stdout, file output, log rotation, message format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/log/core.hpp> | |
#include <boost/log/expressions.hpp> | |
#include <boost/log/sinks/text_file_backend.hpp> | |
#include <boost/log/sources/record_ostream.hpp> | |
#include <boost/log/sources/severity_logger.hpp> | |
#include <boost/log/trivial.hpp> | |
#include <boost/log/utility/setup/common_attributes.hpp> | |
#include <boost/log/utility/setup/console.hpp> | |
#include <boost/log/utility/setup/file.hpp> | |
namespace is = ImageStitching; | |
namespace logging = boost::log; | |
namespace src = boost::log::sources; | |
namespace sinks = boost::log::sinks; | |
namespace keywords = boost::log::keywords; | |
void log_init() { | |
logging::register_simple_formatter_factory< | |
boost::log::trivial::severity_level, char>("Severity"); | |
logging::add_file_log( | |
keywords::target = "logs/", keywords::file_name = "%y%m%d_%3N.log", | |
keywords::rotation_size = 10 * 1024 * 1024, | |
keywords::scan_method = sinks::file::scan_matching, | |
keywords::format = "[%TimeStamp%][%Severity%]: %Message%"); | |
logging::add_console_log(std::cout, | |
boost::log::keywords::format = ">> %Message%"); | |
logging::core::get()->set_filter(logging::trivial::severity >= | |
logging::trivial::info); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment