blob: d38039c74f287d0036767785b358e1c380c68f1a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// 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/dlt_sink_backend.hpp"
#ifdef USE_DLT
#include <dlt/dlt.h>
#endif
#include <boost/log/expressions.hpp>
#include "../include/defines.hpp"
namespace expressions = boost::log::expressions;
namespace vsomeip_v3
{
dlt_sink_backend::dlt_sink_backend(const std::string &_app_id,
const std::string &_context_id) {
(void)_app_id;
#ifdef USE_DLT
DLT_REGISTER_CONTEXT(dlt_, _context_id.c_str(), VSOMEIP_LOG_DEFAULT_CONTEXT_NAME);
#else
(void)_context_id;
#endif
}
dlt_sink_backend::~dlt_sink_backend() {
#ifdef USE_DLT
DLT_UNREGISTER_CONTEXT(dlt_);
#endif
}
BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", logging::trivial::severity_level)
void dlt_sink_backend::consume(const logging::record_view &rec) {
#ifdef USE_DLT
auto message = rec[expressions::smessage];
auto severity_level = rec[severity];
DLT_LOG_STRING(dlt_, (severity_level)?level_as_dlt(*severity_level):DLT_LOG_WARN,
(message)?message.get<std::string>().c_str():"consume() w/o message");
#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_v3
|