Apache log4cxx  Version 0.12.0
level.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _LOG4CXX_LEVEL_H
19 #define _LOG4CXX_LEVEL_H
20 
21 
22 #include <log4cxx/logstring.h>
23 #include <limits.h>
24 #include <log4cxx/helpers/object.h>
25 
26 #if defined(_MSC_VER)
27  #pragma warning ( push )
28  #pragma warning ( disable: 4251 )
29 #endif
30 
31 namespace log4cxx
32 {
41 class Level;
42 typedef std::shared_ptr<Level> LevelPtr;
43 
52 class LOG4CXX_EXPORT Level : public helpers::Object
53 {
54  public:
55  class LOG4CXX_EXPORT LevelClass : public helpers::Class
56  {
57  public:
58  LevelClass() : helpers::Class() {}
59 
60  virtual LogString getName() const
61  {
62  return LOG4CXX_STR("Level");
63  }
64 
65  virtual LevelPtr toLevel(const LogString& sArg) const
66  {
67  return Level::toLevelLS(sArg);
68  }
69 
70  virtual LevelPtr toLevel(int val) const
71  {
72  return Level::toLevel(val);
73  }
74  };
75 
80 
81 
84  Level(int level,
85  const LogString& name,
86  int syslogEquivalent);
87 
93  static LevelPtr toLevel(const std::string& sArg);
102  static LevelPtr toLevel(const std::string& sArg,
103  const LevelPtr& defaultLevel);
108  void toString(std::string& name) const;
109 
110 #if LOG4CXX_WCHAR_T_API
111 
116  static LevelPtr toLevel(const std::wstring& sArg);
125  static LevelPtr toLevel(const std::wstring& sArg,
126  const LevelPtr& defaultLevel);
131  void toString(std::wstring& name) const;
132 #endif
133 #if LOG4CXX_UNICHAR_API
134 
139  static LevelPtr toLevel(const std::basic_string<UniChar>& sArg);
148  static LevelPtr toLevel(const std::basic_string<UniChar>& sArg,
149  const LevelPtr& defaultLevel);
154  void toString(std::basic_string<UniChar>& name) const;
155 #endif
156 #if LOG4CXX_CFSTRING_API
157 
162  static LevelPtr toLevel(const CFStringRef& sArg);
171  static LevelPtr toLevel(const CFStringRef& sArg,
172  const LevelPtr& defaultLevel);
177  void toString(CFStringRef& name) const;
178 #endif
179 
184  static LevelPtr toLevelLS(const LogString& sArg);
193  static LevelPtr toLevelLS(const LogString& sArg,
194  const LevelPtr& defaultLevel);
199  LogString toString() const;
200 
205  static LevelPtr toLevel(int val);
206 
211  static LevelPtr toLevel(int val, const LevelPtr& defaultLevel);
212 
213  enum
214  {
215  OFF_INT = INT_MAX,
216  FATAL_INT = 50000,
217  ERROR_INT = 40000,
218  WARN_INT = 30000,
219  INFO_INT = 20000,
220  DEBUG_INT = 10000,
221  TRACE_INT = 5000,
222  ALL_INT = INT_MIN
223  };
224 
225 
226  static void initializeLevels();
227  static LevelPtr getAll();
228  static LevelPtr getFatal();
229  static LevelPtr getError();
230  static LevelPtr getWarn();
231  static LevelPtr getInfo();
232  static LevelPtr getDebug();
233  static LevelPtr getTrace();
234  static LevelPtr getOff();
235 
236 
240  virtual bool equals(const LevelPtr& level) const;
241 
242  inline bool operator==(const Level& level1) const
243  {
244  return (this->level == level1.level);
245  }
246 
247  inline bool operator!=(const Level& level1) const
248  {
249  return (this->level != level1.level);
250  }
251 
255  inline int getSyslogEquivalent() const
256  {
257  return syslogEquivalent;
258  }
259 
260 
270  virtual bool isGreaterOrEqual(const LevelPtr& level) const;
271 
272 
276  inline int toInt() const
277  {
278  return level;
279  }
280 
281  private:
282  static volatile bool initialized;
283  static std::mutex initMutex;
284  static LevelPtr allLevel;
285  static LevelPtr fatalLevel;
286  static LevelPtr errorLevel;
287  static LevelPtr warnLevel;
288  static LevelPtr infoLevel;
289  static LevelPtr debugLevel;
290  static LevelPtr traceLevel;
291  static LevelPtr offLevel;
292 
293  int level;
294  LogString name;
295  int syslogEquivalent;
296  Level(const Level&);
297  Level& operator=(const Level&);
298 };
299 
300 }
301 
302 #define DECLARE_LOG4CXX_LEVEL(level)\
303  public:\
304  class Class##level : public Level::LevelClass\
305  {\
306  public:\
307  Class##level() : Level::LevelClass() {}\
308  virtual LogString getName() const { return LOG4CXX_STR(#level); } \
309  virtual LevelPtr toLevel(const LogString& sArg) const\
310  { return level::toLevelLS(sArg); }\
311  virtual LevelPtr toLevel(int val) const\
312  { return level::toLevel(val); }\
313  };\
314  DECLARE_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(level, Class##level)
315 
316 #define IMPLEMENT_LOG4CXX_LEVEL(level) \
317  IMPLEMENT_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(level, Class##level)
318 
319 #if defined(_MSC_VER)
320  #pragma warning (pop)
321 #endif
322 
323 #endif //_LOG4CXX_LEVEL_H
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:148
LevelClass()
Definition: level.h:58
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:142
std::shared_ptr< Level > LevelPtr
Definition: optionconverter.h:27
static LevelPtr toLevel(const std::string &sArg)
Convert the string passed as argument to a level.
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:136
virtual LevelPtr toLevel(const LogString &sArg) const
Definition: level.h:65
const struct __CFString * CFStringRef
Definition: logstring.h:36
static LevelPtr toLevelLS(const LogString &sArg)
Convert the string passed as argument to a level.
base class for java-like objects.
Definition: object.h:101
bool operator!=(const Level &level1) const
Definition: level.h:247
int getSyslogEquivalent() const
Return the syslog equivalent of this level as an integer.
Definition: level.h:255
#define DECLARE_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(object, class)
Definition: object.h:56
Definition: class.h:37
int toInt() const
Returns the integer representation of this level.
Definition: level.h:276
virtual LevelPtr toLevel(int val) const
Definition: level.h:70
Defines the minimum set of levels recognized by the system, that is OFF, FATAL, ERROR, WARN, INFO, DEBUG and ALL.
Definition: level.h:52
Definition: level.h:55
Definition: appender.h:32
virtual LogString getName() const
Definition: level.h:60
std::basic_string< logchar > LogString
Definition: logstring.h:66
bool operator==(const Level &level1) const
Definition: level.h:242