Skip to content

Instantly share code, notes, and snippets.

@jiahaowu
Created February 26, 2017 23:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jiahaowu/34950d8fa49ab2dc63d30e2d3a6a1666 to your computer and use it in GitHub Desktop.
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
#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