• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <boost/move/utility_core.hpp>
9 #include <boost/log/sources/logger.hpp>
10 #include <boost/log/sources/record_ostream.hpp>
11 #include <boost/log/sources/global_logger_storage.hpp>
12 #include <boost/log/utility/setup/file.hpp>
13 #include <boost/log/utility/setup/common_attributes.hpp>
14 
15 namespace logging = boost::log;
16 namespace src = boost::log::sources;
17 namespace keywords = boost::log::keywords;
18 
BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(my_logger,src::logger_mt)19 BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(my_logger, src::logger_mt)
20 
21 void logging_function1()
22 {
23     src::logger lg;
24 
25 //[ example_tutorial_logging_manual_logging
26     logging::record rec = lg.open_record();
27     if (rec)
28     {
29         logging::record_ostream strm(rec);
30         strm << "Hello, World!";
31         strm.flush();
32         lg.push_record(boost::move(rec));
33     }
34 //]
35 }
36 
logging_function2()37 void logging_function2()
38 {
39     src::logger_mt& lg = my_logger::get();
40     BOOST_LOG(lg) << "Greetings from the global logger!";
41 }
42 
main(int,char * [])43 int main(int, char*[])
44 {
45     logging::add_file_log("sample.log");
46     logging::add_common_attributes();
47 
48     logging_function1();
49     logging_function2();
50 
51     return 0;
52 }
53