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 
13 // ----------------------------------------------------------------------
14 // Initialization/Exiting
15 // ----------------------------------------------------------------------
16 
17 ActiveTextLogger::ActiveTextLogger(const char* name) : ActiveTextLoggerComponentBase(name), m_log_file() {}
18 
20 
21 // ----------------------------------------------------------------------
22 // Handlers to implement for typed input ports
23 // ----------------------------------------------------------------------
24 
25 void ActiveTextLogger::TextLogger_handler(FwIndexType portNum,
26  FwEventIdType id,
27  Fw::Time& timeTag,
28  const Fw::LogSeverity& severity,
29  Fw::TextLogString& text) {
30  // Currently not doing any input filtering
31  // TKC - 5/3/2018 - remove diagnostic
32  if (Fw::LogSeverity::DIAGNOSTIC == severity.e) {
33  return;
34  }
35 
36  // Format the string here, so that it is done in the task context
37  // of the caller. Format doc borrowed from PassiveTextLogger.
38  const char* severityString = nullptr;
39  switch (severity.e) {
41  severityString = "FATAL";
42  break;
44  severityString = "WARNING_HI";
45  break;
47  severityString = "WARNING_LO";
48  break;
50  severityString = "COMMAND";
51  break;
53  severityString = "ACTIVITY_HI";
54  break;
56  severityString = "ACTIVITY_LO";
57  break;
59  severityString = "DIAGNOSTIC";
60  break;
61  default:
62  severityString = "SEVERITY ERROR";
63  break;
64  }
65  // Overflow is allowed and truncation accepted
67  (void)intText.format("EVENT: (%" PRI_FwEventIdType ") (%" PRI_FwTimeBaseStoreType ":%" PRIu32 ",%" PRIu32
68  ") %s: %s\n",
69  id, static_cast<FwTimeBaseStoreType>(timeTag.getTimeBase()), timeTag.getSeconds(),
70  timeTag.getUSeconds(), severityString, text.toChar());
71 
72  // Call internal interface so that everything else is done on component thread,
73  // this helps ensure consistent ordering of the printed text:
74  this->TextQueue_internalInterfaceInvoke(intText);
75 }
76 
77 // ----------------------------------------------------------------------
78 // Internal interface handlers
79 // ----------------------------------------------------------------------
80 
81 void ActiveTextLogger::TextQueue_internalInterfaceHandler(const Fw::InternalInterfaceString& text) {
82  // Print to console:
83  Fw::Logger::log(text);
84 
85  // Print to file if there is one:
86  (void)this->m_log_file.write_to_log(text.toChar(), text.length()); // Ignoring return status
87 }
88 
89 // ----------------------------------------------------------------------
90 // Helper Methods
91 // ----------------------------------------------------------------------
92 
93 bool ActiveTextLogger::set_log_file(const char* fileName, const U32 maxSize, const U32 maxBackups) {
94  FW_ASSERT(fileName != nullptr);
95 
96  return this->m_log_file.set_log_file(fileName, maxSize, maxBackups);
97 }
98 
99 } // 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
static void log(const char *format,...)
log a formated string with supplied arguments
Definition: Logger.cpp:21
TimeBase getTimeBase() const
Definition: Time.cpp:94
const char * toChar() const
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:86
SizeType length() const
Get length of string.
Definition: StringBase.cpp:121
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:55
Important informational events.
U32 getUSeconds() const
Definition: Time.cpp:90
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.
void TextQueue_internalInterfaceInvoke(const Fw::InternalInterfaceString &text)
Internal interface base-class function for TextQueue.
#define FW_ASSERT(...)
Definition: Assert.hpp:14