kspaceFirstOrder3D-OMP  1.2
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
Logger Class Reference

Static class implementing the user interface by info messages. More...

#include <Logger.h>

Public Types

enum  LogLevel { LogLevel::kBasic = 0, LogLevel::kAdvanced = 1, LogLevel::kFull = 2 }
 Log level of the message. More...
 

Public Member Functions

 Logger ()=delete
 Default constructor is not allowed, static class.
 
 Logger (const Logger &)=delete
 Copy constructor is not allowed, static class.
 
 ~Logger ()=delete
 Destructor is not allowed, static class.
 
Loggeroperator= (const Logger &)=delete
 Operator= is not allowed, static class.
 

Static Public Member Functions

static void setLevel (const LogLevel actualLogLevel)
 Set the log level. More...
 
static LogLevel getLevel ()
 
template<typename... Args>
static void log (const LogLevel queryLevel, const std::string &format, Args ... args)
 Log desired activity for a given log level, version with string format. More...
 
static void log (const LogLevel queryLevel, const std::string &message)
 Log desired activity for a given log level. More...
 
static void error (const std::string &errorMessage)
 Log an error. More...
 
static void errorAndTerminate (const std::string &errorMessage)
 Log an error and terminate the execution. More...
 
static void flush (const LogLevel queryLevel)
 Flush output messages. More...
 
static std::string wordWrapString (const std::string &inputString, const std::string &delimiters, const int indentation=0, const int lineSize=65)
 
template<typename ... Args>
static std::string formatMessage (const std::string &format, Args ... args)
 C++-11 replacement for sprintf that works with std::string instead of char*. More...
 

Static Private Member Functions

static std::string getWord (std::istringstream &textStream, const std::string &delimiters)
 Extract a word from a string stream based on delimiters. More...
 

Static Private Attributes

static LogLevel slogLevel = LogLevel::kBasic
 Log level of the logger. More...
 

Detailed Description

StaticClass used for printing out info and error message based on the verbose level.
This is a static class.

Definition at line 49 of file Logger.h.

Member Enumeration Documentation

◆ LogLevel

enum Logger::LogLevel
strong

A enum to specify at which log level the message should be displayed, or the level setd.

Enumerator
kBasic 

Basic (default) level of verbosity.

kAdvanced 

Advanced level of verbosity.

kFull 

Full level of verbosity.

Definition at line 58 of file Logger.h.

Member Function Documentation

◆ error()

void Logger::error ( const std::string &  errorMessage)
static
Parameters
[in]errorMessage- Error message to be printed out.

Log an error.

Definition at line 73 of file Logger.cpp.

◆ errorAndTerminate()

void Logger::errorAndTerminate ( const std::string &  errorMessage)
static
Parameters
[in]errorMessage- error message to be printed to stderr.

Log an error and terminate the execution.

Definition at line 84 of file Logger.cpp.

◆ flush()

void Logger::flush ( const LogLevel  queryLevel)
static
Parameters
[in]queryLevel- Log level of the flush.

Flush logger, output messages only.

Definition at line 97 of file Logger.cpp.

◆ formatMessage()

template<typename ... Args>
static std::string Logger::formatMessage ( const std::string &  format,
Args ...  args 
)
inlinestatic

The routine was proposed at http://stackoverflow.com/questions/2342162/stdstring-formatting-like-sprintf and should work with both Linux and VS 2015. However it still does not support string in formated arguments

Parameters
[in]format- Format string.
[in]args- Arguments, std::string is not accepted.
Returns
Formated string.

Definition at line 157 of file Logger.h.

◆ getLevel()

static LogLevel Logger::getLevel ( )
inlinestatic

Get current log level.

Returns
Current log level.

Definition at line 87 of file Logger.h.

◆ getWord()

string Logger::getWord ( std::istringstream &  textStream,
const std::string &  delimiters 
)
staticprivate
Parameters
[in,out]textStream- Input text stream.
[in]delimiters- List of delimiters as a single string.
Returns
A word from the string.

Extract a word from a string stream based on delimiters.

Definition at line 177 of file Logger.cpp.

◆ log() [1/2]

template<typename... Args>
static void Logger::log ( const LogLevel  queryLevel,
const std::string &  format,
Args ...  args 
)
inlinestatic
Parameters
[in]queryLevel- What level to use.
[in]format- Format string.
[in]args- Arguments, std::string is not accepted.

Definition at line 97 of file Logger.h.

◆ log() [2/2]

void Logger::log ( const LogLevel  queryLevel,
const std::string &  message 
)
static
Parameters
[in]queryLevel- Log level of the message.
[in]message- Message to log.

Log desired activity.

Definition at line 60 of file Logger.cpp.

◆ setLevel()

void Logger::setLevel ( const LogLevel  actualLogLevel)
static
Parameters
[in]actualLogLevel- Log level for the logger.

Initialise or change logging level.

Definition at line 51 of file Logger.cpp.

◆ wordWrapString()

string Logger::wordWrapString ( const std::string &  inputString,
const std::string &  delimiters,
const int  indentation = 0,
const int  lineSize = 65 
)
static

Wrap the line based on delimiters and align it with the rest of the logger output.

Parameters
[in]inputString- Input string.
[in]delimiters- String of delimiters, every char is a delimiter.
[in]indentation- Indentation from the beginning.
[in]lineSize- Line size.
Returns
Wrapped string.
Note
The string must not contain tabulator and end-of-line characters.

Wrap the line based on delimiters and align it with the rest of the logger output.

Definition at line 111 of file Logger.cpp.

Member Data Documentation

◆ slogLevel

Logger::LogLevel Logger::slogLevel = LogLevel::kBasic
staticprivate

static declaration of the LogLevel private field

Definition at line 181 of file Logger.h.


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