mirror of
https://github.com/nasa/fprime.git
synced 2025-12-10 00:44:37 -06:00
mstarch: fixing up new Logger, LogAssert for #208
This commit is contained in:
parent
29cdd96c3b
commit
e5c80c2557
@ -20,14 +20,12 @@ SRC = \
|
||||
LogPacket.cpp \
|
||||
LogString.cpp \
|
||||
TextLogString.cpp \
|
||||
AmpcsEvrLogPacket.cpp \
|
||||
Log.cpp
|
||||
AmpcsEvrLogPacket.cpp
|
||||
|
||||
HDR = LogBuffer.hpp \
|
||||
LogPacket.hpp \
|
||||
LogString.hpp \
|
||||
TextLogString.hpp \
|
||||
AmpcsEvrLogPacket.hpp \
|
||||
Log.hpp
|
||||
AmpcsEvrLogPacket.hpp
|
||||
|
||||
SUBDIRS = test
|
||||
|
||||
16
Fw/Logger/CMakeLists.txt
Normal file
16
Fw/Logger/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
####
|
||||
# F prime CMakeLists.txt:
|
||||
#
|
||||
# SOURCE_FILES: combined list of source and autocoding diles
|
||||
# MOD_DEPS: (optional) module dependencies
|
||||
#
|
||||
####
|
||||
set(MOD_DEPS
|
||||
Fw/Cfg
|
||||
Fw/Types
|
||||
)
|
||||
set(SOURCE_FILES
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Logger.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/LogAssert.cpp"
|
||||
)
|
||||
register_fprime_module()
|
||||
77
Fw/Logger/LogAssert.cpp
Normal file
77
Fw/Logger/LogAssert.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* LogAssert.cpp
|
||||
*
|
||||
* Created on: Sep 9, 2016
|
||||
* Author: tcanham
|
||||
* Note: this file was originally a log assert file, under Fw::Types. It now made generic
|
||||
* to log asserts to Fw::Logger
|
||||
*/
|
||||
|
||||
#include <Fw/Logger/LogAssert.hpp>
|
||||
#include <Fw/Logger/Logger.hpp>
|
||||
|
||||
#if FW_ASSERT_LEVEL == FW_NO_ASSERT
|
||||
|
||||
#else
|
||||
|
||||
#if FW_ASSERT_LEVEL == FW_FILEID_ASSERT
|
||||
#define fileIdFs "Assert file ID %d: Line: %d "
|
||||
#else
|
||||
#define fileIdFs "Assert file \"%s\": Line: %d "
|
||||
#endif
|
||||
|
||||
|
||||
namespace Fw {
|
||||
|
||||
LogAssertHook::LogAssertHook() {
|
||||
|
||||
}
|
||||
|
||||
LogAssertHook::~LogAssertHook() {
|
||||
}
|
||||
|
||||
void LogAssertHook::reportAssert(
|
||||
FILE_NAME_ARG file,
|
||||
NATIVE_UINT_TYPE lineNo,
|
||||
NATIVE_UINT_TYPE numArgs,
|
||||
AssertArg arg1,
|
||||
AssertArg arg2,
|
||||
AssertArg arg3,
|
||||
AssertArg arg4,
|
||||
AssertArg arg5,
|
||||
AssertArg arg6
|
||||
) {
|
||||
// Assumption is that file (when string) goes back to static macro in the code and will persist
|
||||
switch (numArgs) {
|
||||
case 0:
|
||||
Fw::Logger::logMsg(fileIdFs,reinterpret_cast<POINTER_CAST>(file),lineNo,0,0,0,0);
|
||||
break;
|
||||
case 1:
|
||||
Fw::Logger::logMsg(fileIdFs " %d\n",reinterpret_cast<POINTER_CAST>(file),lineNo,arg1,0,0,0);
|
||||
break;
|
||||
case 2:
|
||||
Fw::Logger::logMsg(fileIdFs " %d %d\n",reinterpret_cast<POINTER_CAST>(file),lineNo,arg1,arg2,0,0);
|
||||
break;
|
||||
case 3:
|
||||
Fw::Logger::logMsg(fileIdFs " %d %d %d\n",reinterpret_cast<POINTER_CAST>(file),lineNo,arg1,arg2,arg3,0);
|
||||
break;
|
||||
case 4:
|
||||
Fw::Logger::logMsg(fileIdFs " %d %d %d %d\n",reinterpret_cast<POINTER_CAST>(file),lineNo,arg1,arg2,arg3,arg4);
|
||||
break;
|
||||
default: // can't fit remainder of arguments in log message
|
||||
Fw::Logger::logMsg(fileIdFs " %d %d %d %d +\n",reinterpret_cast<POINTER_CAST>(file),lineNo,arg1,arg2,arg3,arg4);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LogAssertHook::printAssert(const I8* msg) {
|
||||
// do nothing since reportAssert() sends message
|
||||
}
|
||||
|
||||
void LogAssertHook::doAssert(void) {
|
||||
}
|
||||
|
||||
} // namespace Fw
|
||||
|
||||
#endif
|
||||
38
Fw/Logger/LogAssert.hpp
Normal file
38
Fw/Logger/LogAssert.hpp
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* LogAssert.hpp
|
||||
*
|
||||
* Created on: Sep 9, 2016
|
||||
* Author: tcanham
|
||||
* Note: this file was originally a log assert file, under Fw::Types. It now made generic
|
||||
* to log asserts to Fw::Logger
|
||||
*/
|
||||
|
||||
#ifndef LOGGER_LOGASSERT_HPP_
|
||||
#define LOGGER_LOGASSERT_HPP_
|
||||
|
||||
#include <Fw/Types/Assert.hpp>
|
||||
|
||||
namespace Fw {
|
||||
|
||||
class LogAssertHook: public Fw::AssertHook {
|
||||
public:
|
||||
LogAssertHook();
|
||||
virtual ~LogAssertHook();
|
||||
void reportAssert(
|
||||
FILE_NAME_ARG file,
|
||||
NATIVE_UINT_TYPE lineNo,
|
||||
NATIVE_UINT_TYPE numArgs,
|
||||
AssertArg arg1,
|
||||
AssertArg arg2,
|
||||
AssertArg arg3,
|
||||
AssertArg arg4,
|
||||
AssertArg arg5,
|
||||
AssertArg arg6
|
||||
);
|
||||
void printAssert(const I8* msg);
|
||||
void doAssert(void);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* VXWORKSLOGASSERT_HPP_ */
|
||||
@ -12,7 +12,7 @@
|
||||
namespace Fw {
|
||||
|
||||
//Initial logger is NULL
|
||||
Loger* Logger::s_current_logger = NULL;
|
||||
Logger* Logger::s_current_logger = NULL;
|
||||
|
||||
// Basic log implementation
|
||||
void Logger :: logMsg(
|
||||
@ -30,7 +30,7 @@ void Logger :: logMsg(
|
||||
}
|
||||
}
|
||||
// Register the logger
|
||||
void Logger :: registerLogger(Loger* logger)
|
||||
void Logger :: registerLogger(Logger* logger)
|
||||
{
|
||||
Logger::s_current_logger = logger;
|
||||
}
|
||||
|
||||
@ -6,8 +6,10 @@
|
||||
#
|
||||
# There are some standard files that are included for reference
|
||||
|
||||
SRC = Log.cpp
|
||||
SRC = Logger.cpp \
|
||||
LogAssert.cpp
|
||||
|
||||
HDR = Log.hpp
|
||||
HDR = Logger.hpp \
|
||||
LogAssert.hpp
|
||||
|
||||
SUBDIRS = test
|
||||
SUBDIRS =
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include <Fw/Port/PortBase.hpp>
|
||||
#include <Fw/Types/BasicTypes.hpp>
|
||||
#include <Fw/Log/Log.hpp>
|
||||
#include <Fw/Logger/Logger.hpp>
|
||||
#include <stdio.h>
|
||||
|
||||
#if FW_PORT_TRACING
|
||||
@ -70,9 +70,9 @@ namespace Fw {
|
||||
|
||||
if (do_trace) {
|
||||
#if FW_OBJECT_NAMES == 1
|
||||
Fw::Log::logMsg("Trace: %s\n", (POINTER_CAST)this->m_objName, 0, 0, 0, 0, 0);
|
||||
Fw::Logger::logMsg("Trace: %s\n", (POINTER_CAST)this->m_objName, 0, 0, 0, 0, 0);
|
||||
#else
|
||||
Fw::Log::logMsg("Trace: %p\n", (POINTER_CAST)this, 0, 0, 0, 0, 0);
|
||||
Fw::Logger::logMsg("Trace: %p\n", (POINTER_CAST)this, 0, 0, 0, 0, 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,81 +0,0 @@
|
||||
/*
|
||||
* VxWorksLogAssert.cpp
|
||||
*
|
||||
* Created on: Sep 9, 2016
|
||||
* Author: tcanham
|
||||
*/
|
||||
|
||||
#include <Fw/Types/VxWorks/VxWorksLogAssert.hpp>
|
||||
#include <stdio.h>
|
||||
#include <taskLib.h>
|
||||
#include <Fw/Log/Log.hpp>
|
||||
|
||||
#if FW_ASSERT_LEVEL == FW_NO_ASSERT
|
||||
|
||||
#else
|
||||
|
||||
#if FW_ASSERT_LEVEL == FW_FILEID_ASSERT
|
||||
#define fileIdFs "Assert file ID %d: Line: %d "
|
||||
#else
|
||||
#define fileIdFs "Assert file \"%s\": Line: %d "
|
||||
#endif
|
||||
|
||||
|
||||
namespace Fw {
|
||||
|
||||
VxWorksLogAssertHook::VxWorksLogAssertHook() {
|
||||
|
||||
}
|
||||
|
||||
VxWorksLogAssertHook::~VxWorksLogAssertHook() {
|
||||
}
|
||||
|
||||
void VxWorksLogAssertHook::reportAssert(
|
||||
FILE_NAME_ARG file,
|
||||
NATIVE_UINT_TYPE lineNo,
|
||||
NATIVE_UINT_TYPE numArgs,
|
||||
AssertArg arg1,
|
||||
AssertArg arg2,
|
||||
AssertArg arg3,
|
||||
AssertArg arg4,
|
||||
AssertArg arg5,
|
||||
AssertArg arg6
|
||||
) {
|
||||
|
||||
// Assumption is that file (when string) goes back to static macro in the code and will persist
|
||||
|
||||
switch (numArgs) {
|
||||
case 0:
|
||||
Fw::Log::logMsg(fileIdFs,reinterpret_cast<POINTER_CAST>(file),lineNo,0,0,0,0);
|
||||
break;
|
||||
case 1:
|
||||
Fw::Log::logMsg(fileIdFs " %d\n",reinterpret_cast<POINTER_CAST>(file),lineNo,arg1,0,0,0);
|
||||
break;
|
||||
case 2:
|
||||
Fw::Log::logMsg(fileIdFs " %d %d\n",reinterpret_cast<POINTER_CAST>(file),lineNo,arg1,arg2,0,0);
|
||||
break;
|
||||
case 3:
|
||||
Fw::Log::logMsg(fileIdFs " %d %d %d\n",reinterpret_cast<POINTER_CAST>(file),lineNo,arg1,arg2,arg3,0);
|
||||
break;
|
||||
case 4:
|
||||
Fw::Log::logMsg(fileIdFs " %d %d %d %d\n",reinterpret_cast<POINTER_CAST>(file),lineNo,arg1,arg2,arg3,arg4);
|
||||
break;
|
||||
default: // can't fit remainder of arguments in log message
|
||||
Fw::Log::logMsg(fileIdFs " %d %d %d %d +\n",reinterpret_cast<POINTER_CAST>(file),lineNo,arg1,arg2,arg3,arg4);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void VxWorksLogAssertHook::printAssert(const I8* msg) {
|
||||
// do nothing since reportAssert() sends message
|
||||
}
|
||||
|
||||
void VxWorksLogAssertHook::doAssert(void) {
|
||||
// suspend task so it can be looked at.
|
||||
taskSuspend(0);
|
||||
}
|
||||
|
||||
} // namespace Fw
|
||||
|
||||
#endif
|
||||
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* VxWorksLogAssert.hpp
|
||||
*
|
||||
* Created on: Sep 9, 2016
|
||||
* Author: tcanham
|
||||
*/
|
||||
|
||||
#ifndef VXWORKSLOGASSERT_HPP_
|
||||
#define VXWORKSLOGASSERT_HPP_
|
||||
|
||||
#include <Fw/Types/Assert.hpp>
|
||||
|
||||
namespace Fw {
|
||||
|
||||
class VxWorksLogAssertHook: public Fw::AssertHook {
|
||||
public:
|
||||
VxWorksLogAssertHook();
|
||||
virtual ~VxWorksLogAssertHook();
|
||||
void reportAssert(
|
||||
FILE_NAME_ARG file,
|
||||
NATIVE_UINT_TYPE lineNo,
|
||||
NATIVE_UINT_TYPE numArgs,
|
||||
AssertArg arg1,
|
||||
AssertArg arg2,
|
||||
AssertArg arg3,
|
||||
AssertArg arg4,
|
||||
AssertArg arg5,
|
||||
AssertArg arg6
|
||||
);
|
||||
void printAssert(const I8* msg);
|
||||
void doAssert(void);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* VXWORKSLOGASSERT_HPP_ */
|
||||
@ -41,9 +41,6 @@ HDR = \
|
||||
MallocAllocator.hpp
|
||||
|
||||
# FwStructSerializable.hpp
|
||||
|
||||
SRC_BAERAD750 = \
|
||||
VxWorks/VxWorksLogAssert.cpp
|
||||
|
||||
SUBDIRS = test
|
||||
|
||||
|
||||
@ -31,6 +31,7 @@ set(MOD_DEPS
|
||||
"${CMAKE_THREAD_LIBS_INIT}"
|
||||
Fw/Cfg
|
||||
Fw/Types
|
||||
Fw/Logger
|
||||
Utils/Hash
|
||||
)
|
||||
|
||||
|
||||
15
Os/Log.hpp
15
Os/Log.hpp
@ -1,14 +1,16 @@
|
||||
/**
|
||||
* File: Os/Log.hpp
|
||||
* Description: this file provides an implementation of the Fw::Logger class that is backed by the
|
||||
* Os abstraction layer.
|
||||
*/
|
||||
#ifndef _Log_hpp_
|
||||
#define _Log_hpp_
|
||||
|
||||
#include <Fw/Types/BasicTypes.hpp>
|
||||
#include <Fw/Log/Log.hpp>
|
||||
#include <Fw/Obj/ObjBase.hpp>
|
||||
#include <Fw/Types/EightyCharString.hpp>
|
||||
#include <Fw/Types/Serializable.hpp>
|
||||
#include <Fw/Logger/Logger.hpp>
|
||||
|
||||
namespace Os {
|
||||
class Log : public Fw::Log {
|
||||
class Log : public Fw::Logger {
|
||||
public:
|
||||
/**
|
||||
* Function called on the logger to log a message. This is abstract virtual method and
|
||||
@ -31,9 +33,6 @@ namespace Os {
|
||||
POINTER_CAST a5 = 0,
|
||||
POINTER_CAST a6 = 0
|
||||
);
|
||||
|
||||
static void logMsg(const char* fmt, POINTER_CAST a1, POINTER_CAST a2, POINTER_CAST a3, POINTER_CAST a4, POINTER_CAST a5, POINTER_CAST a6); //!< write a message to the system log
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -1,14 +1,23 @@
|
||||
/**
|
||||
* File: Os/LogPrintf.cpp
|
||||
* Description: an implementation on the Os::Log abstraction that routes log messages into standard
|
||||
* printf calls.
|
||||
*/
|
||||
#include <Os/Log.hpp>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Os {
|
||||
// Instance implementation
|
||||
void Log::log(const char* fmt, POINTER_CAST a1, POINTER_CAST a2, POINTER_CAST a3, POINTER_CAST a4, POINTER_CAST a5, POINTER_CAST a6) {
|
||||
Os::Log::logMsg(fmt, a1, a2, a3, a4, a5, a6);
|
||||
}
|
||||
// Backwards-compatible static implementation
|
||||
void Log::logMsg(const char* fmt, POINTER_CAST a1, POINTER_CAST a2, POINTER_CAST a3, POINTER_CAST a4, POINTER_CAST a5, POINTER_CAST a6) {
|
||||
void Log::log(
|
||||
const char* fmt,
|
||||
POINTER_CAST a1,
|
||||
POINTER_CAST a2,
|
||||
POINTER_CAST a3,
|
||||
POINTER_CAST a4,
|
||||
POINTER_CAST a5,
|
||||
POINTER_CAST a6
|
||||
) {
|
||||
(void)printf(fmt, a1, a2, a3, a4, a5, a6);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#include <Components.hpp>
|
||||
#include <Fw/Types/Assert.hpp>
|
||||
#include <Os/Task.hpp>
|
||||
#include <Fw/Log/Log.hpp>
|
||||
#include <Fw/Logger/Logger.hpp>
|
||||
#include <Os/Log.hpp>
|
||||
#include <Fw/Types/MallocAllocator.hpp>
|
||||
|
||||
@ -394,7 +394,7 @@ int main(int argc, char* argv[]) {
|
||||
port_number = 0;
|
||||
option = 0;
|
||||
hostname = NULL;
|
||||
Fw::Log::registerLogger(&osLogger);
|
||||
Fw::Logger::registerLogger(&osLogger);
|
||||
while ((option = getopt(argc, argv, "hp:a:")) != -1){
|
||||
switch(option) {
|
||||
case 'h':
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <Fw/Log/Log.hpp>
|
||||
#include <Fw/Logger/Logger.hpp>
|
||||
#include <Svc/FatalHandler/FatalHandlerComponentImpl.hpp>
|
||||
#include "Fw/Types/BasicTypes.hpp"
|
||||
|
||||
@ -26,9 +26,9 @@ namespace Svc {
|
||||
const NATIVE_INT_TYPE portNum,
|
||||
FwEventIdType Id) {
|
||||
// for **nix, delay then exit with error code
|
||||
Fw::Log::logMsg("FATAL %d handled.\n",(U32)Id,0,0,0,0,0);
|
||||
Fw::Logger::logMsg("FATAL %d handled.\n",(U32)Id,0,0,0,0,0);
|
||||
(void)Os::Task::delay(1000);
|
||||
Fw::Log::logMsg("Exiting.\n",0,0,0,0,0,0);
|
||||
Fw::Logger::logMsg("Exiting.\n",0,0,0,0,0,0);
|
||||
(void)raise( SIGSEGV );
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -13,14 +13,14 @@
|
||||
#include <Svc/FatalHandler/FatalHandlerComponentImpl.hpp>
|
||||
#include "Fw/Types/BasicTypes.hpp"
|
||||
#include <taskLib.h>
|
||||
#include <Fw/Log/Log.hpp>
|
||||
#include <Fw/Logger/Logger.hpp>
|
||||
|
||||
namespace Svc {
|
||||
|
||||
void FatalHandlerComponentImpl::FatalReceive_handler(
|
||||
const NATIVE_INT_TYPE portNum,
|
||||
FwEventIdType Id) {
|
||||
Fw::Log::logMsg("FATAL %d handled.\n",(U32)Id,0,0,0,0,0);
|
||||
Fw::Logger::logMsg("FATAL %d handled.\n",(U32)Id,0,0,0,0,0);
|
||||
taskSuspend(0);
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#include <Svc/PassiveConsoleTextLogger/ConsoleTextLoggerImpl.hpp>
|
||||
#include <Fw/Types/BasicTypes.hpp>
|
||||
#include <Fw/Types/Assert.hpp>
|
||||
#include <Fw/Log/Log.hpp>
|
||||
#include <Fw/Logger/Logger.hpp>
|
||||
#include <Fw/Cfg/Config.hpp>
|
||||
|
||||
enum {
|
||||
@ -55,7 +55,7 @@ namespace Svc {
|
||||
// null terminate
|
||||
logBuffers[logEntry][FW_LOG_TEXT_BUFFER_SIZE - 1] = 0;
|
||||
|
||||
Fw::Log::logMsg("EVENT: (%d) (%d:%d,%d) %s: %s\n",
|
||||
Fw::Logger::logMsg("EVENT: (%d) (%d:%d,%d) %s: %s\n",
|
||||
// printf("EVENT: (%d) (%d:%d,%d) %s: %s\n",
|
||||
(POINTER_CAST)id,
|
||||
(POINTER_CAST)timeTag.getTimeBase(),
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#include <Fw/Log/Log.hpp>
|
||||
#include <Fw/Logger/Logger.hpp>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
Fw::Log::logMsg("You Win!\n", 0, 0, 0, 0, 0, 0);
|
||||
Fw::Logger::logMsg("You Win!\n", 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#include <Fw/Log/Log.hpp>
|
||||
#include <Fw/Logger/Logger.hpp>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
Fw::Log::logMsg("You Win!\n", 0, 0, 0, 0, 0, 0);
|
||||
Fw::Logger::logMsg("You Win!\n", 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user