Matrix Science Mascot Parser toolkit
 
Loading...
Searching...
No Matches
ms_stdout_logger Class Reference

Concrete class which implements ms_logger and outputs log text to standard out. More...

#include <ms_logging.hpp>

Inheritance diagram for ms_stdout_logger:
Collaboration diagram for ms_stdout_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_stdout_logger (unsigned int colsToOutput=ms_logger::COL_LOGGER_DEFAULTS)
 Constructor.
 
virtual ~ms_stdout_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)
 Logs the passed message directly to standard out.
 
virtual void setColsToOutput (const unsigned int colsToOutput)
 Set the value to specify which columns should be output by the logger.
 

Detailed Description

Concrete class which implements ms_logger and outputs log text to standard out.

Member Enumeration Documentation

◆ LogOutputColumns_e

enum LogOutputColumns_e
inherited

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_stdout_logger()

ms_stdout_logger ( unsigned int  colsToOutput = ms_logger::COL_LOGGER_DEFAULTS)

Constructor.

Parameters
colsToOutputis used to specify the cols to include in the log and also the format

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
inherited

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
virtualinherited

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
inherited

Returns the header line based on the specified column names.

Returns
a string that contains the column names

◆ onLogMessage()

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 
)
virtual

Logs the passed message directly to standard out.

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)

Implements ms_logger.

◆ setColsToOutput()

void setColsToOutput ( const unsigned int  colsToOutput)
virtualinherited

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: