main.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright Andrey Semashev 2007 - 2015.
  3. * Distributed under the Boost Software License, Version 1.0.
  4. * (See accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /*!
  8. * \file main.cpp
  9. * \author Andrey Semashev
  10. * \date 07.11.2009
  11. *
  12. * \brief An example of trivial logging.
  13. */
  14. // #define BOOST_ALL_DYN_LINK 1
  15. // #define BOOST_LOG_DYN_LINK 1
  16. #include <boost/log/trivial.hpp>
  17. #include <boost/log/core.hpp>
  18. #include <boost/log/expressions.hpp>
  19. int main(int argc, char* argv[])
  20. {
  21. // Trivial logging: all log records are written into a file
  22. BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
  23. BOOST_LOG_TRIVIAL(debug) << "A debug severity message";
  24. BOOST_LOG_TRIVIAL(info) << "An informational severity message";
  25. BOOST_LOG_TRIVIAL(warning) << "A warning severity message";
  26. BOOST_LOG_TRIVIAL(error) << "An error severity message";
  27. BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";
  28. // Filtering can also be applied
  29. using namespace boost::log;
  30. core::get()->set_filter
  31. (
  32. trivial::severity >= trivial::info
  33. );
  34. // Now the first two lines will not pass the filter
  35. BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
  36. BOOST_LOG_TRIVIAL(debug) << "A debug severity message";
  37. BOOST_LOG_TRIVIAL(info) << "An informational severity message";
  38. BOOST_LOG_TRIVIAL(warning) << "A warning severity message";
  39. BOOST_LOG_TRIVIAL(error) << "An error severity message";
  40. BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";
  41. return 0;
  42. }