]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/log/example/doc/sinks_multifile.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)
10 #include <boost/smart_ptr/shared_ptr.hpp>
11 #include <boost/smart_ptr/make_shared_object.hpp>
12 #include <boost/log/core.hpp>
13 #include <boost/log/expressions.hpp>
14 #include <boost/log/sinks/sync_frontend.hpp>
15 #include <boost/log/sinks/text_multifile_backend.hpp>
16 #include <boost/log/sources/logger.hpp>
17 #include <boost/log/sources/record_ostream.hpp>
18 #include <boost/log/attributes/scoped_attribute.hpp>
20 namespace logging
= boost::log
;
21 namespace src
= boost::log::sources
;
22 namespace expr
= boost::log::expressions
;
23 namespace sinks
= boost::log::sinks
;
24 namespace keywords
= boost::log::keywords
;
26 //[ example_sinks_multifile
29 boost::shared_ptr
< logging::core
> core
= logging::core::get();
31 boost::shared_ptr
< sinks::text_multifile_backend
> backend
=
32 boost::make_shared
< sinks::text_multifile_backend
>();
34 // Set up the file naming pattern
35 backend
->set_file_name_composer
37 sinks::file::as_file_name_composer(expr::stream
<< "logs/" << expr::attr
< std::string
>("RequestID") << ".log")
40 // Wrap it into the frontend and register in the core.
41 // The backend requires synchronization in the frontend.
42 typedef sinks::synchronous_sink
< sinks::text_multifile_backend
> sink_t
;
43 boost::shared_ptr
< sink_t
> sink(new sink_t(backend
));
49 << "[RequestID: " << expr::attr
< std::string
>("RequestID")
50 << "] " << expr::smessage
57 void logging_function()
60 BOOST_LOG(lg
) << "Hello, world!";
63 int main(int, char*[])
68 BOOST_LOG_SCOPED_THREAD_TAG("RequestID", "Request1");
72 BOOST_LOG_SCOPED_THREAD_TAG("RequestID", "Request2");