From: Christian P. <cp...@us...> - 2005-01-10 02:39:05
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/App In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21795/include/pclasses/App Added Files: LogChannel.h LogManager.h LogMessage.h LogTarget.h Makefile.am Log Message: Added Logging framework --- NEW FILE: LogMessage.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_LogMessage_h #define P_LogMessage_h #include <pclasses/DateTime.h> #include <pclasses/Unicode/String.h> #include <string> namespace P { namespace App { //! Log message class class LogMessage { public: //! Log message level enum Level { Debug, Info, Notice, Warning, Error, Critical }; LogMessage(const DateTime& when, Level l, const Unicode::String& msg); ~LogMessage() throw(); const DateTime& when() const throw(); Level level() const throw(); const Unicode::String& msg() const throw(); static std::string level2Str(Level l); static Level str2Level(const std::string& l); private: DateTime _when; Level _level; Unicode::String _msg; }; } // !namespace App } // !namespace P #endif --- NEW FILE: Makefile.am --- INCLUDES = METASOURCES = AUTO pkginclude_HEADERS = AppDetails.h LogMessage.h LogTarget.h LogChannel.h LogManager.h --- NEW FILE: LogTarget.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_LogTarget_h #define P_LogTarget_h #include <pclasses/Factory.h> #include <pclasses/IO/IOError.h> #include <pclasses/IO/URL.h> #include <pclasses/App/LogMessage.h> namespace P { namespace App { //! Log message target class LogTarget { public: LogTarget(); virtual ~LogTarget() throw(); //! Opens the logging target virtual void open(const IO::URL& url) throw(IO::IOError) = 0; //! Closes the logging target virtual void close() throw(IO::IOError) = 0; //! Close and re-open the logging target virtual void reload() throw(IO::IOError) = 0; //! Output log message to target virtual void output(const LogMessage& msg) throw(IO::IOError) = 0; //! Test if the target is valid virtual bool valid() const throw() = 0; //! Returns current log level LogMessage::Level logLevel() const throw(); //! Set log level void setLogLevel(LogMessage::Level l) throw(); private: LogMessage::Level _logLevel; }; //! LogTarget factory typedef NamedTypeFactory<LogTarget> LogTargetFactory; } // !namespace App } // !namespace P #endif --- NEW FILE: LogChannel.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_LogChannel_h #define P_LogChannel_h #include <pclasses/IO/IOError.h> #include <pclasses/App/LogMessage.h> #include <string> #include <map> #include <iostream> namespace P { namespace App { class LogTarget; //! Log message channel class LogChannel: public std::ostream { public: typedef std::map<std::string, LogTarget*> TargetMap; LogChannel(); ~LogChannel() throw(); //! Add a logging target bool addTarget(const std::string& name, LogTarget* target); //! Remove named logging target LogTarget* removeTarget(const std::string& name) throw(); //! Remove logging target by pointer bool removeTarget(LogTarget* target) throw(); //! Close and re-open all targets void reload() const throw(); //! Output log message to all targets void output(const LogMessage& msg) const throw(); //! Returns current log level LogMessage::Level logLevel() const throw(); //! Set log level void setLogLevel(LogMessage::Level l) throw(); //! Switch stream message level LogChannel& operator()(LogMessage::Level) throw(); private: TargetMap _targets; LogMessage::Level _logLevel; }; } // !namespace App } // !namespace P #endif --- NEW FILE: LogManager.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_LogManager_h #define P_LogManager_h #include <pclasses/App/LogTarget.h> #include <pclasses/App/LogChannel.h> #include <map> #include <string> namespace P { namespace App { //! Log manager class LogManager { public: //! Map of LogChannels typedef std::map<std::string,LogChannel*> ChannelMap; //! Map of owned LogTargets typedef std::map< std::pair<LogChannel*, std::string>, LogTarget* > TargetMap; LogManager(); ~LogManager() throw(); //! Close and re-open all LogTargets void reload() throw(); //! Add logging channel /*! Returns NULL if the named LogChannel already exists. The LogChannel is owned by the LogManager. */ LogChannel* addChannel(const std::string& name); //! Remove logging channel bool removeChannel(const std::string& name); //! Returns a pointer to the named LogChannel /*! Returns NULL if the named LogChannel does not exist. */ LogChannel* channel(const std::string& name) const; //! Add a logging target /*! Returns NULL if the target already exists, or the LogTarget type is not registered. The LogTarget is owned by the LogManager. */ LogTarget* addTarget(LogChannel* chan, const std::string& name, const std::string& type); //! Remove a logging target bool removeTarget(LogChannel* chan, const std::string& name); //! Returns a refernce to the named LogChannel /*! If the channel does not exist it is created. */ LogChannel& operator()(const std::string& channel); //! Returns the instance of the LogManager static LogManager& instance(); private: ChannelMap _channels; TargetMap _targets; }; } // !namespace App } // !namespace P #endif |