FARGOS/VISTA Object Management Environment Core
..
|
Log message record used to remember output format and argument values, potentially deferring formatting to a later point in time or by an external process. More...
#include <logging_api.hpp>
Classes | |
struct | ArgumentRecord |
union | LOG_argument_union |
Union to hold arbitrary argument value. More... | |
Public Types | |
enum | { LOG_MAX_ARGUMENT_TOTAL = 3600, MIN_IOV_UNIT_LEN = 64 } |
enum | LogPrefixMask { LOG_DATESTAMP =1, LOG_TIMESTAMP =2, LOG_THREAD_ID =4, LOG_FILENAME =8, LOG_LINE_NUMBER =16, LOG_ERROR_LEVEL =32, LOG_BINARY_FORMAT_STRING =128 } |
Log line prefix attributes. More... | |
enum | LogLevelSeverityMask { LOG_SEVERITY_TRACE = (1 << 4), LOG_SEVERITY_DEBUG = (1 << 5), LOG_SEVERITY_INFO = (1 << 6), LOG_SEVERITY_WARN = (1 << 7), LOG_SEVERITY_ERROR = (1 << 8), LOG_SEVERITY_FATAL = (1 << 9), LOG_SEVERITY_USER = (1 << 10), AND_USE_SYSLOG = 0x1, AND_USE_STDERR = 0x2, AND_SPECIAL_MASK = 0xf } |
Standard bit flags to define severity level. There is a partial order of implied importance here, but each level is distinct and filtering one level does not imply anything about another. User-defined masks can start at LOG_SEVERITY_USER onwards. These are not normally referenced directly, but instead by the aliases introduced by DEFINE_COMPONENT_LOG_MASKS(). A non-standard level name can be introduced by declaring something similar to: enum { COMPONENT_LEVEL(component,level) = (1 << N) }; where N is some unused bit position (e.g., 11 or more). Example: enum { COMPONENT_LEVEL(myComponent,incoming) = (1 << 11), COMPONENT_LEVEL(myComponent,outgoing) = (1 << 12) }; See DECLARE_COMPONENT_USER_LOG_MASK() and DEFINE_COMPONENT_USER_LOG_MASK() for related convenience macros. More... | |
enum | LogArgumentType { LOG_ARG_TYPE_INT32 =SharedMemoryVariable::SMV_TYPE_INT32, LOG_ARG_TYPE_UINT32 =SharedMemoryVariable::SMV_TYPE_UINT32, LOG_ARG_TYPE_INT64 =SharedMemoryVariable::SMV_TYPE_INT64, LOG_ARG_TYPE_UINT64 =SharedMemoryVariable::SMV_TYPE_UINT64, LOG_ARG_TYPE_FLOAT =SharedMemoryVariable::SMV_TYPE_FLOAT, LOG_ARG_TYPE_DOUBLE =SharedMemoryVariable::SMV_TYPE_DOUBLE, LOG_ARG_TYPE_TEXT =SharedMemoryVariable::SMV_TYPE_STRING, LOG_ARG_TYPE_CHAR =SharedMemoryVariable::SMV_TYPE_TINY_STRING, LOG_ARG_TYPE_BINARY =SharedMemoryVariable::SMV_TYPE_TINY_BINARY_STRING, LOG_ARG_TYPE_POINTER =128, LOG_ARG_TYPE_ROM_TEXT = LOG_ARG_TYPE_POINTER | LOG_ARG_TYPE_TEXT, LOG_ARG_TYPE_TEXT_FRAGMENT = LOG_ARG_TYPE_POINTER | LOG_ARG_TYPE_CHAR, LOG_ARG_TYPE_HEX_FRAGMENT = LOG_ARG_TYPE_POINTER | LOG_ARG_TYPE_CHAR | LOG_ARG_TYPE_FLOAT, LOG_ARG_TYPE_HEX_FRAGMENT_UPPER = LOG_ARG_TYPE_POINTER | LOG_ARG_TYPE_CHAR | LOG_ARG_TYPE_DOUBLE, LOG_ARG_TYPE_POSIX_NANOSECONDS = 256 | LOG_ARG_TYPE_UINT64, LOG_ARG_TYPE_FIXED_POINT = 512 | LOG_ARG_TYPE_UINT64 } |
Argument type indicators, reuses those from the SharedMemoryVariables. More... | |
typedef uint32_t | LogArgumentLenType_t |
Typedef for length of field to store argument length. More... | |
Public Member Functions | |
LogMessageRecord (LogManager *mgr, uint32_t importanceFlags, const char *atFileName, uint32_t atLineNumber, int_fast32_t fileNameLen=-1) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3") | |
~LogMessageRecord () | |
LogManager * | getLogManager () const OME_ALWAYS_INLINE |
void | setLogFormat (const char *f) OME_ALWAYS_INLINE |
Set arbitrary log line format text. More... | |
int | generateFormatString (unsigned int fieldNum) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3") |
Append appropriate format parameters for previously added argument. More... | |
SharedBufferAllocRecord * | formatRecordAsText (unsigned int prefixWithFlags, size_t *returnLen=nullptr, uint32_t singleThreaded=false) OME_ALWAYS_OPTIMIZE("-O3") |
Format LogMessageRecord into text, prefixing the line with the indicated attributes. More... | |
size_t | writeAsTextToBuffer (unsigned int prefixWithFlags) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3") |
Format the LogMessageRecord as a text output line (using formatRecordAsText()) and pass the resulting buffer to the LogManager via writeDataToBuffer(). More... | |
SharedBufferAllocRecord * | prepareBinaryRecord (unsigned int prefixWithFlags, size_t *returnLen=nullptr, uint32_t singleThreaded=false) |
Assemble LogMesageRecord into a suitable PDU format. More... | |
size_t | writeAsBinaryToBuffer (unsigned int prefixWithFlags) |
Format the LogMessageRecord as a binary record (using prepareBinaryRecord()) and pass the resulting buffer to the LogManager via writeDataToBuffer(). More... | |
template<typename T > | |
void | emitOverflowError (const T &arg) OME_COLD_ROUTINE |
Called when too many arguments are output. More... | |
Static Public Member Functions | |
static void | splitLongLogLine (LogMessageRecord &context, const char *line, const char *separators=",;", size_t blockLength=LogManager::MAX_LOG_LINE_LENGTH) |
Split the content of a null-terminate string across multiple log lines, breaking the lines at appropriate points (such as punctuation). More... | |
static int | define_commandline_flag (const char *flagName, LogMaskPrimitiveType_t mask, const char *label=nullptr) |
Define a new log level name for the command line parser. More... | |
static int | process_commandline_log_flags (LogSubsystemInfo *info, int argc, const char *argv[], int *newArgc, const char **newArgv) |
Process the standard argument list provided to an application and strip out the logging-related options. More... | |
static TextBlock_struct | getSeverityLabelWithLength (uint_fast32_t level) |
Get the text label for a logging level along with its length. More... | |
static const char * | getSeverityLabel (uint_fast32_t level) |
Public Attributes | |
LogManager * | logMgr |
Points to LogManager used for output. More... | |
const char * | logLineFormat |
Points format line for log line. More... | |
const char * | sourceFile |
Points to source file, usually from FILE More... | |
struct timespec | timestamp |
Timestamp of log event creation. More... | |
uint64_t | threadId |
Thread Id of log event creator. More... | |
uint32_t | sourceFileNameLen |
Length of sourceFile path. More... | |
uint32_t | argCount |
Number of arguments for log line. More... | |
uint32_t | sourceLine |
Line in source file, usually from LINE More... | |
uint32_t | importanceLevel |
Value from LogLevelSeverityMask enum. More... | |
uint32_t | generatedOffset |
End of log line generated via << operator. More... | |
uint32_t | argCountExceeded |
char | generatedFormatLine [LogManager::MAX_LOG_LINE_LENGTH - 4] |
struct LogMessageRecord::ArgumentRecord | argList [LOG_MAX_ARGUMENT_TOTAL] |
Log message record used to remember output format and argument values, potentially deferring formatting to a later point in time or by an external process.
typedef uint32_t LogMessageRecord::LogArgumentLenType_t |
Typedef for length of field to store argument length.
This is used within a single address space, so it can be the most appropriate for the target environment. This flexiblity is not present in the argLength field of the LogLineBinaryValueHeader structure.
anonymous enum |
Argument type indicators, reuses those from the SharedMemoryVariables.
Standard bit flags to define severity level. There is a partial order of implied importance here, but each level is distinct and filtering one level does not imply anything about another. User-defined masks can start at LOG_SEVERITY_USER onwards. These are not normally referenced directly, but instead by the aliases introduced by DEFINE_COMPONENT_LOG_MASKS(). A non-standard level name can be introduced by declaring something similar to: enum { COMPONENT_LEVEL(component,level) = (1 << N) }; where N is some unused bit position (e.g., 11 or more). Example: enum { COMPONENT_LEVEL(myComponent,incoming) = (1 << 11), COMPONENT_LEVEL(myComponent,outgoing) = (1 << 12) }; See DECLARE_COMPONENT_USER_LOG_MASK() and DEFINE_COMPONENT_USER_LOG_MASK() for related convenience macros.
Enumerator | |
---|---|
LOG_SEVERITY_TRACE | |
LOG_SEVERITY_DEBUG | |
LOG_SEVERITY_INFO | |
LOG_SEVERITY_WARN | |
LOG_SEVERITY_ERROR | |
LOG_SEVERITY_FATAL | |
LOG_SEVERITY_USER | |
AND_USE_SYSLOG | |
AND_USE_STDERR | |
AND_SPECIAL_MASK |
Log line prefix attributes.
|
inline |
References LogManager::getTimestamp(), and OME_EXPECT_TRUE.
|
inline |
|
static |
Define a new log level name for the command line parser.
flagName | defines the name of the custom log level that will be added to the standard names such as info and error. |
mask | defines the affected logging levels. |
label | is an optional label that provides an level label to be output rather than standard labels such as "INFO" and "ERROR". |
Referenced by AutoRegisterLogLevelName::AutoRegisterLogLevelName().
SharedBufferAllocRecord * LogMessageRecord::formatRecordAsText | ( | unsigned int | prefixWithFlags, |
size_t * | returnLen = nullptr , |
||
uint32_t | singleThreaded = false |
||
) |
Format LogMessageRecord into text, prefixing the line with the indicated attributes.
prefixWithFlags | is a set of bit flags from the LogPrefixMask enum. |
returnLen | is an optional pointer to a location into which the final formatted length of the output line will be returned. |
singleThreaded | is a Boolean flag indicating if a background output thread is not in use, which enables some optimizations that are possible when a background output thread is not present. |
A SharedBufferAllocRecord is acquired from the log manager and a text output line is assembled into the buffer.
References ADD_IOV_ELEMENT, LogManager::allocateBuffer(), AND_USE_SYSLOG, LogMessageRecord::ArgumentRecord::argLen, argList, LogManager::argTimeCacheTable, LogMessageRecord::LOG_argument_union::asUCstring, TextBlock_struct::bfrLen, SharedBufferAllocRecord_32::blockLen, LogManager::bufferAddress(), byteAsLowercaseHexadecimal, byteAsUppercaseHexadecimal, LogMessageRecord::LOG_argument_union::d, LogMessageRecord::LOG_argument_union::f, fixedpoint_to_ascii(), float_to_ascii(), TimePointOfGranularity< UNITS >::formatIntoString(), TimePointCacheTable::getCacheEntry(), getSeverityLabel(), getSeverityLabelWithLength(), LogMessageRecord::LOG_argument_union::i32, LogMessageRecord::LOG_argument_union::i64, importanceLevel, int_to_ascii(), TimePointCache::isForDay(), LOG_ARG_TYPE_DOUBLE, LOG_ARG_TYPE_HEX_FRAGMENT, LOG_ARG_TYPE_HEX_FRAGMENT_UPPER, LOG_ARG_TYPE_INT64, LOG_ARG_TYPE_POINTER, LOG_ARG_TYPE_ROM_TEXT, LOG_ARG_TYPE_TEXT, LOG_ARG_TYPE_TEXT_FRAGMENT, LOG_DATESTAMP, LOG_ERROR_LEVEL, LOG_FILENAME, LOG_LINE_NUMBER, LOG_THREAD_ID, LOG_TIMESTAMP, LogMessageRecord::ArgumentRecord::logArgs, logLineFormat, logMgr, LogManager::logTimePointCache, MAX_ELEMENT_TOTAL, OME_EXPECT_FALSE, OME_EXPECT_TRUE, OME_PREFETCH, LogManager::pruneDirectoryPrefix(), LogMessageRecord::LOG_argument_union::ptr, sourceFile, sourceFileNameLen, sourceLine, TextBlock_struct::textBfr, threadId, timestamp, LogMessageRecord::LOG_argument_union::u32, LogMessageRecord::LOG_argument_union::u64, uint_to_ascii(), and SharedBufferAllocRecord_32::usedLen.
|
inline |
Append appropriate format parameters for previously added argument.
fieldNum | indicates the field to be appended. |
References LogMessageRecord::ArgumentRecord::argBaseType, LogMessageRecord::ArgumentRecord::argLen, LogMessageRecord::LOG_argument_union::asChars, LogMessageRecord::ArgumentRecord::logArgs, OME_EXPECT_FALSE, OME_EXPECT_TRUE, and LogMessageRecord::LOG_argument_union::ptr.
|
inline |
Referenced by splitLongLogLine().
|
static |
Referenced by formatRecordAsText(), and ReadBinaryLog::outputAssembledLine().
|
static |
Get the text label for a logging level along with its length.
level | specifies the logging level of interest. |
Referenced by formatRecordAsText().
SharedBufferAllocRecord * LogMessageRecord::prepareBinaryRecord | ( | unsigned int | prefixWithFlags, |
size_t * | returnLen = nullptr , |
||
uint32_t | singleThreaded = false |
||
) |
Assemble LogMesageRecord into a suitable PDU format.
prefixWithFlags | is a bit mask that indicates the output fields that should be included on the log line (such as time, thread id, file name, line number, etc.). | |
[out] | returnLen | is an optional pointer that points to a location into which the length of the output record will be stored. |
singleThreaded | is a Boolean flag indicating if a background output thread is not in use, which enables some optimizations that are possible when a background output thread is not present. |
A SharedBufferAllocRecord is acquired from the log manager and the output data is assembled into the buffer.
References LogLineBinaryHeader::_reserved, ADD_IOV_ELEMENT, LogManager::allocateBuffer(), argCount, LogLineBinaryHeader::argumentCount, TextBlock_struct::bfrLen, SharedBufferAllocRecord_32::blockLen, LogManager::bufferAddress(), LogLineBinaryHeader::byteOrder, POSIXtimeInUnits< UNITS >::convertToNanosecondsSinceEpoch(), LogLineBinaryHeader::formatVersion, LogLineBinaryHeader::importanceLevel, importanceLevel, LogLineBinaryHeader::lineNumber, LOG_BINARY_FORMAT_STRING, LOG_FILENAME, LOG_LINE_BINARY_FORMAT_BE, LOG_LINE_BINARY_FORMAT_LE, LOG_LINE_BINARY_FORMAT_VER1, LOG_MAX_ARGUMENT_TOTAL, logLineFormat, logMgr, LogLineBinaryHeader::logPrefixMask, LogLineBinaryHeader::nanosecondTimestamp, LogLineBinaryHeader::offsetFileName, LogLineBinaryHeader::offsetFormatString, LogManager::pruneDirectoryPrefix(), sourceFile, sourceFileNameLen, sourceLine, TextBlock_struct::textBfr, LogLineBinaryHeader::threadId, threadId, and timestamp.
|
static |
Process the standard argument list provided to an application and strip out the logging-related options.
info | points at the LogSystemInfo object to be initialized, usually default_LogsubsystemInfo. |
argc | specifies the number of arguments in the argv array. |
argv | is an array of pointers to the application's command line arguments. |
newArgc | is a pointer to a variable into which the new argument count should be stored. Usually specified as the address of the original argc. |
newArgv | is a pointer to a new array of pointers to character strings. Usually specified as the original argv. |
The most common usage is to perform this call immediately at the start of a program's main() routine:
References LogSubsystemInfo::programName.
Referenced by LogManager::initializeLogSubsystem().
|
inline |
Set arbitrary log line format text.
f | specifies the output format prototype. |
Uses printf() syntax with the following extensions.
Referenced by splitLongLogLine().
|
static |
Split the content of a null-terminate string across multiple log lines, breaking the lines at appropriate points (such as punctuation).
context | is a reference to the log record being constructed. |
line | points at the text to be split across multiple lines |
separators | specifies the characters after which the line can broken. |
blockLength | specifies the maximum number of permitted characters on a line. |
References addLogArg(), argCount, generatedOffset, getLogManager(), LogManager::getLogPrefixMask(), importanceLevel, logMgr, setLogFormat(), sourceFile, sourceLine, and writeAsTextToBuffer().
|
inline |
Format the LogMessageRecord as a binary record (using prepareBinaryRecord()) and pass the resulting buffer to the LogManager via writeDataToBuffer().
prefixWithFlags | is a bit mask that selects the fields to be output (e.g., time, thread id, file name, line number, etc.). |
Whether the output is performed immediately or processed by a background thread is dependent on the mode of the LogManager.
References IO_Processor::currentThreadState, LogManager::get_IO_Manager(), OME_EXPECT_TRUE, IO_Processor::PROCESS_DURING_READ, and LogManager::writeDataToBuffer().
|
inline |
Format the LogMessageRecord as a text output line (using formatRecordAsText()) and pass the resulting buffer to the LogManager via writeDataToBuffer().
prefixWithFlags | is a bit mask that indicates the output fields that should be included on the log line (such as time, thread id, file name, line number, etc.). |
Whether the output is performed immediately or processed by a background thread is dependent on the mode of the LogManager.
References IO_Processor::currentThreadState, LogManager::get_IO_Manager(), OME_EXPECT_TRUE, IO_Processor::PROCESS_DURING_READ, and LogManager::writeDataToBuffer().
Referenced by splitLongLogLine().
uint32_t LogMessageRecord::argCount |
Number of arguments for log line.
Referenced by addLogArg(), prepareBinaryRecord(), and splitLongLogLine().
uint32_t LogMessageRecord::argCountExceeded |
Referenced by emitOverflowError().
struct LogMessageRecord::ArgumentRecord LogMessageRecord::argList[LOG_MAX_ARGUMENT_TOTAL] |
Referenced by addLogArg(), and formatRecordAsText().
char LogMessageRecord::generatedFormatLine[LogManager::MAX_LOG_LINE_LENGTH - 4] |
uint32_t LogMessageRecord::generatedOffset |
End of log line generated via << operator.
Referenced by splitLongLogLine().
uint32_t LogMessageRecord::importanceLevel |
Value from LogLevelSeverityMask enum.
Referenced by formatRecordAsText(), prepareBinaryRecord(), and splitLongLogLine().
const char* LogMessageRecord::logLineFormat |
Points format line for log line.
Referenced by formatRecordAsText(), and prepareBinaryRecord().
LogManager* LogMessageRecord::logMgr |
Points to LogManager used for output.
Referenced by formatRecordAsText(), prepareBinaryRecord(), and splitLongLogLine().
const char* LogMessageRecord::sourceFile |
Points to source file, usually from FILE
Referenced by emitOverflowError(), formatRecordAsText(), prepareBinaryRecord(), and splitLongLogLine().
uint32_t LogMessageRecord::sourceFileNameLen |
Length of sourceFile path.
Referenced by formatRecordAsText(), and prepareBinaryRecord().
uint32_t LogMessageRecord::sourceLine |
Line in source file, usually from LINE
Referenced by emitOverflowError(), formatRecordAsText(), prepareBinaryRecord(), and splitLongLogLine().
uint64_t LogMessageRecord::threadId |
Thread Id of log event creator.
Referenced by formatRecordAsText(), and prepareBinaryRecord().
struct timespec LogMessageRecord::timestamp |
Timestamp of log event creation.
Referenced by formatRecordAsText(), and prepareBinaryRecord().
![]() | Generated: Fri Jul 31 2020 18:19:16
Support Information |