/**

* Class Logger written by Justin Klein, 2003

* Revised 2004

  **/

 

 

/**

* This class can be used to log events to a Console Window in Windows, to a specified

* logFile, or both.  The console can be hidden or shown at any time.  It can also

* redirect anything that is printed to stdout or stderr to specified files.  Finally,

* it can be used as a command interpreter, where you can type commands into a console

* window, they’re parsed, and returned for processing.

**/

 

 

/**

  * Initializes a Logger

*   -logFileName specifies the file which will be logged to

*    (NULL logs to c:\logFile.log)

*   -logFileHeader contains a string that will be written as a header

*    (NULL to writes a default header)

  * If the file exists, its contents will be destroyed.

  **/

            void Init(char* logFileName, char* logFileHeader);

 

/**

  * Appends a new message to the logfile, and to the console (if it's visible).

  **/

            void write(char* msg);

 

 

/**

* Appends a new message to the logfile, and to the console (if it's visible).

* Can be used with printf-style param lists.

  **/

            void writef(char* msg, ...);

 

 

/**

  * "Flushes" the logger, by closing its output file and reopening it.

  **/

            void flush();

 

 

/**

  * Writes a message only to the console, without writing to the logfile.

  * Has no effect if the console is currently invisible.

  **/

            void writeToConsole(char* msg);

 

 

 

/**

  * Collects input from the console! If the user hasn't typed anything, an empty string

  * is returned; otherwise the user-entered string is returned.  This message-processing

  * loop of a console-based application that uses this class should be structured something like:

      MSG msg;

    PeekMessage( &msg, NULL, 0U, 0U, PM_NOREMOVE );

      while( msg.message != WM_QUIT )

      {

            if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))                //if a message is waiting, dispatch it

            {

                  TranslateMessage(&msg);

                  DispatchMessage(&msg);

            }

            else

                  ProcessInput();                                                         //THIS IS WHERE you'd readFromConsole,

      }                                                                                         //And parse the returned commands.

      *

      * IMPORTANT NOTE: A logger should only be used as EITHER a command interpreter OR a

      * logger, not both; once readFromConsole() is called, messages that are printed to

      * the console window will NOT be reflected (they will, however, still be reflected in

      * the logfile).  Likewise, commands entered here are NOT stored in the logfile.                                                                                   //And parse the returned commands.

  **/

            char* readFromConsole();

 

 

 

/**

  * Displays the log in a console window

  **/

            void showConsole();

 

 

/**

  * Hides the console window, if present.

  **/

            void hideConsole();

 

 

/**

  * Returns TRUE if the console is currently visible, FALSE otherwise.

  **/

            BOOL isConsoleVisible();

 

 

/**

  * Returns the filename currently being used by the logger int he param;

  * ensure that the "name" string is long enough to support the filename

  **/

            void getFileName(char* name);

 

 

/**

  * Begins redirecting stdout & stderr to the specified files; anything printed

  * to either of these streams between a call to this function and a call to

  * endStdRedirect will be written instead to the filenames specified here.

  * If the streams could not be redirected, false is returned and nothing is changed.

  **/

            BOOL beginStdRedirect(char *stdoutFile, char *stderrFile);

 

 

/**

  * Stops redirecting stdout & stderr, and restores them to their normal state;

  * if beginStdRedirect has not been called, this function has no effect.

  **/

            void endStdRedirect();