logger.h

Go to the documentation of this file.
00001 /**
00002  * @file logger.h
00003  * Header for Base class for 'loggers' that write text messages to log files
00004  * (see \ref textlogs and class \link Cantera::Logger Logger\endlink).
00005  */
00006 /*
00007  * $Id: logger.h 368 2010-01-04 00:46:26Z hkmoffa $
00008  */
00009 
00010 #ifndef CT_LOGGER_H
00011 #define CT_LOGGER_H
00012 
00013 #include <iostream>
00014 
00015 #include <cstdlib>
00016 
00017 namespace Cantera {
00018 
00019     ///
00020     /// Base class for 'loggers' that write text messages to log files.
00021     ///
00022     /// This class is used to direct log messages to application- or
00023     /// environment-specific output. The default is to simply print
00024     /// the messages to the standard output stream or standard error
00025     /// stream, but classes may be derived from Logger that implement
00026     /// other output options. This is important when Cantera is used
00027     /// in applications that do not display the standard output, such
00028     /// as MATLAB.  The Cantera MATLAB interface derives a class from
00029     /// Logger that implements these methods with MATLAB-specific
00030     /// procedures, insuring that the messages will be passed through
00031     /// to the user. It would also be possible to derive a class that
00032     /// displayed the messages in a pop-up window, or redirected them
00033     /// to a file, etc.
00034     ///  
00035     /// To install a logger, call function setLogger (global.h / misc.cpp).
00036     ///
00037     /// See the files Cantera/python/src/pylogger.h and
00038     /// Cantera/matlab/cantera/private/mllogger.h for examples of
00039     /// deriving logger classes.
00040     /// @ingroup textlogs
00041     ///
00042     class Logger {
00043     public:
00044 
00045       //! Constructor - empty
00046       Logger() {}
00047 
00048       //! Destructor - empty
00049       virtual ~Logger() {}
00050 
00051       //! Write a log message.
00052       /*!
00053        *  The default behavior is to write to
00054        *  the standard output. Note that no end-of-line character is
00055        *  appended to the message, and so if one is desired it must
00056        *  be included in the string.
00057        *
00058        * @param msg      String message to be written to cout
00059        */
00060       virtual void write(const std::string& msg) {
00061         std::cout << msg;
00062       }
00063 
00064       //! Write an end of line character and flush output.
00065       /*!
00066        *  Some systems treat endl and \n differently. The endl
00067        *  statement causes a flushing of stdout to the screen.
00068        */
00069       virtual void writeendl() {
00070         std::cout << std::endl;
00071       }
00072 
00073       //! Write an error message and quit. 
00074       /*! 
00075        *  The default behavior is
00076        *  to write to the standard eror stream, and then call
00077        *  exit(). Note that no end-of-line character is appended to
00078        *  the message, and so if one is desired it must be included
00079        *  in the string. Note that this default behavior will
00080        *  terminate the application Cantera is invoked from (MATLAB,
00081        *  Excel, etc.) If this is not desired, then derive a class
00082        *  and reimplement this method.
00083        *
00084        * @param msg    Error message to be written to cerr.
00085        */
00086       virtual void error(const std::string& msg) {
00087         std::cerr << msg << std::endl;
00088         exit(EXIT_FAILURE);
00089       }
00090 
00091       /// Return an integer specifying the application environment.
00092       virtual int env() { return 0; }
00093     };
00094 
00095 }
00096 #endif
Generated by  doxygen 1.6.3