Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

plog.h

Go to the documentation of this file.
00001 /*
00002  *   P::Classes - Portable C++ Application Framework
00003  *   Copyright (C) 2000-2003  Christian Prochnow <cproch@seculogix.de>
00004  *
00005  *   This library is free software; you can redistribute it and/or
00006  *   modify it under the terms of the GNU Lesser General Public
00007  *   License as published by the Free Software Foundation; either
00008  *   version 2 of the License, or (at your option) any later version.
00009  *
00010  *   This library 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 GNU
00013  *   Lesser General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU Lesser General Public
00016  *   License along with this library; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #ifndef _plog_h_
00021 #define _plog_h_
00022 
00023 #include <pclasses/pexport.h>
00024 #include <pclasses/pexception.h>
00025 #include <pclasses/pcriticalsection.h>
00026 #include <pclasses/pthreadkey.h>
00027 #include <pclasses/ptime.h>
00028 #include <set>
00029 #include <list>
00030 #include <string>
00031 #include <iostream>
00032 
00033 namespace P {
00034 
00036 
00040 enum LogLevel {
00041   LOG_DEBUG = 0,    
00042   LOG_INFO,         
00043   LOG_NOTICE,       
00044   LOG_WARNING,      
00045   LOG_ERROR,        
00046   LOG_CRITICAL,     
00047   LOG_EMERGENCY     
00048 };
00049 
00051 
00056 class PCORE_EXPORT Logger {
00057   public:
00058     Logger();
00059     virtual ~Logger();
00060 
00061     inline void setLogLevel(LogLevel l)
00062     { m_level = l; }
00063 
00064     inline LogLevel logLevel() const
00065     { return m_level; }
00066 
00067     virtual void start(const std::string& path) = 0;
00068     virtual void stop() = 0;
00069     virtual void restart() = 0;
00070 
00071     virtual bool isActive() const = 0;
00072 
00073     virtual void output(const DateTime& t, LogLevel l, const std::string& ident, const std::string& subsys, const char* msg) = 0;
00074 
00075     static std::string logLevel2Str(LogLevel l);
00076     static LogLevel str2LogLevel(const std::string& str);
00077 
00078   private:
00079     LogLevel  m_level;
00080 };
00081 
00083 
00092 class PCORE_EXPORT SystemLog: protected std::streambuf, public std::ostream
00093 {
00094   public:
00096 
00099     SystemLog(const std::string& ident);
00100     ~SystemLog();
00101 
00103     inline const std::string& ident() const
00104     { return m_ident; }
00105 
00107     void addLogger(Logger* log);
00108 
00110     bool removeLogger(Logger* log);
00111 
00113     void restart();
00114 
00116     void enableSubsys(const std::string& name);
00117 
00119     void disableSubsys(const std::string& name);
00120 
00122     SystemLog& operator()(const std::string& subsys, LogLevel l);
00123 
00125     SystemLog& operator()(LogLevel l);
00126 
00127     inline const std::list<Logger*> loggers() const
00128     { return m_loggers; }
00129 
00130   protected:
00131     int overflow(int c);
00132 
00133   private:
00134     struct LogState;
00135     LogState* state();
00136 
00137     std::string           m_ident;
00138     ThreadKey<LogState>   m_state;
00139     CriticalSection       m_lock;
00140     std::list<Logger*>    m_loggers;
00141     std::set<std::string> m_disabled;
00142 };
00143 
00149 }
00150 
00151 #endif

Generated on Fri Mar 12 21:08:31 2004 for P::Classes by doxygen 1.3.3