Advertisement
Guest User

Untitled

a guest
Jul 19th, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #define BOOST_LOG_DYN_LINK 1
  2.  
  3. // clang++ -std=c++11 -l boost_log -l boost_log_setup -l boost_thread -l boost_system -l pthread boostlog.cpp
  4.  
  5. #include <iostream>
  6. #include <fstream>
  7. #include <string>
  8.  
  9. #include <boost/log/core.hpp>
  10. #include <boost/log/trivial.hpp>
  11. #include <boost/log/expressions.hpp>
  12.  
  13. #include <boost/log/sources/severity_logger.hpp>
  14.  
  15. #include <boost/log/utility/setup/common_attributes.hpp>
  16. #include <boost/log/utility/setup/file.hpp>
  17. #include <boost/log/utility/setup/console.hpp>
  18. #include <boost/log/utility/setup/from_stream.hpp>
  19.  
  20.  
  21. void setup_logging()
  22. {
  23.   std::string format = "Code: [%TimeStamp%]: %Message%";
  24.   boost::log::add_file_log("sample.log",
  25.                            boost::log::keywords::format = format);
  26.   boost::log::add_console_log(std::cout,
  27.                               boost::log::keywords::format = format);
  28.   boost::log::core::get()->set_filter(
  29.     boost::log::trivial::severity >= boost::log::trivial::info
  30.     );
  31.  
  32.   std::ifstream settings_file("log.settings");
  33.   boost::log::init_from_stream(settings_file);
  34.  
  35. }
  36.  
  37. int main(int argc, char** argv)
  38. {
  39.   setup_logging();
  40.   boost::log::add_common_attributes();
  41.  
  42.   using namespace boost::log::trivial;
  43.   boost::log::sources::severity_logger<severity_level> lg;
  44.  
  45.   BOOST_LOG_SEV(lg, trace) << "A trace severity message";
  46.   BOOST_LOG_SEV(lg, debug) << "A debug severity message";
  47.   BOOST_LOG_SEV(lg, info) << "An informational severity message";
  48.   BOOST_LOG_SEV(lg, warning) << "A warning severity message";
  49.   BOOST_LOG_SEV(lg, error) << "An error severity message";
  50.   BOOST_LOG_SEV(lg, fatal) << "A fatal severity message";
  51.  
  52.   return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement