Line data Source code
1 : /********************************************************************************
2 : * Copyright (c) 2026 BMW AG
3 : *
4 : * This program and the accompanying materials are made available under the
5 : * terms of the Apache License Version 2.0 which is available at
6 : * https://www.apache.org/licenses/LICENSE-2.0
7 : *
8 : * SPDX-License-Identifier: Apache-2.0
9 : ********************************************************************************/
10 : #include <climits>
11 : #include <cstdarg>
12 : #include <cstdio>
13 :
14 : #include <etl/span.h>
15 : #include <middleware/logger/Logger.h>
16 :
17 : #include "Logger.h"
18 :
19 : namespace middleware::logger
20 : {
21 :
22 13 : static char const* get_log_level_name(LogLevel level)
23 : {
24 : static char const* level_names[] = {"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "CRITICAL"};
25 13 : auto const idx = static_cast<uint8_t>(level);
26 13 : return (idx > 0U && idx < 7U) ? level_names[idx - 1U] : "UNKNOWN";
27 : }
28 :
29 : // NOLINTBEGIN(cert-dcl50-cpp,cppcoreguidelines-pro-type-vararg,cert-err33-c,clang-analyzer-valist.Uninitialized)
30 13 : void log(LogLevel const level, char const* const f, ...)
31 : {
32 : std::va_list ap;
33 13 : va_start(ap, f);
34 : char msg[PIPE_BUF];
35 13 : (void)vsnprintf(msg, sizeof(msg), f, ap);
36 13 : va_end(ap);
37 : // NOLINTEND(cert-dcl50-cpp,cppcoreguidelines-pro-type-vararg,cert-err33-c,clang-analyzer-valist.Uninitialized)
38 :
39 13 : if (level > LogLevel::None)
40 : {
41 13 : simulation::Logger::log("[", get_log_level_name(level), "] ", msg);
42 : }
43 : else
44 : {
45 0 : simulation::Logger::log(msg);
46 : }
47 13 : }
48 :
49 13 : void logBinary(LogLevel const level, ::etl::span<uint8_t const> const data)
50 : {
51 : (void)level;
52 : (void)data;
53 13 : }
54 :
55 13 : uint32_t getMessageId(Error const id)
56 : {
57 : (void)id;
58 13 : return 0U;
59 : }
60 :
61 : } // namespace middleware::logger
|