1 /******************************************************************
3 * Copyright 2017 - 2020 Samsung Electronics All Rights Reserved.
5 * Author: Jaroslaw Pelczar <j.pelczar@samsung.com>
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 #ifndef SHARED_BOOST_LOG_DLOG_SINK_H_
22 #define SHARED_BOOST_LOG_DLOG_SINK_H_
24 #include <boost/log/sinks.hpp>
29 template<typename AttributeValueT = int> class dlog_direct_severity_mapping :
30 public boost::log::sinks::basic_direct_mapping<log_priority, AttributeValueT>
32 typedef boost::log::sinks::basic_direct_mapping<log_priority, AttributeValueT> base_type;
34 explicit dlog_direct_severity_mapping(boost::log::attribute_name const& name) :
40 template<typename AttributeValueT = int> class dlog_custom_severity_mapping :
41 public boost::log::sinks::basic_custom_mapping<log_priority, AttributeValueT>
43 typedef boost::log::sinks::basic_custom_mapping<log_priority, AttributeValueT> base_type;
45 explicit dlog_custom_severity_mapping(boost::log::attribute_name const& name) :
46 base_type(name, DLOG_DEBUG)
51 class dlog_output_backend :
52 public boost::log::sinks::basic_formatted_sink_backend<char>
54 typedef boost::log::sinks::basic_formatted_sink_backend<char> base_type;
55 typedef std::function< log_priority (boost::log::record_view const&) > severity_mapper_type;
58 std::string log_domain_;
59 severity_mapper_type level_mapper_;
61 inline void send(log_priority level, string_type const& formatted_message) {
62 dlog_print(level, log_domain_.c_str(), "%s", formatted_message.c_str());
70 void consume(boost::log::record_view const& rec, string_type const& formatted_message) {
72 send(DLOG_DEBUG, formatted_message);
74 send(level_mapper_(rec), formatted_message);
78 void set_log_domain(const std::string& name)
83 void set_severity_mapper(severity_mapper_type const& mapper)
85 level_mapper_ = mapper;
89 #endif /* SHARED_BOOST_LOG_DLOG_SINK_H_ */