]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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/date_time/posix_time/posix_time_types.hpp> | |
9 | #include <boost/log/trivial.hpp> | |
10 | #include <boost/log/expressions.hpp> | |
11 | #include <boost/log/sources/severity_logger.hpp> | |
12 | #include <boost/log/sources/record_ostream.hpp> | |
13 | #include <boost/log/utility/setup/file.hpp> | |
14 | #include <boost/log/utility/setup/common_attributes.hpp> | |
15 | #include <boost/log/support/date_time.hpp> | |
16 | ||
17 | namespace logging = boost::log; | |
18 | namespace src = boost::log::sources; | |
19 | namespace expr = boost::log::expressions; | |
20 | namespace keywords = boost::log::keywords; | |
21 | ||
22 | #if 1 | |
23 | ||
24 | //[ example_tutorial_formatters_stream | |
25 | void init() | |
26 | { | |
27 | logging::add_file_log | |
28 | ( | |
29 | keywords::file_name = "sample_%N.log", | |
30 | // This makes the sink to write log records that look like this: | |
31 | // 1: <normal> A normal severity message | |
32 | // 2: <error> An error severity message | |
33 | keywords::format = | |
34 | ( | |
35 | expr::stream | |
36 | << expr::attr< unsigned int >("LineID") | |
37 | << ": <" << logging::trivial::severity | |
38 | << "> " << expr::smessage | |
39 | ) | |
40 | ); | |
41 | } | |
42 | //] | |
43 | ||
44 | #else | |
45 | ||
46 | //[ example_tutorial_formatters_stream_date_time | |
47 | void init() | |
48 | { | |
49 | logging::add_file_log | |
50 | ( | |
51 | keywords::file_name = "sample_%N.log", | |
52 | // This makes the sink to write log records that look like this: | |
53 | // YYYY-MM-DD HH:MI:SS: <normal> A normal severity message | |
54 | // YYYY-MM-DD HH:MI:SS: <error> An error severity message | |
55 | keywords::format = | |
56 | ( | |
57 | expr::stream | |
58 | << expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S") | |
59 | << ": <" << logging::trivial::severity | |
60 | << "> " << expr::smessage | |
61 | ) | |
62 | ); | |
63 | } | |
64 | //] | |
65 | ||
66 | #endif | |
67 | ||
68 | int main(int, char*[]) | |
69 | { | |
70 | init(); | |
71 | logging::add_common_attributes(); | |
72 | ||
73 | using namespace logging::trivial; | |
74 | src::severity_logger< severity_level > lg; | |
75 | ||
76 | BOOST_LOG_SEV(lg, trace) << "A trace severity message"; | |
77 | BOOST_LOG_SEV(lg, debug) << "A debug severity message"; | |
78 | BOOST_LOG_SEV(lg, info) << "An informational severity message"; | |
79 | BOOST_LOG_SEV(lg, warning) << "A warning severity message"; | |
80 | BOOST_LOG_SEV(lg, error) << "An error severity message"; | |
81 | BOOST_LOG_SEV(lg, fatal) << "A fatal severity message"; | |
82 | ||
83 | return 0; | |
84 | } |