Apache log4cxx Version 0.13.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>
25#include <mutex>
26
27#if defined(_MSC_VER)
28 #pragma warning ( push )
29 #pragma warning ( disable: 4251 )
30#endif
31
32namespace log4cxx
33{
42class Level;
43typedef std::shared_ptr<Level> LevelPtr;
44
53class LOG4CXX_EXPORT Level : public helpers::Object
54{
55 public:
56 class LOG4CXX_EXPORT LevelClass : public helpers::Class
57 {
58 public:
59 LevelClass() : helpers::Class() {}
60
61 virtual LogString getName() const
62 {
63 return LOG4CXX_STR("Level");
64 }
65
66 virtual LevelPtr toLevel(const LogString& sArg) const
67 {
68 return Level::toLevelLS(sArg);
69 }
70
71 virtual LevelPtr toLevel(int val) const
72 {
73 return Level::toLevel(val);
74 }
75 };
76
81
85 Level(int level,
86 const LogString& name,
87 int syslogEquivalent);
88
94 static LevelPtr toLevel(const std::string& sArg);
103 static LevelPtr toLevel(const std::string& sArg,
104 const LevelPtr& defaultLevel);
109 void toString(std::string& name) const;
110
111#if LOG4CXX_WCHAR_T_API
117 static LevelPtr toLevel(const std::wstring& sArg);
126 static LevelPtr toLevel(const std::wstring& sArg,
127 const LevelPtr& defaultLevel);
132 void toString(std::wstring& name) const;
133#endif
134#if LOG4CXX_UNICHAR_API
140 static LevelPtr toLevel(const std::basic_string<UniChar>& sArg);
149 static LevelPtr toLevel(const std::basic_string<UniChar>& sArg,
150 const LevelPtr& defaultLevel);
155 void toString(std::basic_string<UniChar>& name) const;
156#endif
157#if LOG4CXX_CFSTRING_API
163 static LevelPtr toLevel(const CFStringRef& sArg);
172 static LevelPtr toLevel(const CFStringRef& sArg,
173 const LevelPtr& defaultLevel);
178 void toString(CFStringRef& name) const;
179#endif
185 static LevelPtr toLevelLS(const LogString& sArg);
194 static LevelPtr toLevelLS(const LogString& sArg,
195 const LevelPtr& defaultLevel);
201
206 static LevelPtr toLevel(int val);
207
212 static LevelPtr toLevel(int val, const LevelPtr& defaultLevel);
213
214 enum
215 {
216 OFF_INT = INT_MAX,
217 FATAL_INT = 50000,
218 ERROR_INT = 40000,
219 WARN_INT = 30000,
220 INFO_INT = 20000,
221 DEBUG_INT = 10000,
222 TRACE_INT = 5000,
223 ALL_INT = INT_MIN
224 };
225
226
227 static void initializeLevels();
228 static LevelPtr getAll();
235 static LevelPtr getOff();
236
237
241 virtual bool equals(const LevelPtr& level) const;
242
243 inline bool operator==(const Level& level1) const
244 {
245 return (this->level == level1.level);
246 }
247
248 inline bool operator!=(const Level& level1) const
249 {
250 return (this->level != level1.level);
251 }
252
256 inline int getSyslogEquivalent() const
257 {
258 return syslogEquivalent;
259 }
260
261
271 virtual bool isGreaterOrEqual(const LevelPtr& level) const;
272
273
277 inline int toInt() const
278 {
279 return level;
280 }
281
282 private:
283 static volatile bool initialized;
284 static std::mutex initMutex;
285 static LevelPtr allLevel;
286 static LevelPtr fatalLevel;
287 static LevelPtr errorLevel;
288 static LevelPtr warnLevel;
289 static LevelPtr infoLevel;
290 static LevelPtr debugLevel;
291 static LevelPtr traceLevel;
292 static LevelPtr offLevel;
293
294 int level;
295 LogString name;
296 int syslogEquivalent;
297 Level(const Level&);
298 Level& operator=(const Level&);
299};
300
301}
302
303#define DECLARE_LOG4CXX_LEVEL(level)\
304 public:\
305 class Class##level : public Level::LevelClass\
306 {\
307 public:\
308 Class##level() : Level::LevelClass() {}\
309 virtual LogString getName() const { return LOG4CXX_STR(#level); } \
310 virtual LevelPtr toLevel(const LogString& sArg) const\
311 { return level::toLevelLS(sArg); }\
312 virtual LevelPtr toLevel(int val) const\
313 { return level::toLevel(val); }\
314 };\
315 DECLARE_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(level, Class##level)
316
317#define IMPLEMENT_LOG4CXX_LEVEL(level) \
318 IMPLEMENT_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(level, Class##level)
319
320#if defined(_MSC_VER)
321 #pragma warning (pop)
322#endif
323
324#endif //_LOG4CXX_LEVEL_H
Definition: level.h:57
virtual LevelPtr toLevel(int val) const
Definition: level.h:71
virtual LevelPtr toLevel(const LogString &sArg) const
Definition: level.h:66
virtual LogString getName() const
Definition: level.h:61
LevelClass()
Definition: level.h:59
Defines the minimum set of levels recognized by the system, that is OFF, FATAL, ERROR,...
Definition: level.h:54
static LevelPtr getError()
static LevelPtr toLevel(const std::wstring &sArg, const LevelPtr &defaultLevel)
Convert the string passed as argument to a level.
static LevelPtr getAll()
static LevelPtr toLevel(const CFStringRef &sArg)
Convert the string passed as argument to a level.
static LevelPtr toLevel(int val)
Convert an integer passed as argument to a level.
static LevelPtr getWarn()
static LevelPtr getOff()
static LevelPtr getDebug()
LogString toString() const
Returns the string representation of this level.
static LevelPtr toLevel(const std::string &sArg)
Convert the string passed as argument to a level.
virtual bool equals(const LevelPtr &level) const
Two levels are equal if their level fields are equal.
bool operator!=(const Level &level1) const
Definition: level.h:248
static LevelPtr getTrace()
static LevelPtr toLevel(int val, const LevelPtr &defaultLevel)
Convert an integer passed as argument to a level.
virtual bool isGreaterOrEqual(const LevelPtr &level) const
Returns true if this level has a higher or equal level than the level passed as argument,...
static LevelPtr toLevel(const std::basic_string< UniChar > &sArg, const LevelPtr &defaultLevel)
Convert the string passed as argument to a level.
void toString(std::wstring &name) const
Get the name of the level.
static LevelPtr toLevelLS(const LogString &sArg)
Convert the string passed as argument to a level.
static LevelPtr getInfo()
void toString(CFStringRef &name) const
Get the name of the level.
static void initializeLevels()
int getSyslogEquivalent() const
Return the syslog equivalent of this level as an integer.
Definition: level.h:256
bool operator==(const Level &level1) const
Definition: level.h:243
void toString(std::basic_string< UniChar > &name) const
Get the name of the level.
int toInt() const
Returns the integer representation of this level.
Definition: level.h:277
static LevelPtr toLevel(const std::wstring &sArg)
Convert the string passed as argument to a level.
static LevelPtr getFatal()
static LevelPtr toLevel(const CFStringRef &sArg, const LevelPtr &defaultLevel)
Convert the string passed as argument to a level.
static LevelPtr toLevelLS(const LogString &sArg, const LevelPtr &defaultLevel)
Convert the string passed as argument to a level.
static LevelPtr toLevel(const std::basic_string< UniChar > &sArg)
Convert the string passed as argument to a level.
Definition: class.h:38
base class for java-like objects.
Definition: object.h:102
const struct __CFString * CFStringRef
Definition: logstring.h:36
Definition: messagehandler.h:23
std::basic_string< logchar > LogString
Definition: logstring.h:66
std::shared_ptr< Level > LevelPtr
Definition: optionconverter.h:28
#define DECLARE_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(object, class)
Definition: object.h:56
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:153
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:147
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:141