1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "oc_logger.hpp"
29 #include <boost/iostreams/stream.hpp>
30 #include <boost/iostreams/categories.hpp>
32 #include <boost/config.hpp>
33 #include <boost/iostreams/categories.hpp>
34 #include <boost/iostreams/detail/ios.hpp>
38 using OC::oc_log_stream;
40 oc_log_stream ols(oc_make_ostream_logger);
42 boost::iostreams::stream<oc_log_stream> os(ols);
44 os << "Greetings from the nifty world of logging!" << std::flush;
46 ols.set_level(OC_LOG_ALL);
47 ols.set_module("TheHappyModule");
48 ols.set_module("TheModule");
49 os << "Whee!" << std::flush;
51 // Setting the module name by getting the device from the stream itself:
52 (*os).set_module("TheHappiestModuleEver");
53 os << "Whee! Again!" << std::flush;
56 /* Show that we can use a C logger from C++: */
59 using OC::oc_log_stream;
61 oc_log_stream ols(oc_make_console_logger);
63 boost::iostreams::stream<oc_log_stream> os(ols);
65 os << "Greetings from the nifty world of logging!" << std::flush;
67 ols.set_level(OC_LOG_ALL);
68 ols.set_module("TheHappyModule");
69 os << "Whee!" << std::flush;
71 (*os).set_module("TheHappiestModuleEver");
72 os << "Whee!" << std::flush;
75 void alternative_demo()
77 /* Annother way to create a context: */
78 auto logger = []() -> boost::iostreams::stream<OC::oc_log_stream>&
80 static OC::oc_log_stream ols(oc_make_ostream_logger);
81 static boost::iostreams::stream<OC::oc_log_stream> os(ols);
86 logger()->set_module("FantasticModule");
87 logger() << "Hello, logging world!" << std::flush;