tutorial_fmt_string.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #include <boost/log/trivial.hpp>
  8. #include <boost/log/sources/severity_logger.hpp>
  9. #include <boost/log/sources/record_ostream.hpp>
  10. #include <boost/log/utility/setup/file.hpp>
  11. #include <boost/log/utility/setup/common_attributes.hpp>
  12. namespace logging = boost::log;
  13. namespace src = boost::log::sources;
  14. namespace keywords = boost::log::keywords;
  15. //[ example_tutorial_formatters_string
  16. void init()
  17. {
  18. logging::add_file_log
  19. (
  20. keywords::file_name = "sample_%N.log",
  21. keywords::format = "[%TimeStamp%]: %Message%"
  22. );
  23. }
  24. //]
  25. int main(int, char*[])
  26. {
  27. init();
  28. logging::add_common_attributes();
  29. using namespace logging::trivial;
  30. src::severity_logger< severity_level > lg;
  31. BOOST_LOG_SEV(lg, trace) << "A trace severity message";
  32. BOOST_LOG_SEV(lg, debug) << "A debug severity message";
  33. BOOST_LOG_SEV(lg, info) << "An informational severity message";
  34. BOOST_LOG_SEV(lg, warning) << "A warning severity message";
  35. BOOST_LOG_SEV(lg, error) << "An error severity message";
  36. BOOST_LOG_SEV(lg, fatal) << "A fatal severity message";
  37. return 0;
  38. }