| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * File: Logger.cpp | ||
| 3 | * Description: Framework logging implementation | ||
| 4 | * Author: mstarch | ||
| 5 | * | ||
| 6 | * This file adds in support to the core 'Fw' package, to separate it from Os and other loggers, and | ||
| 7 | * allow the architect of the system to select which core framework logging should be used. | ||
| 8 | */ | ||
| 9 | #include <Fw/Logger/Logger.hpp> | ||
| 10 | #include <Fw/Types/Assert.hpp> | ||
| 11 | #include <Fw/Types/String.hpp> | ||
| 12 | #include <Fw/Types/StringUtils.hpp> | ||
| 13 | #include <cstdarg> | ||
| 14 | #include <limits> | ||
| 15 | |||
| 16 | namespace Fw { | ||
| 17 | |||
| 18 | // Initial logger is NULL | ||
| 19 | Logger* Logger::s_current_logger = nullptr; | ||
| 20 | |||
| 21 | 464 | void Logger::log(const char* format, ...) { | |
| 22 |
1/1✓ Branch 1 taken 464 times.
|
464 | Fw::String formatted_string; |
| 23 | // Forward the variable arguments to the vformat format implementation | ||
| 24 | va_list args; | ||
| 25 | 464 | va_start(args, format); | |
| 26 |
1/1✓ Branch 1 taken 464 times.
|
464 | (void)formatted_string.vformat(format, args); // log string may safely truncate |
| 27 | 464 | va_end(args); | |
| 28 |
1/1✓ Branch 1 taken 464 times.
|
464 | Logger::log(formatted_string); |
| 29 | 464 | } | |
| 30 | |||
| 31 | 464 | void Logger::log(const ConstStringBase& string) { | |
| 32 |
1/2✓ Branch 0 taken 464 times.
✗ Branch 1 not taken.
|
464 | if (Logger::s_current_logger != nullptr) { |
| 33 | 464 | Logger::s_current_logger->writeMessage(string); | |
| 34 | } | ||
| 35 | 464 | } | |
| 36 | |||
| 37 | 1 | void Logger::registerLogger(Logger* logger) { | |
| 38 | 1 | Logger::s_current_logger = logger; | |
| 39 | 1 | } | |
| 40 | |||
| 41 | } // End namespace Fw | ||
| 42 |