summaryrefslogtreecommitdiff
path: root/implementation/logging
diff options
context:
space:
mode:
Diffstat (limited to 'implementation/logging')
-rw-r--r--implementation/logging/include/android_sink_backend.hpp33
-rw-r--r--implementation/logging/include/defines.hpp3
-rw-r--r--implementation/logging/include/dlt_sink_backend.hpp11
-rw-r--r--implementation/logging/include/logger.hpp48
-rw-r--r--implementation/logging/include/logger_impl.hpp147
-rw-r--r--implementation/logging/src/android_sink_backend.cpp66
-rw-r--r--implementation/logging/src/dlt_sink_backend.cpp4
-rw-r--r--implementation/logging/src/logger.cpp28
-rw-r--r--implementation/logging/src/logger_impl.cpp402
9 files changed, 408 insertions, 334 deletions
diff --git a/implementation/logging/include/android_sink_backend.hpp b/implementation/logging/include/android_sink_backend.hpp
new file mode 100644
index 0000000..defda48
--- /dev/null
+++ b/implementation/logging/include/android_sink_backend.hpp
@@ -0,0 +1,33 @@
+// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef VSOMEIP_V3_ANDROID_SINK_BACKEND_HPP_
+#define VSOMEIP_V3_ANDROID_SINK_BACKEND_HPP_
+
+#include <boost/log/core.hpp>
+#include <boost/log/sinks/basic_sink_backend.hpp>
+#include <boost/log/trivial.hpp>
+
+namespace logging = boost::log;
+namespace sinks = boost::log::sinks;
+
+namespace vsomeip_v3 {
+
+class android_sink_backend :
+ public sinks::basic_sink_backend<
+ sinks::combine_requirements<
+ sinks::synchronized_feeding
+ >::type
+ > {
+public:
+ android_sink_backend();
+ virtual ~android_sink_backend();
+
+ void consume(const logging::record_view &rec);
+};
+
+} // namespace vsomeip_v3
+
+#endif // VSOMEIP_V3_ANDROID_SINK_BACKEND_HPP_
diff --git a/implementation/logging/include/defines.hpp b/implementation/logging/include/defines.hpp
index 1fbaa3c..de5142d 100644
--- a/implementation/logging/include/defines.hpp
+++ b/implementation/logging/include/defines.hpp
@@ -6,9 +6,6 @@
#ifndef LOGGING_DEFINES_HPP_
#define LOGGING_DEFINES_HPP_
-#define VSOMEIP_LOG_DEFAULT_APPLICATION_ID "VSIP"
-#define VSOMEIP_LOG_DEFAULT_APPLICATION_NAME "vSomeIP application|SysInfra|IPC"
-
#define VSOMEIP_LOG_DEFAULT_CONTEXT_ID "VSIP"
#define VSOMEIP_LOG_DEFAULT_CONTEXT_NAME "vSomeIP context"
diff --git a/implementation/logging/include/dlt_sink_backend.hpp b/implementation/logging/include/dlt_sink_backend.hpp
index 58983a6..73a9e79 100644
--- a/implementation/logging/include/dlt_sink_backend.hpp
+++ b/implementation/logging/include/dlt_sink_backend.hpp
@@ -3,8 +3,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-#ifndef LOGGING_INCLUDE_DLT_SINK_BACKEND_HPP_
-#define LOGGING_INCLUDE_DLT_SINK_BACKEND_HPP_
+#ifndef VSOMEIP_V3_DLT_SINK_BACKEND_HPP_
+#define VSOMEIP_V3_DLT_SINK_BACKEND_HPP_
#ifdef USE_DLT
#include <dlt/dlt.h>
@@ -17,8 +17,7 @@
namespace logging = boost::log;
namespace sinks = boost::log::sinks;
-namespace vsomeip
-{
+namespace vsomeip_v3 {
class dlt_sink_backend :
public sinks::basic_sink_backend<
@@ -41,6 +40,6 @@ private:
#endif
};
-} /* namespace vsomeip */
+} // namespace vsomeip_v3
-#endif /* LOGGING_INCLUDE_DLT_SINK_BACKEND_HPP_ */
+#endif // VSOMEIP_V3_DLT_SINK_BACKEND_HPP_
diff --git a/implementation/logging/include/logger.hpp b/implementation/logging/include/logger.hpp
deleted file mode 100644
index 9204692..0000000
--- a/implementation/logging/include/logger.hpp
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-#ifndef VSOMEIP_LOGGER_HPP
-#define VSOMEIP_LOGGER_HPP
-
-#include <string>
-
-#ifdef _WIN32
-#include <iostream>
-#endif
-
-#include <vsomeip/export.hpp>
-
-#include <boost/log/sources/severity_logger.hpp>
-#include <boost/log/trivial.hpp>
-
-namespace vsomeip {
-
-class VSOMEIP_IMPORT_EXPORT logger {
-public:
- static std::shared_ptr<logger> get();
-
- virtual ~logger() {
- }
-
- virtual boost::log::sources::severity_logger_mt<
- boost::log::trivial::severity_level> & get_internal() = 0;
-};
-
-#define VSOMEIP_FATAL BOOST_LOG_SEV(vsomeip::logger::get()->get_internal(), \
- boost::log::trivial::severity_level::fatal)
-#define VSOMEIP_ERROR BOOST_LOG_SEV(vsomeip::logger::get()->get_internal(), \
- boost::log::trivial::severity_level::error)
-#define VSOMEIP_WARNING BOOST_LOG_SEV(vsomeip::logger::get()->get_internal(), \
- boost::log::trivial::severity_level::warning)
-#define VSOMEIP_INFO BOOST_LOG_SEV(vsomeip::logger::get()->get_internal(), \
- boost::log::trivial::severity_level::info)
-#define VSOMEIP_DEBUG BOOST_LOG_SEV(vsomeip::logger::get()->get_internal(), \
- boost::log::trivial::severity_level::debug)
-#define VSOMEIP_TRACE BOOST_LOG_SEV(vsomeip::logger::get()->get_internal(), \
- boost::log::trivial::severity_level::trace)
-
-} // namespace vsomeip
-
-#endif // VSOMEIP_LOGGER_HPP
diff --git a/implementation/logging/include/logger_impl.hpp b/implementation/logging/include/logger_impl.hpp
index 4e628af..4556f0d 100644
--- a/implementation/logging/include/logger_impl.hpp
+++ b/implementation/logging/include/logger_impl.hpp
@@ -1,70 +1,77 @@
-// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-#ifndef VSOMEIP_LOGGER_IMPL_HPP
-#define VSOMEIP_LOGGER_IMPL_HPP
-
-#include <memory>
-#include <string>
-
-#include <boost/log/sinks/sync_frontend.hpp>
-#include <boost/log/sinks/text_ostream_backend.hpp>
-#include <boost/log/sources/severity_logger.hpp>
-#include <boost/log/trivial.hpp>
-
-#include "logger.hpp"
-#include "dlt_sink_backend.hpp"
-
-namespace vsomeip {
-
-class configuration;
-
-BOOST_LOG_ATTRIBUTE_KEYWORD(channel, "Channel", std::string)
-BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity",
- boost::log::trivial::severity_level)
-
-typedef boost::log::sinks::synchronous_sink<
- boost::log::sinks::text_ostream_backend> sink_t;
-typedef boost::log::sinks::synchronous_sink<
- dlt_sink_backend> dlt_sink_t;
-
-class logger_impl: public logger {
-public:
- static std::shared_ptr<logger_impl> & get();
- VSOMEIP_IMPORT_EXPORT static void init(const std::shared_ptr<configuration> &_configuration);
-
- logger_impl();
-
- boost::log::sources::severity_logger_mt<
- boost::log::trivial::severity_level> & get_internal();
-
-private:
- void enable_console();
- void disable_console();
-
- void enable_file(const std::string &_path);
- void disable_file();
-
- void enable_dlt(const std::string &_app_id,
- const std::string &_context_id);
- void disable_dlt();
-
-private:
- boost::log::sources::severity_logger_mt<
- boost::log::trivial::severity_level> logger_;
- boost::log::trivial::severity_level loglevel_;
-
- boost::shared_ptr<sink_t> console_sink_;
- boost::shared_ptr<sink_t> file_sink_;
- boost::shared_ptr<dlt_sink_t> dlt_sink_;
- boost::log::core_ptr log_core_;
-
-private:
- void use_null_logger();
-};
-
-} // namespace vsomeip
-
-#endif // VSOMEIP_INTERNAL_LOG_OWNER_HPP
+// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef VSOMEIP_V3_LOGGER_IMPL_HPP
+#define VSOMEIP_V3_LOGGER_IMPL_HPP
+
+#include <memory>
+#include <string>
+
+#include <boost/log/sinks/sync_frontend.hpp>
+#include <boost/log/sinks/text_ostream_backend.hpp>
+#include <boost/log/sources/severity_logger.hpp>
+#include <boost/log/trivial.hpp>
+
+#include <vsomeip/internal/logger.hpp>
+#include "dlt_sink_backend.hpp"
+#include "android_sink_backend.hpp"
+
+namespace vsomeip_v3 {
+
+class configuration;
+
+BOOST_LOG_ATTRIBUTE_KEYWORD(channel, "Channel", std::string)
+BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity",
+ boost::log::trivial::severity_level)
+
+typedef boost::log::sinks::synchronous_sink<
+ boost::log::sinks::text_ostream_backend> sink_t;
+typedef boost::log::sinks::synchronous_sink<
+ dlt_sink_backend> dlt_sink_t;
+typedef boost::log::sinks::synchronous_sink<
+ android_sink_backend> android_sink_t;
+
+class logger_impl: public logger {
+public:
+ static std::shared_ptr<logger_impl> & get();
+ VSOMEIP_IMPORT_EXPORT static void init(const std::shared_ptr<configuration> &_configuration);
+
+ logger_impl();
+
+ boost::log::sources::severity_logger_mt<
+ boost::log::trivial::severity_level> & get_internal();
+
+private:
+ void enable_console();
+ void disable_console();
+
+ void enable_file(const std::string &_path);
+ void disable_file();
+
+ void enable_dlt(const std::string &_app_id,
+ const std::string &_context_id);
+ void disable_dlt();
+
+ void enable_android();
+ void disable_android();
+
+private:
+ boost::log::sources::severity_logger_mt<
+ boost::log::trivial::severity_level> logger_;
+ boost::log::trivial::severity_level loglevel_;
+
+ boost::shared_ptr<sink_t> console_sink_;
+ boost::shared_ptr<sink_t> file_sink_;
+ boost::shared_ptr<dlt_sink_t> dlt_sink_;
+ boost::shared_ptr<android_sink_t> android_sink_;
+ boost::log::core_ptr log_core_;
+
+private:
+ void use_null_logger();
+};
+
+} // namespace vsomeip_v3
+
+#endif // VSOMEIP_V3_LOGGER_IMPL_HPP
diff --git a/implementation/logging/src/android_sink_backend.cpp b/implementation/logging/src/android_sink_backend.cpp
new file mode 100644
index 0000000..bde7afb
--- /dev/null
+++ b/implementation/logging/src/android_sink_backend.cpp
@@ -0,0 +1,66 @@
+// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include "../include/android_sink_backend.hpp"
+
+#define LOG_TAG "vSomeIP"
+
+#ifdef ANDROID
+#include <utils/Log.h>
+#endif
+
+#include <boost/log/expressions.hpp>
+#include "../include/defines.hpp"
+
+namespace expressions = boost::log::expressions;
+
+namespace vsomeip_v3
+{
+
+android_sink_backend::android_sink_backend() {
+
+}
+
+android_sink_backend::~android_sink_backend() {
+
+}
+
+BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", logging::trivial::severity_level)
+
+void android_sink_backend::consume(const logging::record_view &rec) {
+#ifdef ANDROID
+ auto message = rec[expressions::smessage].get<std::string>().c_str();
+ auto severity_level = rec[severity];
+
+ switch (*severity_level) {
+ case logging::trivial::fatal:
+ ALOGE(message);
+ break;
+ case logging::trivial::error:
+ ALOGE(message);
+ break;
+ case logging::trivial::warning:
+ ALOGW(message);
+ break;
+ case logging::trivial::info:
+ ALOGI(message);
+ break;
+ case logging::trivial::debug:
+ ALOGD(message);
+ break;
+ case logging::trivial::trace:
+ ALOGV(message);
+ break;
+ default:
+ ALOGI(message);
+ break;
+ }
+
+#else
+ (void)rec;
+#endif
+}
+
+} // namespace vsomeip_v3
diff --git a/implementation/logging/src/dlt_sink_backend.cpp b/implementation/logging/src/dlt_sink_backend.cpp
index 5b140fd..d38039c 100644
--- a/implementation/logging/src/dlt_sink_backend.cpp
+++ b/implementation/logging/src/dlt_sink_backend.cpp
@@ -14,7 +14,7 @@
namespace expressions = boost::log::expressions;
-namespace vsomeip
+namespace vsomeip_v3
{
dlt_sink_backend::dlt_sink_backend(const std::string &_app_id,
@@ -67,4 +67,4 @@ DltLogLevelType dlt_sink_backend::level_as_dlt(logging::trivial::severity_level
}
#endif
-} /* namespace vsomeip */
+} // namespace vsomeip_v3
diff --git a/implementation/logging/src/logger.cpp b/implementation/logging/src/logger.cpp
index 630362d..9e22fd0 100644
--- a/implementation/logging/src/logger.cpp
+++ b/implementation/logging/src/logger.cpp
@@ -1,14 +1,14 @@
-// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-#include "../include/logger_impl.hpp"
-
-namespace vsomeip {
-
-std::shared_ptr<logger> logger::get() {
- return logger_impl::get();
-}
-
-} // namespace vsomeip
+// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include "../include/logger_impl.hpp"
+
+namespace vsomeip_v3 {
+
+std::shared_ptr<logger> logger::get() {
+ return logger_impl::get();
+}
+
+} // namespace vsomeip_v3l
diff --git a/implementation/logging/src/logger_impl.cpp b/implementation/logging/src/logger_impl.cpp
index 023dccf..ec3aa9b 100644
--- a/implementation/logging/src/logger_impl.cpp
+++ b/implementation/logging/src/logger_impl.cpp
@@ -1,191 +1,211 @@
-// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-#include <fstream>
-
-#include <boost/log/core.hpp>
-#include <boost/log/expressions.hpp>
-#include <boost/log/sources/logger.hpp>
-#include <boost/log/support/date_time.hpp>
-#include <boost/log/utility/setup/console.hpp>
-#include <boost/log/utility/setup/file.hpp>
-#include <boost/log/utility/setup/common_attributes.hpp>
-#include <boost/log/utility/exception_handler.hpp>
-#include <boost/phoenix/bind/bind_member_function.hpp>
-#include <boost/shared_ptr.hpp>
-
-// The "empty_deleter"-struct was moved from the log-package
-// to the more generic "utility"-package in V1.55. If we'd
-// use the "old" include, we get a "deprecation" warning
-// when compiling with the newer boost version. Therefore a
-// version dependent include handling is done here, which
-// can/should be removed in case GPT is updating Boost to V1.55.
-#if BOOST_VERSION < 105500
-#include <boost/log/utility/empty_deleter.hpp>
-#elif BOOST_VERSION < 105600
-#include <boost/utility/empty_deleter.hpp>
-#else
-#include <boost/core/null_deleter.hpp>
-#endif
-
-#include <vsomeip/runtime.hpp>
-
-#include "../include/logger_impl.hpp"
-#include "../../configuration/include/configuration.hpp"
-#include "../include/defines.hpp"
-
-namespace logging = boost::log;
-namespace sources = boost::log::sources;
-namespace sinks = boost::log::sinks;
-namespace keywords = boost::log::keywords;
-namespace expressions = boost::log::expressions;
-namespace attributes = boost::log::attributes;
-
-using namespace boost::log::trivial;
-
-namespace vsomeip {
-
-std::shared_ptr<logger_impl> & logger_impl::get() {
- static std::shared_ptr<logger_impl> the_logger__ = std::make_shared<
- logger_impl>();
- return the_logger__;
-}
-
-logger_impl::logger_impl()
- : loglevel_(debug),
- log_core_(logging::core::get()) {
- logging::add_common_attributes();
-}
-
-boost::log::sources::severity_logger_mt<boost::log::trivial::severity_level> &
-logger_impl::get_internal() {
- return logger_;
-}
-
-void logger_impl::init(const std::shared_ptr<configuration> &_configuration) {
- get()->loglevel_ = _configuration->get_loglevel();
- logging::core::get()->set_exception_handler(boost::log::make_exception_suppressor());
- logging::core::get()->set_filter(
- logging::trivial::severity >= get()->loglevel_);
-
- if (_configuration->has_console_log())
- get()->enable_console();
- else
- get()->disable_console();
-
- if (_configuration->has_file_log())
- get()->enable_file(_configuration->get_logfile());
- else
- get()->disable_file();
-
- if (_configuration->has_dlt_log()) {
- std::string app_id = runtime::get_property("LogApplication");
- if (app_id == "") app_id = VSOMEIP_LOG_DEFAULT_APPLICATION_ID;
- std::string context_id = runtime::get_property("LogContext");
- if (context_id == "") context_id = VSOMEIP_LOG_DEFAULT_CONTEXT_ID;
- get()->enable_dlt(app_id, context_id);
- } else
- get()->disable_dlt();
-
- if (!_configuration->has_console_log() &&
- !_configuration->has_file_log() &&
- !_configuration->has_dlt_log()) {
- get()->use_null_logger();
- }
-}
-
-void logger_impl::enable_console() {
- if (console_sink_)
- return;
-
- auto vsomeip_log_format = expressions::stream
- << expressions::format_date_time<boost::posix_time::ptime>(
- "TimeStamp", "%Y-%m-%d %H:%M:%S.%f") << " ["
- << expressions::attr<severity_level>("Severity") << "] "
- << expressions::smessage;
-
- boost::shared_ptr<sinks::text_ostream_backend> backend = boost::make_shared<
- sinks::text_ostream_backend>();
- backend->add_stream(boost::shared_ptr<std::ostream>(&std::clog,
-#if BOOST_VERSION < 105500
- boost::log::empty_deleter()
-#elif BOOST_VERSION < 105600
- boost::empty_deleter()
-#else
- boost::null_deleter()
-#endif
- ));
-
- console_sink_ = boost::make_shared<sink_t>(backend);
- console_sink_->set_formatter(vsomeip_log_format);
- logging::core::get()->add_sink(console_sink_);
-}
-
-void logger_impl::disable_console() {
- if (console_sink_)
- logging::core::get()->remove_sink(console_sink_);
-}
-
-void logger_impl::enable_file(const std::string &_path) {
- if (file_sink_)
- return;
-
- auto vsomeip_log_format = expressions::stream
- << expressions::format_date_time<boost::posix_time::ptime>(
- "TimeStamp", "%Y-%m-%d %H:%M:%S.%f") << " ["
- << expressions::attr<severity_level>("Severity") << "] "
- << expressions::smessage;
-
- boost::shared_ptr<sinks::text_ostream_backend> backend = boost::make_shared<
- sinks::text_ostream_backend>();
- backend->add_stream(
- boost::shared_ptr<std::ostream>(
- boost::make_shared<std::ofstream>(_path)));
-
- file_sink_ = boost::make_shared<sink_t>(backend);
- file_sink_->set_formatter(vsomeip_log_format);
- logging::core::get()->add_sink(file_sink_);
-}
-
-void logger_impl::disable_file() {
- if (file_sink_)
- logging::core::get()->remove_sink(file_sink_);
-}
-
-
-void logger_impl::enable_dlt(const std::string &_app_id,
- const std::string &_context_id) {
-#ifdef USE_DLT
- if (dlt_sink_)
- return;
-
- boost::shared_ptr<dlt_sink_backend> backend = boost::make_shared<dlt_sink_backend>(_app_id,
- _context_id);
- dlt_sink_ = boost::make_shared<dlt_sink_t>(backend);
- logging::core::get()->add_sink(dlt_sink_);
-#else
- (void)_app_id;
- (void)_context_id;
-#endif
-}
-
-void logger_impl::disable_dlt() {
- if (dlt_sink_)
- logging::core::get()->remove_sink(dlt_sink_);
-}
-
-void logger_impl::use_null_logger() {
- boost::shared_ptr<sinks::text_ostream_backend> backend = boost::make_shared<
- sinks::text_ostream_backend>();
- backend->add_stream(
- boost::shared_ptr<std::ostream>(new std::ofstream("/dev/null") // TODO: how to call this on windows
- ));
-
- file_sink_ = boost::make_shared<sink_t>(backend);
- logging::core::get()->add_sink(file_sink_);
-}
-
-} // namespace vsomeip
-
+// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <fstream>
+
+#include <boost/log/core.hpp>
+#include <boost/log/expressions.hpp>
+#include <boost/log/sources/logger.hpp>
+#include <boost/log/support/date_time.hpp>
+#include <boost/log/utility/setup/console.hpp>
+#include <boost/log/utility/setup/file.hpp>
+#include <boost/log/utility/setup/common_attributes.hpp>
+#include <boost/log/utility/exception_handler.hpp>
+#include <boost/phoenix/bind/bind_member_function.hpp>
+#include <boost/shared_ptr.hpp>
+
+// The "empty_deleter"-struct was moved from the log-package
+// to the more generic "utility"-package in V1.55. If we'd
+// use the "old" include, we get a "deprecation" warning
+// when compiling with the newer boost version. Therefore a
+// version dependent include handling is done here, which
+// can/should be removed in case GPT is updating Boost to V1.55.
+#if BOOST_VERSION < 105500
+#include <boost/log/utility/empty_deleter.hpp>
+#elif BOOST_VERSION < 105600
+#include <boost/utility/empty_deleter.hpp>
+#else
+#include <boost/core/null_deleter.hpp>
+#endif
+
+#include <vsomeip/runtime.hpp>
+
+#include "../include/logger_impl.hpp"
+#include "../../configuration/include/configuration.hpp"
+#include "../include/defines.hpp"
+
+namespace logging = boost::log;
+namespace sources = boost::log::sources;
+namespace sinks = boost::log::sinks;
+namespace keywords = boost::log::keywords;
+namespace expressions = boost::log::expressions;
+namespace attributes = boost::log::attributes;
+
+using namespace boost::log::trivial;
+
+namespace vsomeip_v3 {
+
+std::shared_ptr<logger_impl> & logger_impl::get() {
+ static std::shared_ptr<logger_impl> the_logger__ = std::make_shared<
+ logger_impl>();
+ return the_logger__;
+}
+
+logger_impl::logger_impl()
+ : loglevel_(debug),
+ log_core_(logging::core::get()) {
+ logging::add_common_attributes();
+}
+
+boost::log::sources::severity_logger_mt<boost::log::trivial::severity_level> &
+logger_impl::get_internal() {
+ return logger_;
+}
+
+void logger_impl::init(const std::shared_ptr<configuration> &_configuration) {
+ get()->loglevel_ = _configuration->get_loglevel();
+ logging::core::get()->set_exception_handler(boost::log::make_exception_suppressor());
+ logging::core::get()->set_filter(
+ logging::trivial::severity >= get()->loglevel_);
+
+ if (_configuration->has_console_log()) {
+ get()->enable_console();
+#ifdef ANDROID
+ get()->enable_android();
+#endif
+ } else {
+ get()->disable_console();
+ }
+
+ if (_configuration->has_file_log())
+ get()->enable_file(_configuration->get_logfile());
+ else
+ get()->disable_file();
+
+ if (_configuration->has_dlt_log()) {
+ std::string app_id = runtime::get_property("LogApplication");
+ if (app_id == "") app_id = VSOMEIP_LOG_DEFAULT_APPLICATION_ID;
+ std::string context_id = runtime::get_property("LogContext");
+ if (context_id == "") context_id = VSOMEIP_LOG_DEFAULT_CONTEXT_ID;
+ get()->enable_dlt(app_id, context_id);
+ } else
+ get()->disable_dlt();
+
+ if (!_configuration->has_console_log() &&
+ !_configuration->has_file_log() &&
+ !_configuration->has_dlt_log()) {
+ get()->use_null_logger();
+ }
+}
+
+void logger_impl::enable_console() {
+ if (console_sink_)
+ return;
+
+ auto vsomeip_log_format = expressions::stream
+ << expressions::format_date_time<boost::posix_time::ptime>(
+ "TimeStamp", "%Y-%m-%d %H:%M:%S.%f") << " ["
+ << expressions::attr<severity_level>("Severity") << "] "
+ << expressions::smessage;
+
+ boost::shared_ptr<sinks::text_ostream_backend> backend = boost::make_shared<
+ sinks::text_ostream_backend>();
+ backend->add_stream(boost::shared_ptr<std::ostream>(&std::clog,
+#if BOOST_VERSION < 105500
+ boost::log::empty_deleter()
+#elif BOOST_VERSION < 105600
+ boost::empty_deleter()
+#else
+ boost::null_deleter()
+#endif
+ ));
+
+ console_sink_ = boost::make_shared<sink_t>(backend);
+ console_sink_->set_formatter(vsomeip_log_format);
+ logging::core::get()->add_sink(console_sink_);
+}
+
+void logger_impl::disable_console() {
+ if (console_sink_)
+ logging::core::get()->remove_sink(console_sink_);
+}
+
+void logger_impl::enable_file(const std::string &_path) {
+ if (file_sink_)
+ return;
+
+ auto vsomeip_log_format = expressions::stream
+ << expressions::format_date_time<boost::posix_time::ptime>(
+ "TimeStamp", "%Y-%m-%d %H:%M:%S.%f") << " ["
+ << expressions::attr<severity_level>("Severity") << "] "
+ << expressions::smessage;
+
+ boost::shared_ptr<sinks::text_ostream_backend> backend = boost::make_shared<
+ sinks::text_ostream_backend>();
+ backend->add_stream(
+ boost::shared_ptr<std::ostream>(
+ boost::make_shared<std::ofstream>(_path)));
+
+ file_sink_ = boost::make_shared<sink_t>(backend);
+ file_sink_->set_formatter(vsomeip_log_format);
+ logging::core::get()->add_sink(file_sink_);
+}
+
+void logger_impl::disable_file() {
+ if (file_sink_)
+ logging::core::get()->remove_sink(file_sink_);
+}
+
+
+void logger_impl::enable_dlt(const std::string &_app_id,
+ const std::string &_context_id) {
+#ifdef USE_DLT
+ if (dlt_sink_)
+ return;
+
+ boost::shared_ptr<dlt_sink_backend> backend = boost::make_shared<dlt_sink_backend>(_app_id,
+ _context_id);
+ dlt_sink_ = boost::make_shared<dlt_sink_t>(backend);
+ logging::core::get()->add_sink(dlt_sink_);
+#else
+ (void)_app_id;
+ (void)_context_id;
+#endif
+}
+
+void logger_impl::disable_dlt() {
+ if (dlt_sink_)
+ logging::core::get()->remove_sink(dlt_sink_);
+}
+
+void logger_impl::enable_android() {
+#ifdef ANDROID
+ if (android_sink_)
+ return;
+
+ boost::shared_ptr<android_sink_backend> backend = boost::make_shared<android_sink_backend>();
+ android_sink_ = boost::make_shared<android_sink_t>(backend);
+ logging::core::get()->add_sink(android_sink_);
+#endif
+}
+
+void logger_impl::disable_android() {
+ if (android_sink_)
+ logging::core::get()->remove_sink(android_sink_);
+}
+
+void logger_impl::use_null_logger() {
+ boost::shared_ptr<sinks::text_ostream_backend> backend = boost::make_shared<
+ sinks::text_ostream_backend>();
+ backend->add_stream(
+ boost::shared_ptr<std::ostream>(new std::ofstream("/dev/null") // TODO: how to call this on windows
+ ));
+
+ file_sink_ = boost::make_shared<sink_t>(backend);
+ logging::core::get()->add_sink(file_sink_);
+}
+
+} // namespace vsomeip_v3
+