]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/log/example/doc/tutorial_file.cpp
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)
8 #include <boost/log/core.hpp>
9 #include <boost/log/trivial.hpp>
10 #include <boost/log/expressions.hpp>
11 #include <boost/log/sinks/text_file_backend.hpp>
12 #include <boost/log/utility/setup/file.hpp>
13 #include <boost/log/utility/setup/common_attributes.hpp>
14 #include <boost/log/sources/severity_logger.hpp>
15 #include <boost/log/sources/record_ostream.hpp>
17 namespace logging
= boost::log
;
18 namespace src
= boost::log::sources
;
19 namespace sinks
= boost::log::sinks
;
20 namespace keywords
= boost::log::keywords
;
24 //[ example_tutorial_file_simple
27 logging::add_file_log("sample.log");
29 logging::core::get()->set_filter
31 logging::trivial::severity
>= logging::trivial::info
36 // We need this due to this bug: https://svn.boost.org/trac/boost/ticket/4416
37 //[ example_tutorial_file_advanced_no_callouts
42 keywords::file_name
= "sample_%N.log",
43 keywords::rotation_size
= 10 * 1024 * 1024,
44 keywords::time_based_rotation
= sinks::file::rotation_at_time_point(0, 0, 0),
45 keywords::format
= "[%TimeStamp%]: %Message%"
48 logging::core::get()->set_filter
50 logging::trivial::severity
>= logging::trivial::info
57 //[ example_tutorial_file_advanced
62 keywords::file_name
= "sample_%N.log", /*< file name pattern >*/
63 keywords::rotation_size
= 10 * 1024 * 1024, /*< rotate files every 10 MiB... >*/
64 keywords::time_based_rotation
= sinks::file::rotation_at_time_point(0, 0, 0), /*< ...or at midnight >*/
65 keywords::format
= "[%TimeStamp%]: %Message%" /*< log record format >*/
68 logging::core::get()->set_filter
70 logging::trivial::severity
>= logging::trivial::info
77 int main(int, char*[])
80 logging::add_common_attributes();
82 using namespace logging::trivial
;
83 src::severity_logger
< severity_level
> lg
;
85 BOOST_LOG_SEV(lg
, trace
) << "A trace severity message";
86 BOOST_LOG_SEV(lg
, debug
) << "A debug severity message";
87 BOOST_LOG_SEV(lg
, info
) << "An informational severity message";
88 BOOST_LOG_SEV(lg
, warning
) << "A warning severity message";
89 BOOST_LOG_SEV(lg
, error
) << "An error severity message";
90 BOOST_LOG_SEV(lg
, fatal
) << "A fatal severity message";