/* * Copyright 2003,2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #ifndef _LOG4CXX_LEVEL_H #define _LOG4CXX_LEVEL_H // Windows specific : // wingdi.h defines ERROR #ifdef ERROR #define OLD_ERROR ERROR #undef ERROR #endif // Windows specific : // atldef.h defines DEBUG #ifdef DEBUG #define OLD_DEBUG DEBUG #undef DEBUG #endif namespace log4cxx { class Level; /** smart pointer to a Level instance */ typedef helpers::ObjectPtrT LevelPtr; /** Defines the minimum set of levels recognized by the system, that is OFF, FATAL, ERROR, WARN, INFO, DEBUG and ALL.

The Level class may be subclassed to define a larger level set. */ class LOG4CXX_EXPORT Level : public helpers::ObjectImpl { public: class LOG4CXX_EXPORT LevelClass : public helpers::Class { protected: LevelClass(const String& className) : helpers::Class(className) {} public: LevelClass() : helpers::Class(_T("Level")) {} virtual const LevelPtr& toLevel(const String& sArg) const { return Level::toLevel(sArg); } virtual const LevelPtr& toLevel(int val) const { return Level::toLevel(val); } }; DECLARE_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(Level, LevelClass) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(Level) END_LOG4CXX_CAST_MAP() /** Instantiate a Level object. */ Level(int level, const String& levelStr, int syslogEquivalent); /** Convert the string passed as argument to a level. If the conversion fails, then this method returns #DEBUG. */ static const LevelPtr& toLevel(const String& sArg); /** Convert an integer passed as argument to a level. If the conversion fails, then this method returns #DEBUG. */ static const LevelPtr& toLevel(int val); /** Convert an integer passed as argument to a level. If the conversion fails, then this method returns the specified default. */ static const LevelPtr& toLevel(int val, const LevelPtr& defaultLevel); /** Convert the string passed as argument to a level. If the conversion fails, then this method returns the value of defaultLevel. */ static const LevelPtr& toLevel(const String& sArg, const LevelPtr& defaultLevel); enum { OFF_INT = INT_MAX, FATAL_INT = 50000, ERROR_INT = 40000, WARN_INT = 30000, INFO_INT = 20000, DEBUG_INT = 10000, ALL_INT = INT_MIN }; /** The ALL level designates all the levels */ static const LevelPtr ALL; /** The FATAL level designates very severe error events that will presumably lead the application to abort. */ static const LevelPtr FATAL; /** The ERROR level designates error events that might still allow the application to continue running. */ static const LevelPtr ERROR; /** The WARN level designates potentially harmful situations. */ static const LevelPtr WARN; /** The INFO level designates informational messages that highlight the progress of the application at coarse-grained level. */ static const LevelPtr INFO; /** The DEBUG level designates fine-grained informational events that are most useful to debug an application. */ static const LevelPtr DEBUG; /** The OFF level designates not set level */ static const LevelPtr OFF; /** Two levels are equal if their level fields are equal. */ virtual bool equals(const LevelPtr& level) const; inline bool operator==(const Level& level) const { return (this->level == level.level); } inline bool operator!=(const Level& level) const { return (this->level != level.level); } /** Return the syslog equivalent of this level as an integer. */ virtual int getSyslogEquivalent() const; /** Returns true if this level has a higher or equal level than the level passed as argument, false otherwise.

You should think twice before overriding the default implementation of isGreaterOrEqual method. */ virtual bool isGreaterOrEqual(const LevelPtr& level) const; /** Returns the string representation of this priority. */ virtual const String& toString() const; /** Returns the integer representation of this level. */ virtual int toInt() const; public: int level; String levelStr; int syslogEquivalent; }; } #define DECLARE_LOG4CXX_LEVEL(level)\ public:\ class Class##level : public Level::LevelClass\ {\ public:\ Class##level() : Level::LevelClass(_T(#level)) {}\ virtual const LevelPtr& toLevel(const String& sArg) const\ { return level::toLevel(sArg); }\ virtual const LevelPtr& toLevel(int val) const\ { return level::toLevel(val); }\ };\ DECLARE_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(level, Class##level) #define IMPLEMENT_LOG4CXX_LEVEL(level) \ IMPLEMENT_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(level, Class##level) #endif //_LOG4CXX_LEVEL_H