• Main Page
  • Classes
  • Files
  • File List
  • File Members

Beesnest/DcLogger.h

Go to the documentation of this file.
00001 /*
00002 Copyright 2007 Erez Bibi (erezbibi@users.sourceforge.net)
00003 This file is part of Beesnest.
00004 
00005 Beesnest is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 Beesnest is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with Beesnest; if not, write to the Free Software
00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 */
00019 
00020 /* DcLogger.h: interface for the CdcLogger class. */
00021 
00022 #ifndef __CDC_LOGGER
00023 #define __CDC_LOGGER
00024 
00025 #include "DcGlobals.h"
00026 #include "DcParameters.h"
00027 #include "DcHttpTime.h"
00028 #include _GET_INCLUDE_PATH (DcMutex.h)
00029 #include _GET_INCLUDE_PATH (DcFileUtil.h)
00030 
00031 /* Period to keep the same file. */
00032 #define LOG_PERIOD_NONE     0
00033 #define LOG_PERIOD_DAY      1
00034 #define LOG_PERIOD_WEEK     2
00035 #define LOG_PERIOD_MONTH    3
00036 
00037 /* Name of log files to pass to CdcHttpTime.Format. */
00038 #define LOG_NAME_NONE       "beesnest.log"
00039 #define LOG_NAME_DAY        "beesnest_%m%d%Y.log"
00040 #define LOG_NAME_WEEK       "beesnest_week%Wof%Y.log"
00041 #define LOG_NAME_MONTH      "beesnest_month%mof%Y.log"
00042 
00043 /**
00044  * This simple class is to handle the log file. It logs data according to the
00045  * Log Level setting in the configuration file. It replaces the log file every
00046  * day, week, month or never, also according to the Log configuration. The class
00047  * prints to a file, and if the application is running in console mode, it
00048  * prints to the console as well. It does not prints to the console the Requests
00049  * data though.
00050  *
00051  * <p>
00052  * @author Erez Bibi
00053  * @version 1.0
00054  */
00055 class CdcLogger
00056 {
00057 private:
00058     /** The log file print level (0..5). */
00059     int nPrintLevel; /* Define in Global.h */
00060     /** The Log period (how often to replace the file. */
00061     int nPeriod;
00062     /** The log file. */
00063     ofstream oLogFile;
00064     /** Mutex for the <b>PrintString</b> function. */
00065     CdcMutex goMutex;
00066     /** The time the current log file was opened. */
00067     CdcHttpTime tLogOpen;
00068 
00069 
00070     /**
00071      * Opens a new log file, with a name according to the Log Period.
00072      */
00073     void OpenLogFile ();
00074 
00075     /**
00076      * Close the log file.
00077      */
00078     void CloseLogFile ();
00079 
00080     /**
00081      * This function check if it is time to replace the log file.
00082      * <p>
00083      * @return True if need to replace file.
00084      */
00085     bool CheckReplaceLogFile ();
00086 
00087 public:
00088     /**
00089      * Constructor - Takes the Log Level and Log Period from the configuration
00090      * file.
00091      */
00092     CdcLogger ()    /* Print Level General is so we get error message if cannot init. */
00093     : nPrintLevel (PS_GEN), nPeriod (LOG_PERIOD_NONE) {}
00094 
00095     /**
00096      * Destructor - Just close the log file.
00097      */
00098     virtual ~CdcLogger () { CloseLogFile (); }
00099 
00100     /**
00101      * This function prints a string to the log file.
00102      * <p>
00103      * @param str The string to print.
00104      * @param level The Log Level of this string. It will not print the string
00105      *  if the level is higher the the general Log Level.
00106      * @param console True if the application is running in a console mode.
00107      */
00108     void PrintString (CdcString str, int level, bool console);
00109 
00110     /**
00111      * I have To initialize the class after I initialize CdcParameters. but if
00112      * CdcParameters fails to read the configuration files, I still need to be
00113      * able to print a message on the console. So the constructor just makes
00114      * this class ready to print general messages to the console, and this
00115      * function does the rest of the initialization.
00116      */
00117     void Init ();
00118 };
00119 
00120 #endif /* __CDC_LOGGER */
00121 
00122 

Generated on Mon Oct 11 2010 16:23:24 for Beesnest by  doxygen 1.7.2