| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // \copyright | ||
| 2 | // Copyright 2009-2015, by the California Institute of Technology. | ||
| 3 | // ALL RIGHTS RESERVED. United States Government Sponsorship | ||
| 4 | // acknowledged. | ||
| 5 | |||
| 6 | #include <Fw/Logger/Logger.hpp> | ||
| 7 | #include <Fw/Types/Assert.hpp> | ||
| 8 | #include <Svc/ActiveTextLogger/ActiveTextLogger.hpp> | ||
| 9 | #include <ctime> | ||
| 10 | |||
| 11 | namespace Svc { | ||
| 12 | static_assert(std::numeric_limits<FwSizeType>::max() >= ACTIVE_TEXT_LOGGER_ID_FILTER_SIZE, | ||
| 13 | "ACTIVE_TEXT_LOGGER_ID_FILTER_SIZE must fit within range of FwSizeType"); | ||
| 14 | |||
| 15 | // ---------------------------------------------------------------------- | ||
| 16 | // Initialization/Exiting | ||
| 17 | // ---------------------------------------------------------------------- | ||
| 18 | |||
| 19 | 5 | ActiveTextLogger::ActiveTextLogger(const char* name) | |
| 20 |
2/2✓ Branch 10 taken 5 times.
✓ Branch 21 taken 5 times.
|
5 | : ActiveTextLoggerComponentBase(name), m_log_file(), m_numFilteredIDs(0), m_severityFilter() { |
| 21 | // Set severity filter defaults from config | ||
| 22 |
2/2✓ Branch 5 taken 5 times.
✓ Branch 8 taken 5 times.
|
5 | this->m_severityFilter.setFilter(Fw::LogSeverity::WARNING_HI, ACTIVE_TEXT_LOGGER_FILTER_WARNING_HI_DEFAULT); |
| 23 |
2/2✓ Branch 5 taken 5 times.
✓ Branch 8 taken 5 times.
|
5 | this->m_severityFilter.setFilter(Fw::LogSeverity::WARNING_LO, ACTIVE_TEXT_LOGGER_FILTER_WARNING_LO_DEFAULT); |
| 24 |
2/2✓ Branch 5 taken 5 times.
✓ Branch 8 taken 5 times.
|
5 | this->m_severityFilter.setFilter(Fw::LogSeverity::COMMAND, ACTIVE_TEXT_LOGGER_FILTER_COMMAND_DEFAULT); |
| 25 |
2/2✓ Branch 5 taken 5 times.
✓ Branch 8 taken 5 times.
|
5 | this->m_severityFilter.setFilter(Fw::LogSeverity::ACTIVITY_HI, ACTIVE_TEXT_LOGGER_FILTER_ACTIVITY_HI_DEFAULT); |
| 26 |
2/2✓ Branch 5 taken 5 times.
✓ Branch 8 taken 5 times.
|
5 | this->m_severityFilter.setFilter(Fw::LogSeverity::ACTIVITY_LO, ACTIVE_TEXT_LOGGER_FILTER_ACTIVITY_LO_DEFAULT); |
| 27 |
2/2✓ Branch 5 taken 5 times.
✓ Branch 8 taken 5 times.
|
5 | this->m_severityFilter.setFilter(Fw::LogSeverity::DIAGNOSTIC, ACTIVE_TEXT_LOGGER_FILTER_DIAGNOSTIC_DEFAULT); |
| 28 | 5 | } | |
| 29 | |||
| 30 | 10 | ActiveTextLogger::~ActiveTextLogger() {} | |
| 31 | |||
| 32 | ✗ | void ActiveTextLogger::configure(const FwEventIdType* filteredIds, FwSizeType count) { | |
| 33 | ✗ | FW_ASSERT(filteredIds != nullptr || count == 0); | |
| 34 | ✗ | FW_ASSERT(count <= ACTIVE_TEXT_LOGGER_ID_FILTER_SIZE, static_cast<FwAssertArgType>(count), | |
| 35 | ACTIVE_TEXT_LOGGER_ID_FILTER_SIZE); | ||
| 36 | |||
| 37 | ✗ | this->m_numFilteredIDs = count; | |
| 38 | ✗ | for (FwSizeType entry = 0; entry < count; entry++) { | |
| 39 | ✗ | this->m_filteredIDs[entry] = filteredIds[entry]; | |
| 40 | } | ||
| 41 | ✗ | } | |
| 42 | |||
| 43 | 4 | void ActiveTextLogger::setSeverityFilter(Fw::LogSeverity severity, bool enabled) { | |
| 44 |
2/2✓ Branch 5 taken 4 times.
✓ Branch 8 taken 4 times.
|
4 | this->m_severityFilter.setFilter(severity, enabled); |
| 45 | 4 | } | |
| 46 | |||
| 47 | // ---------------------------------------------------------------------- | ||
| 48 | // Handlers to implement for typed input ports | ||
| 49 | // ---------------------------------------------------------------------- | ||
| 50 | |||
| 51 | 12 | void ActiveTextLogger::TextLogger_handler(FwIndexType portNum, | |
| 52 | FwEventIdType id, | ||
| 53 | Fw::Time& timeTag, | ||
| 54 | const Fw::LogSeverity& severity, | ||
| 55 | Fw::TextLogString& text) { | ||
| 56 | // Check severity filter | ||
| 57 |
4/4✓ Branch 5 taken 12 times.
✓ Branch 8 taken 12 times.
✓ Branch 13 taken 2 times.
✓ Branch 14 taken 10 times.
|
12 | if (this->m_severityFilter.isFiltered(severity)) { |
| 58 | 2 | return; | |
| 59 | } | ||
| 60 | |||
| 61 | // Check event ID filters | ||
| 62 |
1/2✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
|
10 | for (FwSizeType i = 0; i < this->m_numFilteredIDs; i++) { |
| 63 | ✗ | if (this->m_filteredIDs[i] == id) { | |
| 64 | ✗ | return; | |
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | // Format the string here, so that it is done in the task context | ||
| 69 | // of the caller. Format doc borrowed from PassiveTextLogger. | ||
| 70 | 10 | const char* severityString = nullptr; | |
| 71 |
6/10✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
10 | switch (severity.e) { |
| 72 | 1 | case Fw::LogSeverity::FATAL: | |
| 73 | 1 | severityString = "FATAL"; | |
| 74 | 1 | break; | |
| 75 | 2 | case Fw::LogSeverity::WARNING_HI: | |
| 76 | 2 | severityString = "WARNING_HI"; | |
| 77 | 2 | break; | |
| 78 | 2 | case Fw::LogSeverity::WARNING_LO: | |
| 79 | 2 | severityString = "WARNING_LO"; | |
| 80 | 2 | break; | |
| 81 | ✗ | case Fw::LogSeverity::COMMAND: | |
| 82 | ✗ | severityString = "COMMAND"; | |
| 83 | ✗ | break; | |
| 84 | 4 | case Fw::LogSeverity::ACTIVITY_HI: | |
| 85 | 4 | severityString = "ACTIVITY_HI"; | |
| 86 | 4 | break; | |
| 87 | 1 | case Fw::LogSeverity::ACTIVITY_LO: | |
| 88 | 1 | severityString = "ACTIVITY_LO"; | |
| 89 | 1 | break; | |
| 90 | ✗ | case Fw::LogSeverity::DIAGNOSTIC: | |
| 91 | ✗ | severityString = "DIAGNOSTIC"; | |
| 92 | ✗ | break; | |
| 93 | ✗ | default: | |
| 94 | ✗ | severityString = "SEVERITY ERROR"; | |
| 95 | ✗ | break; | |
| 96 | } | ||
| 97 | 10 | FW_ASSERT(severityString != nullptr); | |
| 98 | // Overflow is allowed and truncation accepted | ||
| 99 |
1/1✓ Branch 2 taken 10 times.
|
20 | Fw::InternalInterfaceString intText; |
| 100 |
3/3✓ Branch 3 taken 10 times.
✓ Branch 6 taken 10 times.
✓ Branch 9 taken 10 times.
|
50 | (void)intText.format("EVENT: (%" PRI_FwEventIdType ") (%" PRI_FwTimeBaseStoreType ":%" PRIu32 ",%" PRIu32 |
| 101 | ") %s: %s\n", | ||
| 102 |
1/1✓ Branch 5 taken 10 times.
|
30 | id, static_cast<FwTimeBaseStoreType>(timeTag.getTimeBase()), timeTag.getSeconds(), |
| 103 | 20 | timeTag.getUSeconds(), severityString, text.toChar()); | |
| 104 | |||
| 105 | // Call internal interface so that everything else is done on component thread, | ||
| 106 | // this helps ensure consistent ordering of the printed text: | ||
| 107 |
1/1✓ Branch 5 taken 10 times.
|
10 | this->TextQueue_internalInterfaceInvoke(intText); |
| 108 | } | ||
| 109 | |||
| 110 | // ---------------------------------------------------------------------- | ||
| 111 | // Internal interface handlers | ||
| 112 | // ---------------------------------------------------------------------- | ||
| 113 | |||
| 114 | 10 | void ActiveTextLogger::TextQueue_internalInterfaceHandler(const Fw::InternalInterfaceString& text) { | |
| 115 | // Print to console: | ||
| 116 | 10 | Fw::Logger::log(text); | |
| 117 | |||
| 118 | // Print to file if there is one: | ||
| 119 | 10 | (void)this->m_log_file.write_to_log(text.toChar(), text.length()); // Ignoring return status | |
| 120 | 10 | } | |
| 121 | |||
| 122 | // ---------------------------------------------------------------------- | ||
| 123 | // Helper Methods | ||
| 124 | // ---------------------------------------------------------------------- | ||
| 125 | |||
| 126 | 21 | bool ActiveTextLogger::set_log_file(const char* fileName, const U32 maxSize, const U32 maxBackups) { | |
| 127 | 21 | FW_ASSERT(fileName != nullptr); | |
| 128 | |||
| 129 | 21 | return this->m_log_file.set_log_file(fileName, maxSize, maxBackups); | |
| 130 | } | ||
| 131 | |||
| 132 | } // namespace Svc | ||
| 133 |