Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / log / example / doc / tutorial_fmt_string.cpp
1 /*
2  *          Copyright Andrey Semashev 2007 - 2014.
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/log/trivial.hpp>
9 #include <boost/log/sources/severity_logger.hpp>
10 #include <boost/log/sources/record_ostream.hpp>
11 #include <boost/log/utility/setup/file.hpp>
12 #include <boost/log/utility/setup/common_attributes.hpp>
13
14 namespace logging = boost::log;
15 namespace src = boost::log::sources;
16 namespace keywords = boost::log::keywords;
17
18 //[ example_tutorial_formatters_string
19 void init()
20 {
21     logging::add_file_log
22     (
23         keywords::file_name = "sample_%N.log",
24         keywords::format = "[%TimeStamp%]: %Message%"
25     );
26 }
27 //]
28
29 int main(int, char*[])
30 {
31     init();
32     logging::add_common_attributes();
33
34     using namespace logging::trivial;
35     src::severity_logger< severity_level > lg;
36
37     BOOST_LOG_SEV(lg, trace) << "A trace severity message";
38     BOOST_LOG_SEV(lg, debug) << "A debug severity message";
39     BOOST_LOG_SEV(lg, info) << "An informational severity message";
40     BOOST_LOG_SEV(lg, warning) << "A warning severity message";
41     BOOST_LOG_SEV(lg, error) << "An error severity message";
42     BOOST_LOG_SEV(lg, fatal) << "A fatal severity message";
43
44     return 0;
45 }