]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/log/example/doc/sinks_file.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / log / example / doc / sinks_file.cpp
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 <string>
9 #include <fstream>
10 #include <iostream>
11 #include <boost/smart_ptr/shared_ptr.hpp>
12 #include <boost/log/core.hpp>
13 #include <boost/log/sinks/sync_frontend.hpp>
14 #include <boost/log/sinks/text_file_backend.hpp>
15 #include <boost/log/sources/severity_channel_logger.hpp>
16 #include <boost/log/sources/record_ostream.hpp>
17
18 namespace logging = boost::log;
19 namespace src = boost::log::sources;
20 namespace sinks = boost::log::sinks;
21 namespace keywords = boost::log::keywords;
22
23 //[ example_sinks_file
24 void init_logging()
25 {
26 boost::shared_ptr< logging::core > core = logging::core::get();
27
28 boost::shared_ptr< sinks::text_file_backend > backend =
29 boost::make_shared< sinks::text_file_backend >(
30 keywords::file_name = "file_%5N.log", /*< file name pattern >*/
31 keywords::rotation_size = 5 * 1024 * 1024, /*< rotate the file upon reaching 5 MiB size... >*/
32 keywords::time_based_rotation = sinks::file::rotation_at_time_point(12, 0, 0) /*< ...or every day, at noon, whichever comes first >*/
33 );
34
35 // Wrap it into the frontend and register in the core.
36 // The backend requires synchronization in the frontend.
37 typedef sinks::synchronous_sink< sinks::text_file_backend > sink_t;
38 boost::shared_ptr< sink_t > sink(new sink_t(backend));
39
40 core->add_sink(sink);
41 }
42 //]
43
44 int main(int, char*[])
45 {
46 init_logging();
47
48 src::severity_channel_logger< > lg(keywords::channel = "net");
49 BOOST_LOG_SEV(lg, 3) << "Hello world!";
50
51 return 0;
52 }