F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ActiveTextLogger.cpp
Go to the documentation of this file.
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>
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 
20  : ActiveTextLoggerComponentBase(name), m_log_file(), m_numFilteredIDs(0) {}
21 
23 
24 void ActiveTextLogger::configure(const FwEventIdType* filteredIds, FwSizeType count) {
25  FW_ASSERT(count < ACTIVE_TEXT_LOGGER_ID_FILTER_SIZE, static_cast<FwAssertArgType>(count),
27 
28  this->m_numFilteredIDs = count;
29  for (FwSizeType entry = 0; entry < count; entry++) {
30  this->m_filteredIDs[entry] = filteredIds[entry];
31  }
32 }
33 
34 // ----------------------------------------------------------------------
35 // Handlers to implement for typed input ports
36 // ----------------------------------------------------------------------
37 
38 void ActiveTextLogger::TextLogger_handler(FwIndexType portNum,
39  FwEventIdType id,
40  Fw::Time& timeTag,
41  const Fw::LogSeverity& severity,
42  Fw::TextLogString& text) {
43  // Currently not doing any input filtering
44  // TKC - 5/3/2018 - remove diagnostic
45  if (Fw::LogSeverity::DIAGNOSTIC == severity.e) {
46  return;
47  }
48  // Check event ID filters
49  for (FwSizeType i = 0; i < this->m_numFilteredIDs; i++) {
50  if (this->m_filteredIDs[i] == id) {
51  return;
52  }
53  }
54 
55  // Format the string here, so that it is done in the task context
56  // of the caller. Format doc borrowed from PassiveTextLogger.
57  const char* severityString = nullptr;
58  switch (severity.e) {
60  severityString = "FATAL";
61  break;
63  severityString = "WARNING_HI";
64  break;
66  severityString = "WARNING_LO";
67  break;
69  severityString = "COMMAND";
70  break;
72  severityString = "ACTIVITY_HI";
73  break;
75  severityString = "ACTIVITY_LO";
76  break;
78  severityString = "DIAGNOSTIC";
79  break;
80  default:
81  severityString = "SEVERITY ERROR";
82  break;
83  }
84  // Overflow is allowed and truncation accepted
86  (void)intText.format("EVENT: (%" PRI_FwEventIdType ") (%" PRI_FwTimeBaseStoreType ":%" PRIu32 ",%" PRIu32
87  ") %s: %s\n",
88  id, static_cast<FwTimeBaseStoreType>(timeTag.getTimeBase()), timeTag.getSeconds(),
89  timeTag.getUSeconds(), severityString, text.toChar());
90 
91  // Call internal interface so that everything else is done on component thread,
92  // this helps ensure consistent ordering of the printed text:
93  this->TextQueue_internalInterfaceInvoke(intText);
94 }
95 
96 // ----------------------------------------------------------------------
97 // Internal interface handlers
98 // ----------------------------------------------------------------------
99 
100 void ActiveTextLogger::TextQueue_internalInterfaceHandler(const Fw::InternalInterfaceString& text) {
101  // Print to console:
102  Fw::Logger::log(text);
103 
104  // Print to file if there is one:
105  (void)this->m_log_file.write_to_log(text.toChar(), text.length()); // Ignoring return status
106 }
107 
108 // ----------------------------------------------------------------------
109 // Helper Methods
110 // ----------------------------------------------------------------------
111 
112 bool ActiveTextLogger::set_log_file(const char* fileName, const U32 maxSize, const U32 maxBackups) {
113  FW_ASSERT(fileName != nullptr);
114 
115  return this->m_log_file.set_log_file(fileName, maxSize, maxBackups);
116 }
117 
118 } // namespace Svc
bool write_to_log(const char *const buf, const FwSizeType size)
Write the passed buf to the log if possible.
Definition: LogFile.cpp:34
void configure(const FwEventIdType *filteredIds, FwSizeType count)
Configure component with event ID filters.
PlatformSizeType FwSizeType
static void log(const char *format,...)
log a formated string with supplied arguments
Definition: Logger.cpp:21
TimeBase getTimeBase() const
Definition: Time.cpp:96
const char * toChar() const
Convert to a C-style char*.
ActiveTextLogger(const char *compName)
Component constructor.
T e
The raw enum value.
Software diagnostic events.
#define PRI_FwEventIdType
FwIdType FwEventIdType
The type of an event identifier.
Less important informational events.
An activity related to commanding.
A less serious but recoverable event.
U32 getSeconds() const
Definition: Time.cpp:88
A serious but recoverable event.
virtual ~ActiveTextLogger()
Component destructor.
bool set_log_file(const char *fileName, const FwSizeType maxSize, const FwSizeType maxBackups=10)
Set log file and max size.
Definition: LogFile.cpp:69
Enum representing event severity.
Auto-generated base for ActiveTextLogger component.
#define PRI_FwTimeBaseStoreType
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:39
Important informational events.
U32 getUSeconds() const
Definition: Time.cpp:92
PlatformIndexType FwIndexType
bool set_log_file(const char *fileName, const U32 maxSize, const U32 maxBackups=10)
Set log file and max size.
A fatal non-recoverable event.
RateGroupDivider component implementation.
virtual SizeType length() const
Get the length of the string.
void TextQueue_internalInterfaceInvoke(const Fw::InternalInterfaceString &text)
Internal interface base-class function for TextQueue.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
const char * toChar() const
Convert to a C-style char*.