]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/log/example/doc/tutorial_file_manual.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / log / example / doc / tutorial_file_manual.cpp
CommitLineData
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 <fstream>
9#include <boost/smart_ptr/shared_ptr.hpp>
10#include <boost/smart_ptr/make_shared_object.hpp>
11#include <boost/log/core.hpp>
12#include <boost/log/trivial.hpp>
13#include <boost/log/sinks/sync_frontend.hpp>
14#include <boost/log/sinks/text_ostream_backend.hpp>
15#include <boost/log/sources/logger.hpp>
16#include <boost/log/sources/record_ostream.hpp>
17
18namespace logging = boost::log;
19namespace src = boost::log::sources;
20namespace sinks = boost::log::sinks;
21
22//[ example_tutorial_file_manual
23void init()
24{
25 // Construct the sink
26 typedef sinks::synchronous_sink< sinks::text_ostream_backend > text_sink;
27 boost::shared_ptr< text_sink > sink = boost::make_shared< text_sink >();
28
29 // Add a stream to write log to
30 sink->locked_backend()->add_stream(
31 boost::make_shared< std::ofstream >("sample.log"));
32
33 // Register the sink in the logging core
34 logging::core::get()->add_sink(sink);
35}
36//]
37
38int main(int, char*[])
39{
40 init();
41
42 src::logger lg;
43 BOOST_LOG(lg) << "Hello world!";
44
45 return 0;
46}