From: Tomasz Swierczek Date: Mon, 23 Sep 2019 10:26:37 +0000 (+0200) Subject: Moved boost_log_dlog_sink.h to dcm-daemon subdirectory X-Git-Tag: submit/tizen/20191211.031516~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F05%2F214505%2F2;p=platform%2Fcore%2Fsecurity%2Fdevice-certificate-manager.git Moved boost_log_dlog_sink.h to dcm-daemon subdirectory This file is not re-used between client & daemon. This change should improve SAM score. Change-Id: I6826839da1e37cf9d85813e7de7a13dcc651cf85 --- diff --git a/dcm-daemon/boost_log_dlog_sink.h b/dcm-daemon/boost_log_dlog_sink.h new file mode 100644 index 0000000..625c8c0 --- /dev/null +++ b/dcm-daemon/boost_log_dlog_sink.h @@ -0,0 +1,108 @@ +/****************************************************************** + * + * Copyright 2017 - 2019 Samsung Electronics All Rights Reserved. + * + * Author: Jaroslaw Pelczar + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +#ifndef SHARED_BOOST_LOG_DLOG_SINK_H_ +#define SHARED_BOOST_LOG_DLOG_SINK_H_ + +#include +#include + +#ifdef USE_DLOG_LOGGING +#include +#else +typedef enum { + DLOG_UNKNOWN = 0, /**< Keep this always at the start */ + DLOG_DEFAULT, /**< Default */ + DLOG_VERBOSE, /**< Verbose */ + DLOG_DEBUG, /**< Debug */ + DLOG_INFO, /**< Info */ + DLOG_WARN, /**< Warning */ + DLOG_ERROR, /**< Error */ + DLOG_FATAL, /**< Fatal */ + DLOG_SILENT, /**< Silent */ + DLOG_PRIO_MAX /**< Keep this always at the end. */ +} log_priority; +#endif + +template class dlog_direct_severity_mapping : + public boost::log::sinks::basic_direct_mapping +{ + typedef boost::log::sinks::basic_direct_mapping base_type; +public: + explicit dlog_direct_severity_mapping(boost::log::attribute_name const& name) : + base_type(name) + { + } +}; + +template class dlog_custom_severity_mapping : + public boost::log::sinks::basic_custom_mapping +{ + typedef boost::log::sinks::basic_custom_mapping base_type; +public: + explicit dlog_custom_severity_mapping(boost::log::attribute_name const& name) : + base_type(name, DLOG_DEBUG) + { + } +}; + +class dlog_output_backend : + public boost::log::sinks::basic_formatted_sink_backend +{ + typedef boost::log::sinks::basic_formatted_sink_backend base_type; + typedef std::function< log_priority (boost::log::record_view const&) > severity_mapper_type; + +private: + std::string log_domain_; + severity_mapper_type level_mapper_; + + inline void send(log_priority level, string_type const& formatted_message) { +#ifdef USE_DLOG_LOGGING + dlog_print(level, log_domain_.c_str(), "%s", formatted_message.c_str()); +#else + fprintf(stderr, "%d/(%s): %s\n", level, log_domain_.c_str(), formatted_message.c_str()); +#endif + } + +public: + dlog_output_backend() + { + } + + void consume(boost::log::record_view const& rec, string_type const& formatted_message) { + if(!level_mapper_) { + send(DLOG_DEBUG, formatted_message); + } else { + send(level_mapper_(rec), formatted_message); + } + } + + void set_log_domain(const std::string& name) + { + log_domain_ = name; + } + + void set_severity_mapper(severity_mapper_type const& mapper) + { + level_mapper_ = mapper; + } +}; + +#endif /* SHARED_BOOST_LOG_DLOG_SINK_H_ */ diff --git a/shared/boost_log_dlog_sink.h b/shared/boost_log_dlog_sink.h deleted file mode 100644 index 625c8c0..0000000 --- a/shared/boost_log_dlog_sink.h +++ /dev/null @@ -1,108 +0,0 @@ -/****************************************************************** - * - * Copyright 2017 - 2019 Samsung Electronics All Rights Reserved. - * - * Author: Jaroslaw Pelczar - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ - -#ifndef SHARED_BOOST_LOG_DLOG_SINK_H_ -#define SHARED_BOOST_LOG_DLOG_SINK_H_ - -#include -#include - -#ifdef USE_DLOG_LOGGING -#include -#else -typedef enum { - DLOG_UNKNOWN = 0, /**< Keep this always at the start */ - DLOG_DEFAULT, /**< Default */ - DLOG_VERBOSE, /**< Verbose */ - DLOG_DEBUG, /**< Debug */ - DLOG_INFO, /**< Info */ - DLOG_WARN, /**< Warning */ - DLOG_ERROR, /**< Error */ - DLOG_FATAL, /**< Fatal */ - DLOG_SILENT, /**< Silent */ - DLOG_PRIO_MAX /**< Keep this always at the end. */ -} log_priority; -#endif - -template class dlog_direct_severity_mapping : - public boost::log::sinks::basic_direct_mapping -{ - typedef boost::log::sinks::basic_direct_mapping base_type; -public: - explicit dlog_direct_severity_mapping(boost::log::attribute_name const& name) : - base_type(name) - { - } -}; - -template class dlog_custom_severity_mapping : - public boost::log::sinks::basic_custom_mapping -{ - typedef boost::log::sinks::basic_custom_mapping base_type; -public: - explicit dlog_custom_severity_mapping(boost::log::attribute_name const& name) : - base_type(name, DLOG_DEBUG) - { - } -}; - -class dlog_output_backend : - public boost::log::sinks::basic_formatted_sink_backend -{ - typedef boost::log::sinks::basic_formatted_sink_backend base_type; - typedef std::function< log_priority (boost::log::record_view const&) > severity_mapper_type; - -private: - std::string log_domain_; - severity_mapper_type level_mapper_; - - inline void send(log_priority level, string_type const& formatted_message) { -#ifdef USE_DLOG_LOGGING - dlog_print(level, log_domain_.c_str(), "%s", formatted_message.c_str()); -#else - fprintf(stderr, "%d/(%s): %s\n", level, log_domain_.c_str(), formatted_message.c_str()); -#endif - } - -public: - dlog_output_backend() - { - } - - void consume(boost::log::record_view const& rec, string_type const& formatted_message) { - if(!level_mapper_) { - send(DLOG_DEBUG, formatted_message); - } else { - send(level_mapper_(rec), formatted_message); - } - } - - void set_log_domain(const std::string& name) - { - log_domain_ = name; - } - - void set_severity_mapper(severity_mapper_type const& mapper) - { - level_mapper_ = mapper; - } -}; - -#endif /* SHARED_BOOST_LOG_DLOG_SINK_H_ */