Main Page | Class Hierarchy | Class List | File List | Class Members

aedLog.h

00001 
00002 /*
00003  * The aedLog class
00004  * This class provides a simple logging mechanism for the aedGUI library
00005  * ewodarz@blackfoot.net
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Library General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Library General Public
00018  * License along with this library; if not, write to the Free
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  */
00022 
00023 #ifndef AEDLOG_H
00024 #define AEDLOG_H
00025 
00026 #include <iostream>
00027 #include <ostream>
00028 #include <fstream>
00029 #include <vector>
00030 #include "dllmacros.h"
00031 
00032 /*
00033  * The aedLog class provides logging facility. It logs everything to standard
00034  * error but is capable of logging to various other output streams as well.
00035  *
00036  * Sample usage:
00037  *
00038  * ofstream mylog("my_log.txt"), anotherlog("blah.txt");
00039  * pLog->addDestination(&mylog);
00040  * pLog->addDestination(&anotherlog);
00041  * 
00042  * The addDestination() function returns an integer which identifies the
00043  * output stream used so you can use it later to stop writing log information
00044  * to that stream. Example:
00045  * 
00046  * unsigned int i = pLog->addDestination(&somefile);
00047  * ...
00048  * pLog->removeDestination(i);
00049  * 
00050  * You can use four functions to log information: notice(), warning(), error()
00051  * and fatal(). The last one terminates the app. All four functions prefix
00052  * the output string with "aedGUI: ". Example:
00053  * 
00054  * pLog->notice("opening font %s", fontname);
00055  * pLog->warning("font cache size too big");
00056  * pLog->error("couldn't open font, error %d", err);
00057  * pLog->fatal("SDL_Surface pointer is 0!");
00058  * 
00059  * You can prevent aedLog from writing certain kinds of messages with 
00060  * pLog->setMask(), like this:
00061  * 
00062  * pLog->setMask(AED_LOG_WARNING); // this causes warnings not to show up in
00063  *                                      the log
00064  * pLog->setMask(AED_LOG_ALL); // this turns off all log messages (except 
00065  *                                  fatal errors)
00066  */
00067 
00068 enum
00069 {
00070     AED_LOG_NOTICE = 1,
00071     AED_LOG_WARNING = 2,
00072     AED_LOG_ERROR = 4,
00073     AED_LOG_ALL = AED_LOG_NOTICE | AED_LOG_WARNING | AED_LOG_ERROR
00074 };
00075 
00076 class DLLEXPORT aedLog
00077 {
00078   public:
00079     void notice(const char *msg, ...);
00080     void warning(const char *msg, ...);
00081     void error(const char *msg, ...);
00082     void fatal(const char *msg, ...);
00083     unsigned int addDestination(std::ostream * out);
00084     void removeDestination(unsigned int index);
00085     int getMask()
00086     {
00087         return m_Mask;
00088     }
00089     void setMask(int mask)
00090     {
00091         m_Mask = mask;
00092     }
00093 
00094   private:
00095     std::vector < std::ostream * >m_Destinations;
00096     int m_Mask;
00097     static const int m_BufferSize = 1024;
00098 
00099     friend class aedApp;
00100 
00101     aedLog();
00102     void operator=(const aedLog &);
00103     void output(const char *prefix, const char *str);
00104 };
00105 
00106 #ifdef AEDGUI
00107 // This is a pointer to the global aedLog object, initialized
00108 // in aedApp's constructor
00109 extern DLLEXPORT aedLog *pLog;
00110 #endif
00111 
00112 #endif /* AEDLOG_H */

Generated on Mon Mar 1 19:56:18 2004 for aedGUI by doxygen 1.3.6