Matrix Science Mascot Parser toolkit
 
Loading...
Searching...
No Matches
ms_logger Class Referenceabstract

Abstract class which provides the interface used by ms_logging monitor to delegate logging events. More...

#include <ms_logging.hpp>

Inheritance diagram for ms_logger:

Public Types

enum  LogOutputColumns_e {
  COL_ASC_TIME = 0x0001 ,
  COL_ISO8601_TIME = 0x0002 ,
  COL_IP_ADDRESS = 0x0004 ,
  COL_MSG_NUM_DEC = 0x0008 ,
  COL_MSG_NUM_HEX = 0x0010 ,
  COL_SEVERITY_NUM = 0x0020 ,
  COL_SEVERITY_TXT = 0x0040 ,
  COL_MSG_SOURCE_TXT = 0x0080 ,
  COL_SRC_FILE = 0x0100 ,
  COL_SRC_LINENUM = 0x0200 ,
  COL_THREAD_ID = 0x0400 ,
  COL_MSG = 0x0800 ,
  COL_TSV = 0x1000 ,
  COL_QUOTES = 0x2000 ,
  COL_HEADERS = 0x4000 ,
  COL_LOGGER_DEFAULTS = COL_ISO8601_TIME | COL_MSG_NUM_HEX | COL_SEVERITY_TXT | COL_MSG_SOURCE_TXT | COL_SRC_FILE | COL_SRC_LINENUM | COL_MSG | COL_HEADERS
}
 Logging output columns. More...
 

Public Member Functions

 ms_logger (const unsigned int colsToOutput=COL_MSG)
 Constructor.
 
virtual ~ms_logger ()
 Destructor.
 
std::string formatMessage (ms_loggingmonitor::Level_e eSeverity, ms_loggingmonitor::Source_e eSource, long lMsgId, const std::string &text, const char *srcFileName, const int srcFileLineNum, long lContextId) const
 Returns a string with formatting based on the columns requested to be output.
 
virtual unsigned int getColsToOutput () const
 Return the value which specifies which columns should be output by the logger.
 
std::string getHeaderLine () const
 Returns the header line based on the specified column names.
 
virtual void onLogMessage (ms_loggingmonitor::Level_e eSeverity, ms_loggingmonitor::Source_e eSource, long lMsgId, const std::string &text, const char *srcFileName, const int srcFileLineNum, long lContextId=0)=0
 Processes and handles the passed logging message.
 
virtual void setColsToOutput (const unsigned int colsToOutput)
 Set the value to specify which columns should be output by the logger.
 

Detailed Description

Abstract class which provides the interface used by ms_logging monitor to delegate logging events.

See also ms_stdout_logger and ms_file_logger which inherit from this class.

See Logging using ms_loggingmonitor for examples on using this class

Member Enumeration Documentation

◆ LogOutputColumns_e

Logging output columns.

These flags determine which columns are output by ms_stdout_logger and ms_file_logger.

The only way to change the order of the columns is to override the onLogMessage() function.

Enums with a [*] in the description are included in COL_LOGGER_DEFAULTS

See Using enumerated values and static const ints in Perl, Java, Python and C#.

Enumerator
COL_ASC_TIME 

[ ] Output the time in the format: "Sat Jan 6 11:35:22 2018"

COL_ISO8601_TIME 

[*] Output the time in the format: "2018-05-28T08:26:34-01:00". If the local time is the same as UTC, then the format would be: "2018-05-28T08:26:34Z " with 5 trailing spaces.

COL_IP_ADDRESS 

[ ] Output the IP address of the calling getenv("REMOTE_ADDR"). If this is empty, "localhost" is output. Most useful for cgi applications.

COL_MSG_NUM_DEC 

[ ] Output the message number, will either be an ms_log::log_msg or a ms_errs::err value.

COL_MSG_NUM_HEX 

[*] Output the message number, will either be an ms_log::log_msg or a ms_errs::err value.

COL_SEVERITY_NUM 

[ ] Output the ms_loggingmonitor::Level_e severity as a number.

COL_SEVERITY_TXT 

[*] Output the ms_loggingmonitor::Level_e severity as text by calling ms_loggingmonitor::severityAsText .

COL_MSG_SOURCE_TXT 

[*] Output the source of the message. See ms_loggingmonitor::messageSourceAsText

COL_SRC_FILE 

[*] Output the source code file name.

COL_SRC_LINENUM 

[*] Ouput the line number in the source file.

COL_THREAD_ID 

[ ] Output the current thread ID as a hexadecimal number.

COL_MSG 

[*] Output the formatted message text.

COL_TSV 

[ ] By default, the output format is CSV - with each field in quotes. If this flag is used, then the column separator will be a tab

COL_QUOTES 

[ ] Put quotes around every field

COL_HEADERS 

[*] For ms_file_logger, this will ouput column headers if the file is empty and for ms_stdout_logger the constructor will output this

COL_LOGGER_DEFAULTS 

[ ] Default columns used by Matrix Science Applications, includes values marked with [*] above.

Constructor & Destructor Documentation

◆ ms_logger()

ms_logger ( const unsigned int  colsToOutput = COL_MSG)

Constructor.

ms_logger is an abstract class, so this is called from ms_stdout_logger, ms_file_logger and should be called from any other inherited classes.

See Logging using ms_loggingmonitor for examples on using this class

Parameters
colsToOutputis formed by bitwise ORing one or more ms_logger::LogOutputColumns_e values

Member Function Documentation

◆ formatMessage()

std::string formatMessage ( ms_loggingmonitor::Level_e  eSeverity,
ms_loggingmonitor::Source_e  eSource,
long  lMsgId,
const std::string &  text,
const char *  srcFileName,
const int  srcFileLineNum,
long  lContextId 
) const

Returns a string with formatting based on the columns requested to be output.

Called by ms_stdout_logger::onLogMessage and ms_file_logger::onLogMessage to return a formatted string based on the ms_logger::LogOutputColumns_e flags returned by getColsToOutput().

This function can obviously also be called by any custom ms_logger

Parameters
eSeveritythe severity level of the message
eSourcethe source of the message
lMsgIdthe message id or error code
textthe message text
srcFileNamewill normally be supplied using __FILE__
srcFileLineNumwill normally be supplied using __LINE__
lContextIdthe contextid of the message (from MDRO)
Returns
the formatted string.

◆ getColsToOutput()

unsigned int getColsToOutput ( ) const
virtual

Return the value which specifies which columns should be output by the logger.

The value returned is one or more ms_logger::LogOutputColumns_e values bitwise ORed together. formatMessage uses this value to determine which columns to return.

Returns
the value set in the constructor or by calling ms_logger::setColsToOutput

◆ getHeaderLine()

std::string getHeaderLine ( ) const

Returns the header line based on the specified column names.

Returns
a string that contains the column names

◆ setColsToOutput()

void setColsToOutput ( const unsigned int  colsToOutput)
virtual

Set the value to specify which columns should be output by the logger.

formatMessage uses this value to determine which columns to return.

Parameters
colsToOutputis formed by bitwise ORing one or more ms_logger::LogOutputColumns_e values

The documentation for this class was generated from the following files: