]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/log/example/doc/sinks_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)
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>
18 namespace logging
= boost::log
;
19 namespace src
= boost::log::sources
;
20 namespace sinks
= boost::log::sinks
;
21 namespace keywords
= boost::log::keywords
;
23 //[ example_sinks_file
26 boost::shared_ptr
< logging::core
> core
= logging::core::get();
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 >*/
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
));
44 int main(int, char*[])
48 src::severity_channel_logger
< > lg(keywords::channel
= "net");
49 BOOST_LOG_SEV(lg
, 3) << "Hello world!";