2 Copyright (c) 2018-2019 Nokia.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
18 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 * platform project (RICP).
22 #include "private/stdstreamlogger.hpp"
26 #include <boost/iostreams/stream.hpp>
27 #include <boost/iostreams/concepts.hpp>
29 using namespace shareddatalayer;
33 class Sink: public boost::iostreams::sink
36 Sink(const std::string& prefix, int level): prefix(prefix), level(level) { }
40 std::streamsize write(const char* s, std::streamsize n);
43 const std::string prefix;
48 std::streamsize Sink::write(const char* s, std::streamsize n)
51 std::cout << prefix << ": " << std::string(s, n);
53 std::cerr << prefix << ": " << std::string(s, n);
57 StdStreamLogger::StdStreamLogger(const std::string& prefix):
62 StdStreamLogger::~StdStreamLogger()
66 std::ostream& StdStreamLogger::emerg()
68 if (osEmerg == nullptr)
69 osEmerg.reset(new boost::iostreams::stream<Sink>(Sink(prefix, LOG_EMERG)));
73 std::ostream& StdStreamLogger::alert()
75 if (osAlert == nullptr)
76 osAlert.reset(new boost::iostreams::stream<Sink>(Sink(prefix, LOG_ALERT)));
80 std::ostream& StdStreamLogger::crit()
82 if (osCrit == nullptr)
83 osCrit.reset(new boost::iostreams::stream<Sink>(Sink(prefix, LOG_CRIT)));
87 std::ostream& StdStreamLogger::error()
89 if (osError == nullptr)
90 osError.reset(new boost::iostreams::stream<Sink>(Sink(prefix, LOG_ERR)));
94 std::ostream& StdStreamLogger::warning()
96 if (osWarning == nullptr)
97 osWarning.reset(new boost::iostreams::stream<Sink>(Sink(prefix, LOG_WARNING)));
101 std::ostream& StdStreamLogger::notice()
103 if (osNotice == nullptr)
104 osNotice.reset(new boost::iostreams::stream<Sink>(Sink(prefix, LOG_NOTICE)));
108 std::ostream& StdStreamLogger::info()
110 if (osInfo == nullptr)
111 osInfo.reset(new boost::iostreams::stream<Sink>(Sink(prefix, LOG_INFO)));
115 std::ostream& StdStreamLogger::debug()
117 if (osDebug == nullptr)
118 osDebug.reset(new boost::iostreams::stream<Sink>(Sink(prefix, LOG_DEBUG)));