Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BOOST_LOG_DYN_LINK 1
- // clang++ -std=c++11 -l boost_log -l boost_log_setup -l boost_thread -l boost_system -l pthread boostlog.cpp
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <boost/log/core.hpp>
- #include <boost/log/trivial.hpp>
- #include <boost/log/expressions.hpp>
- #include <boost/log/sources/severity_logger.hpp>
- #include <boost/log/utility/setup/common_attributes.hpp>
- #include <boost/log/utility/setup/file.hpp>
- #include <boost/log/utility/setup/console.hpp>
- #include <boost/log/utility/setup/from_stream.hpp>
- void setup_logging()
- {
- std::string format = "Code: [%TimeStamp%]: %Message%";
- boost::log::add_file_log("sample.log",
- boost::log::keywords::format = format);
- boost::log::add_console_log(std::cout,
- boost::log::keywords::format = format);
- boost::log::core::get()->set_filter(
- boost::log::trivial::severity >= boost::log::trivial::info
- );
- std::ifstream settings_file("log.settings");
- boost::log::init_from_stream(settings_file);
- }
- int main(int argc, char** argv)
- {
- setup_logging();
- boost::log::add_common_attributes();
- using namespace boost::log::trivial;
- boost::log::sources::severity_logger<severity_level> lg;
- BOOST_LOG_SEV(lg, trace) << "A trace severity message";
- BOOST_LOG_SEV(lg, debug) << "A debug severity message";
- BOOST_LOG_SEV(lg, info) << "An informational severity message";
- BOOST_LOG_SEV(lg, warning) << "A warning severity message";
- BOOST_LOG_SEV(lg, error) << "An error severity message";
- BOOST_LOG_SEV(lg, fatal) << "A fatal severity message";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement