RMM API 2.0.0
Loading...
Searching...
No Matches
RMMLog Class Reference

Class for managing and writing log messages to different log levels and files. More...

#include <RMMLog.h>

Inheritance diagram for RMMLog:

Public Member Functions

 RMMLog (const char *name)
 Constructs the RMMLog object with a name for the log.
 
 ~RMMLog ()
 Destructor for the RMMLog object.
 
void debug (const char *sender, const char *printer...)
 Logs a debug message.
 
void info (const char *sender, const char *printer...)
 Logs an info message.
 
void warn (const char *sender, const char *printer...)
 Logs a warning message.
 
void error (const char *sender, const char *printer...)
 Logs an error message.
 
void critical (const char *sender, const char *printer...)
 Logs a critical message.
 
void logRelay (std::string logLevel, FILE *out)
 Relays log output to a specified file for a given log level.
 
void getTimestamp (char message[MAX_CHAR_LOG_MESSAGE])
 Retrieves the current timestamp in a formatted string.
 
void getLogMask (int *mask)
 Gets the current log mask.
 
void getLogMask (char *mask)
 Gets the current log mask as a string.
 
rmmStatus setLogMask (int mask)
 Sets the log mask to the given value.
 
void setLogTimeout (int milliseconds)
 Sets the timeout for logging operations.
 
void setFileWriteTimeout (int milliseconds)
 Sets the timeout for file write operations.
 
int getFailedWrites ()
 Gets the count of failed write attempts to the log file.
 
rmmStatus putMsg (std::string msg)
 Store message in a buffer.
 
rmmStatus putInfo (const char *sender, std::string msg)
 Calls both putMsg and info methods.
 
rmmStatus putMsg (const char *message...)
 Store message in a buffer.
 
rmmStatus putInfo (const char *sender, const char *msg...)
 Calls both putMsg and info methods.
 
rmmStatus getMsg (std::string *msg)
 Get the message stored in object container.
 
rmmStatus getLogFilePath (std::string *filePath)
 Get filepath to log.
 
rmmStatus getLogFilePath (std::string *path, std::string *name)
 Retrieves the directory and filename of the log file.
 
rmmStatus setLogFilePath (std::string filePath, bool useName=false)
 Sets the log file path for the log file.
 
rmmStatus setLogFilePath (std::string path, std::string name)
 Sets the log file path using a directory and a custom file name.
 
rmmStatus setWriteToFile (bool option, char mode='w')
 Enable/disable writing to log.
 

Detailed Description

Class for managing and writing log messages to different log levels and files.

This class provides functionality for logging messages of different severities (debug, info, warning, error, and critical) to both the console and to a file. It includes timestamp handling, log masking, and support for different log levels.

Constructor & Destructor Documentation

◆ RMMLog()

RMMLog::RMMLog ( const char * name)

Constructs the RMMLog object with a name for the log.

Parameters
nameThe name to be used for the log.

Member Function Documentation

◆ critical()

void RMMLog::critical ( const char * sender,
const char * printer... )

Logs a critical message.

Parameters
[in]senderThe sender of the log message.
[in]printerThe message to log, can accept formatted arguments.

◆ debug()

void RMMLog::debug ( const char * sender,
const char * printer... )

Logs a debug message.

Parameters
[in]senderThe sender of the log message.
[in]printerThe message to log, can accept formatted arguments.

◆ error()

void RMMLog::error ( const char * sender,
const char * printer... )

Logs an error message.

Parameters
[in]senderThe sender of the log message.
[in]printerThe message to log, can accept formatted arguments.

◆ getFailedWrites()

int RMMLog::getFailedWrites ( )

Gets the count of failed write attempts to the log file.

Returns
int The number of failed writes.

◆ getLogFilePath() [1/2]

rmmStatus RMMLog::getLogFilePath ( std::string * filePath)

Get filepath to log.

Parameters
filePathPointer to string to store filepath
Returns
rmmSuccess

◆ getLogFilePath() [2/2]

rmmStatus RMMLog::getLogFilePath ( std::string * path,
std::string * name )

Retrieves the directory and filename of the log file.

Parameters
[out]pathPointer to store the directory path.
[out]namePointer to store the log file name.
Returns
rmmStatus Returns success or error.

◆ getLogMask() [1/2]

void RMMLog::getLogMask ( char * mask)

Gets the current log mask as a string.

Parameters
[out]maskPointer to a character array where the log mask will be stored.

◆ getLogMask() [2/2]

void RMMLog::getLogMask ( int * mask)

Gets the current log mask.

Parameters
[out]maskPointer to store the current log mask.

◆ getMsg()

rmmStatus RMMLog::getMsg ( std::string * msg)

Get the message stored in object container.

Parameters
msgPointer to string to store message
Returns
rmmSuccess

◆ getTimestamp()

void RMMLog::getTimestamp ( char message[MAX_CHAR_LOG_MESSAGE])

Retrieves the current timestamp in a formatted string.

Parameters
[in]messageThe timestamp string to fill.

◆ info()

void RMMLog::info ( const char * sender,
const char * printer... )

Logs an info message.

Parameters
[in]senderThe sender of the log message.
[in]printerThe message to log, can accept formatted arguments.

◆ logRelay()

void RMMLog::logRelay ( std::string logLevel,
FILE * out )

Relays log output to a specified file for a given log level.

Parameters
[in]logLevelThe level of log (debug, info, warn, error, critical).
[in]outThe file pointer to output the log messages.

◆ putInfo() [1/2]

rmmStatus RMMLog::putInfo ( const char * sender,
const char * msg... )

Calls both putMsg and info methods.

Parameters
sendername of function calling this.
msgmessage to be put into container and printed.
...arguments to format message just like printf would.
Returns
rmmStatus.

◆ putInfo() [2/2]

rmmStatus RMMLog::putInfo ( const char * sender,
std::string msg )

Calls both putMsg and info methods.

Parameters
sendername of function calling this.
msgmessage to be put into container and printed.
Returns
rmmStatus.

◆ putMsg() [1/2]

rmmStatus RMMLog::putMsg ( const char * message...)

Store message in a buffer.

Parameters
messageChar array to treat as message
...Args to format message similar to printf.
Returns
rmmSuccess if can store. rmmTimeout if can't lock thread.

◆ putMsg() [2/2]

rmmStatus RMMLog::putMsg ( std::string msg)

Store message in a buffer.

Parameters
msgString to store message
Returns
rmmSuccess if can store. rmmTimeout if can't lock thread.

◆ setFileWriteTimeout()

void RMMLog::setFileWriteTimeout ( int milliseconds)

Sets the timeout for file write operations.

Parameters
[in]millisecondsTimeout in milliseconds.

◆ setLogFilePath() [1/2]

rmmStatus RMMLog::setLogFilePath ( std::string filePath,
bool useName = false )

Sets the log file path for the log file.

This method sets the log file path based on the provided directory and file name. It can either use the default component name or a custom file name.

If useName is true, the component's name is appended with .log to form the file name. If useName is false, the method expects a complete file path (directory and name) to set as the log file path.

Parameters
[in]filePathThe directory path where the log file will be stored.
[in]useNameA flag to decide if the default name should be used (true) or if a custom name should be provided (false).
Returns
rmmStatus Returns rmmSuccess if the log file path is set correctly, or rmmError if the directory is invalid or another error occurs.

◆ setLogFilePath() [2/2]

rmmStatus RMMLog::setLogFilePath ( std::string path,
std::string name )

Sets the log file path using a directory and a custom file name.

This method sets the log file path for the log file by using the specified directory (path) and custom file name (name). If the provided directory is valid, it combines the directory and name to form the full log file path.

Parameters
[in]pathThe directory path where the log file will be stored.
[in]nameThe custom name for the log file.
Returns
rmmStatus Returns rmmSuccess if the log file path is set successfully, or rmmError if the directory is invalid or another error occurs.
Note
This method is an overload of RMMLog::setLogFilePath(std::string, bool) that explicitly accepts a directory and a custom file name.

◆ setLogMask()

rmmStatus RMMLog::setLogMask ( int mask)

Sets the log mask to the given value.

Parameters
[in]maskThe log mask to set.
Returns
rmmStatus Returns success or failure depending on mask value.

◆ setLogTimeout()

void RMMLog::setLogTimeout ( int milliseconds)

Sets the timeout for logging operations.

Parameters
[in]millisecondsTimeout in milliseconds.

◆ setWriteToFile()

rmmStatus RMMLog::setWriteToFile ( bool option,
char mode = 'w' )

Enable/disable writing to log.

Parameters
optionbool for enabling/disabling writing to log.
modewrite mode. 'w' for creating new file, 'a' for appending log to existing file.
Returns
rmmStatus. Error if mode is not append and file already exists. Success otherwise.

◆ warn()

void RMMLog::warn ( const char * sender,
const char * printer... )

Logs a warning message.

Parameters
[in]senderThe sender of the log message.
[in]printerThe message to log, can accept formatted arguments.

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