diff options
Diffstat (limited to 'implementation/logging/src')
-rw-r--r-- | implementation/logging/src/dlt_sink_backend.cpp | 66 | ||||
-rw-r--r-- | implementation/logging/src/logger_impl.cpp | 9 |
2 files changed, 74 insertions, 1 deletions
diff --git a/implementation/logging/src/dlt_sink_backend.cpp b/implementation/logging/src/dlt_sink_backend.cpp new file mode 100644 index 0000000..b4d2864 --- /dev/null +++ b/implementation/logging/src/dlt_sink_backend.cpp @@ -0,0 +1,66 @@ +// Copyright (C) 2014-2015 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/dlt_sink_backend.hpp" + +#ifdef USE_DLT +#include <dlt/dlt.h> +#endif + +#include <boost/log/expressions.hpp> + +namespace expressions = boost::log::expressions; + +namespace vsomeip +{ + +dlt_sink_backend::dlt_sink_backend() { +#ifdef USE_DLT + DLT_REGISTER_APP("vSIP", "vSomeIP application"); + DLT_REGISTER_CONTEXT(dlt_, "vSIP", "vSomeIP context"); +#endif +} + +dlt_sink_backend::~dlt_sink_backend() { +#ifdef USE_DLT + DLT_UNREGISTER_CONTEXT(dlt_); + DLT_UNREGISTER_APP(); +#endif +} + +BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", logging::trivial::severity_level) + +void dlt_sink_backend::consume(const logging::record_view &rec) { +#ifdef USE_DLT + std::string message = *rec[expressions::smessage]; + logging::trivial::severity_level severity_level = *rec[severity]; + DLT_LOG_STRING(dlt_, level_as_dlt(severity_level), message.c_str()); +#else + (void)rec; +#endif +} + +#ifdef USE_DLT +DltLogLevelType dlt_sink_backend::level_as_dlt(logging::trivial::severity_level _level) { + switch (_level) { + case logging::trivial::fatal: + return DLT_LOG_FATAL; + case logging::trivial::error: + return DLT_LOG_ERROR; + case logging::trivial::warning: + return DLT_LOG_WARN; + case logging::trivial::info: + return DLT_LOG_INFO; + case logging::trivial::debug: + return DLT_LOG_DEBUG; + case logging::trivial::trace: + return DLT_LOG_VERBOSE; + default: + return DLT_LOG_DEFAULT; + } +} +#endif + +} /* namespace vsomeip */ diff --git a/implementation/logging/src/logger_impl.cpp b/implementation/logging/src/logger_impl.cpp index ef98749..6bf4e08 100644 --- a/implementation/logging/src/logger_impl.cpp +++ b/implementation/logging/src/logger_impl.cpp @@ -124,7 +124,14 @@ void logger_impl::enable_file(const std::string &_path) { }
void logger_impl::enable_dlt() {
- // TODO: implement
+#ifdef USE_DLT
+ if (dlt_sink_)
+ return;
+
+ boost::shared_ptr<dlt_sink_backend> backend = boost::make_shared<dlt_sink_backend>();
+ dlt_sink_ = boost::make_shared<dlt_sink_t>(backend);
+ logging::core::get()->add_sink(dlt_sink_);
+#endif
}
void logger_impl::use_null_logger() {
|