Cantera  3.1.0
Loading...
Searching...
No Matches
Logger Class Reference

Base class for 'loggers' that write text messages to log files. More...

#include <logger.h>

Inheritance diagram for Logger:
[legend]

Detailed Description

Base class for 'loggers' that write text messages to log files.

This class is used to direct log messages to application- or environment- specific output. The default is to simply print the messages to the standard output stream or standard error stream, but classes may be derived from Logger that implement other output options. This is important when Cantera is used in applications that do not display the standard output, such as Python. The Cantera Python interface derives a class from Logger that implements these methods with Python-specific procedures, insuring that the messages will be passed through to the user. It would also be possible to derive a class that displayed the messages in a pop-up window, or redirected them to a file, etc.

To install a logger, call function setLogger (global.h / misc.cpp).

See the file Cantera/python/src/pylogger.h for examples of deriving logger classes.

Definition at line 39 of file logger.h.

Public Member Functions

 Logger ()
 Constructor - empty.
 
virtual ~Logger ()
 Destructor - empty.
 
virtual void write (const string &msg)
 Write a log message.
 
virtual void writeendl ()
 Write an end of line character and flush output.
 
virtual void warn (const string &warning, const string &msg)
 Write a warning message.
 
virtual void error (const string &msg)
 Write an error message and quit.
 

Constructor & Destructor Documentation

◆ Logger()

Logger ( )
inline

Constructor - empty.

Definition at line 43 of file logger.h.

◆ ~Logger()

virtual ~Logger ( )
inlinevirtual

Destructor - empty.

Definition at line 46 of file logger.h.

Member Function Documentation

◆ write()

virtual void write ( const string &  msg)
inlinevirtual

Write a log message.

The default behavior is to write to the standard output. Note that no end-of-line character is appended to the message, and so if one is desired it must be included in the string.

Parameters
msgString message to be written to cout

Reimplemented in PythonLogger, and ExternalLogger.

Definition at line 56 of file logger.h.

◆ writeendl()

virtual void writeendl ( )
inlinevirtual

Write an end of line character and flush output.

Some systems treat endl and
differently. The endl statement causes a flushing of stdout to the screen.

Reimplemented in ExternalLogger, and PythonLogger.

Definition at line 65 of file logger.h.

◆ warn()

virtual void warn ( const string &  warning,
const string &  msg 
)
inlinevirtual

Write a warning message.

The default behavior is to write to the logging output.

Parameters
warningString specifying type of warning
msgString message to be written to cout

Reimplemented in PythonLogger, and ExternalLogger.

Definition at line 75 of file logger.h.

◆ error()

virtual void error ( const string &  msg)
inlinevirtual

Write an error message and quit.

The default behavior is to write to the standard error stream, and then call exit(). Note that no end-of-line character is appended to the message, and so if one is desired it must be included in the string. Note that this default behavior will terminate the application Cantera is invoked from (MATLAB, Excel, etc.) If this is not desired, then derive a class and reimplement this method.

Parameters
msgError message to be written to cerr.

Reimplemented in PythonLogger, ExternalLogger, and NoExitLogger.

Definition at line 90 of file logger.h.


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