F´ Flight Software - C/C++ Documentation  NASA-v1.5.0
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ActiveTextLoggerImpl.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 
7 #include <Fw/Types/Assert.hpp>
8 #include <time.h>
9 
10 namespace Svc {
11 
12  // ----------------------------------------------------------------------
13  // Initialization/Exiting
14  // ----------------------------------------------------------------------
15 
18  m_log_file()
19  {
20 
21  }
22 
24  {
25 
26  }
27 
29  {
30  ActiveTextLoggerComponentBase::init(queueDepth,instance);
31  }
32 
33  // ----------------------------------------------------------------------
34  // Handlers to implement for typed input ports
35  // ----------------------------------------------------------------------
36 
38  FwEventIdType id,
39  Fw::Time &timeTag,
40  Fw::TextLogSeverity severity,
41  Fw::TextLogString &text)
42  {
43 
44  // Currently not doing any input filtering
45  // TKC - 5/3/2018 - remove diagnostic
47  return;
48  }
49 
50  // Format the string here, so that it is done in the task context
51  // of the caller. Format doce borrowed from PassiveTextLogger.
52  const char *severityString = "UNKNOWN";
53  switch (severity) {
54  case Fw::TEXT_LOG_FATAL:
55  severityString = "FATAL";
56  break;
58  severityString = "WARNING_HI";
59  break;
61  severityString = "WARNING_LO";
62  break;
64  severityString = "COMMAND";
65  break;
67  severityString = "ACTIVITY_HI";
68  break;
70  severityString = "ACTIVITY_LO";
71  break;
73  severityString = "DIAGNOSTIC";
74  break;
75  default:
76  severityString = "SEVERITY ERROR";
77  break;
78  }
79 
80  // TODO: Add calling task id to format string
82  NATIVE_INT_TYPE stat;
83 
85 
86  time_t t = timeTag.getSeconds();
87  // Using localtime_r prevents any other calls to localtime (from another thread for example) from
88  // interfering with our time object before we use it. However, the null pointer check is still needed
89  // to ensure a successful call
90  tm tm;
91  if (localtime_r(&t, &tm) == NULL) {
92  return;
93  }
94 
95  stat = snprintf(textStr,
97  "EVENT: (%d) (%04d-%02d-%02dT%02d:%02d:%02d.%03u) %s: %s\n",
98  id, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
99  tm.tm_min,tm.tm_sec,timeTag.getUSeconds(),
100  severityString,text.toChar());
101  }
102  else {
103 
104  stat = snprintf(textStr,
106  "EVENT: (%d) (%d:%d,%d) %s: %s\n",
107  id,timeTag.getTimeBase(),timeTag.getSeconds(),timeTag.getUSeconds(),severityString,text.toChar());
108  }
109 
110  // If there was a error then just return:
111  if (stat <= 0) {
112  return;
113  }
114  // If there was string text truncation:
115  else if (stat >= FW_INTERNAL_INTERFACE_STRING_MAX_SIZE) {
116  // Do nothing
117  }
118 
119  // Call internal interface so that everything else is done on component thread,
120  // this helps ensure consistent ordering of the printed text:
121  Fw::InternalInterfaceString intText(textStr);
122  this->TextQueue_internalInterfaceInvoke(intText);
123  }
124 
125  // ----------------------------------------------------------------------
126  // Internal interface handlers
127  // ----------------------------------------------------------------------
128 
130  {
131 
132  // Print to console:
133  (void) printf("%s",text.toChar());
134 
135  // Print to file if there is one:
136  (void) this->m_log_file.write_to_log(text.toChar(), text.length()); // Ignoring return status
137 
138  }
139 
140  // ----------------------------------------------------------------------
141  // Helper Methods
142  // ----------------------------------------------------------------------
143 
144  bool ActiveTextLoggerComponentImpl::set_log_file(const char* fileName, const U32 maxSize, const U32 maxBackups)
145  {
146  FW_ASSERT(fileName != NULL);
147 
148  return this->m_log_file.set_log_file(fileName, maxSize, maxBackups);
149  }
150 
151 
152 } // namespace Svc
Fw::InternalInterfaceString
Definition: InternalInterfaceString.hpp:11
Fw::TEXT_LOG_ACTIVITY_HI
@ TEXT_LOG_ACTIVITY_HI
Definition: LogTextPortAc.hpp:31
Svc::ActiveTextLoggerComponentImpl::TextLogger_handler
virtual void TextLogger_handler(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, Fw::TextLogSeverity severity, Fw::TextLogString &text)
Handler for input port TextLogger.
Definition: ActiveTextLoggerImpl.cpp:37
Svc::ActiveTextLoggerComponentBase::text
PROTECTED FwEventIdType Fw::Time Fw::TextLogSeverity Fw::TextLogString & text
Definition: ActiveTextLoggerComponentAc.hpp:101
Fw::TextLogString
Definition: TextLogString.hpp:11
Fw::Time
Definition: Time.hpp:10
Svc::ActiveTextLoggerComponentImpl::TextQueue_internalInterfaceHandler
virtual void TextQueue_internalInterfaceHandler(const Fw::InternalInterfaceString &text)
Definition: ActiveTextLoggerImpl.cpp:129
Fw::TextLogSeverity
TextLogSeverity
Definition: LogTextPortAc.hpp:26
Svc::ActiveTextLoggerComponentBase::timeTag
PROTECTED FwEventIdType Fw::Time & timeTag
Definition: ActiveTextLoggerComponentAc.hpp:98
Fw::Time::getTimeBase
TimeBase getTimeBase(void) const
Definition: Time.cpp:142
Fw::TEXT_LOG_DIAGNOSTIC
@ TEXT_LOG_DIAGNOSTIC
Definition: LogTextPortAc.hpp:33
Fw::TEXT_LOG_COMMAND
@ TEXT_LOG_COMMAND
Definition: LogTextPortAc.hpp:30
Svc::LogFile::set_log_file
bool set_log_file(const char *fileName, const U32 maxSize, const U32 maxBackups=10)
Set log file and max size.
Definition: LogFile.cpp:80
Fw::Time::getUSeconds
U32 getUSeconds(void) const
Definition: Time.cpp:138
Svc::ActiveTextLoggerComponentBase
Auto-generated base for ActiveTextLogger component.
Definition: ActiveTextLoggerComponentAc.hpp:34
Svc::ActiveTextLoggerComponentImpl::ActiveTextLoggerComponentImpl
ActiveTextLoggerComponentImpl(const char *compName)
Component constructor.
Definition: ActiveTextLoggerImpl.cpp:16
Fw::TEXT_LOG_WARNING_HI
@ TEXT_LOG_WARNING_HI
Definition: LogTextPortAc.hpp:28
Assert.hpp
Fw::ObjBase::init
void init(void)
Object initializer.
Definition: ObjBase.cpp:26
Fw::TEXT_LOG_WARNING_LO
@ TEXT_LOG_WARNING_LO
Definition: LogTextPortAc.hpp:29
Fw::TEXT_LOG_ACTIVITY_LO
@ TEXT_LOG_ACTIVITY_LO
Definition: LogTextPortAc.hpp:32
Svc::ActiveTextLoggerComponentImpl::~ActiveTextLoggerComponentImpl
virtual ~ActiveTextLoggerComponentImpl()
Component destructor.
Definition: ActiveTextLoggerImpl.cpp:23
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:9
Fw::TEXT_LOG_FATAL
@ TEXT_LOG_FATAL
Definition: LogTextPortAc.hpp:27
Svc::ActiveTextLoggerComponentImpl::set_log_file
bool set_log_file(const char *fileName, const U32 maxSize, const U32 maxBackups=10)
Set log file and max size.
Definition: ActiveTextLoggerImpl.cpp:144
ActiveTextLoggerImpl.hpp
Fw::Time::getSeconds
U32 getSeconds(void) const
Definition: Time.cpp:134
Svc::LogFile::write_to_log
bool write_to_log(const char *const buf, const U32 size)
Write the passed buf to the log if possible.
Definition: LogFile.cpp:39
Svc
Definition: ActiveLoggerComponentAc.cpp:22
Svc::ActiveTextLoggerComponentBase::severity
PROTECTED FwEventIdType Fw::Time Fw::TextLogSeverity severity
Definition: ActiveTextLoggerComponentAc.hpp:99
TB_WORKSTATION_TIME
@ TB_WORKSTATION_TIME
Time as reported on workstation where software is running. For testing.
Definition: FpConfig.hpp:326
Fw::InternalInterfaceString::toChar
const char * toChar(void) const
gets char buffer
Definition: InternalInterfaceString.cpp:34
Svc::ActiveTextLoggerComponentImpl::m_log_file
LogFile m_log_file
Definition: ActiveTextLoggerImpl.hpp:115
FwEventIdType
#define FwEventIdType
Type representation for a event id.
Definition: FpConfig.hpp:70
FW_INTERNAL_INTERFACE_STRING_MAX_SIZE
#define FW_INTERNAL_INTERFACE_STRING_MAX_SIZE
Max size of interface string parameter type.
Definition: FpConfig.hpp:281
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29
NULL
#define NULL
NULL.
Definition: BasicTypes.hpp:100