Apache Log4cxx  Version 1.3.0
Loading...
Searching...
No Matches
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
27namespace LOG4CXX_NS
28{
37class Level;
38typedef std::shared_ptr<Level> LevelPtr;
39
49{
50 public:
52 {
53 public:
54 LevelClass() : helpers::Class() {}
55
56 virtual LogString getName() const
57 {
58 return LOG4CXX_STR("Level");
59 }
60
61 virtual LevelPtr toLevel(const LogString& sArg) const
62 {
63 return Level::toLevelLS(sArg);
64 }
65
66 virtual LevelPtr toLevel(int val) const
67 {
68 return Level::toLevel(val);
69 }
70 };
71
76
80 Level(int level,
81 const LogString& name,
82 int syslogEquivalent);
83
89 static LevelPtr toLevel(const std::string& sArg);
98 static LevelPtr toLevel(const std::string& sArg,
99 const LevelPtr& defaultLevel);
104 void toString(std::string& name) const;
105
106#if LOG4CXX_WCHAR_T_API
112 static LevelPtr toLevel(const std::wstring& sArg);
121 static LevelPtr toLevel(const std::wstring& sArg,
122 const LevelPtr& defaultLevel);
127 void toString(std::wstring& name) const;
128#endif
129#if LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR
135 static LevelPtr toLevel(const std::basic_string<UniChar>& sArg);
144 static LevelPtr toLevel(const std::basic_string<UniChar>& sArg,
145 const LevelPtr& defaultLevel);
150 void toString(std::basic_string<UniChar>& name) const;
151#endif
152#if LOG4CXX_CFSTRING_API
158 static LevelPtr toLevel(const CFStringRef& sArg);
167 static LevelPtr toLevel(const CFStringRef& sArg,
168 const LevelPtr& defaultLevel);
173 void toString(CFStringRef& name) const;
174#endif
180 static LevelPtr toLevelLS(const LogString& sArg);
189 static LevelPtr toLevelLS(const LogString& sArg,
190 const LevelPtr& defaultLevel);
196
201 static LevelPtr toLevel(int val);
202
207 static LevelPtr toLevel(int val, const LevelPtr& defaultLevel);
208
209 enum
210 {
211 OFF_INT = INT_MAX,
212 FATAL_INT = 50000,
213 ERROR_INT = 40000,
214 WARN_INT = 30000,
215 INFO_INT = 20000,
216 DEBUG_INT = 10000,
217 TRACE_INT = 5000,
218 ALL_INT = INT_MIN
219 };
220
221 struct Data
222 {
231 };
232 using DataPtr = std::shared_ptr<Data>;
233
234 static const DataPtr& getData();
235 static LevelPtr getAll();
242 static LevelPtr getOff();
243
244
248 virtual bool equals(const LevelPtr& level) const;
249
250 inline bool operator==(const Level& level1) const
251 {
252 return (this->level == level1.level);
253 }
254
255 inline bool operator!=(const Level& level1) const
256 {
257 return (this->level != level1.level);
258 }
259
263 inline int getSyslogEquivalent() const
264 {
265 return syslogEquivalent;
266 }
267
268
278 virtual bool isGreaterOrEqual(const LevelPtr& level) const;
279
280
284 inline int toInt() const
285 {
286 return level;
287 }
288
289 private:
291 int level;
292 int syslogEquivalent;
293 Level(const Level&);
294 Level& operator=(const Level&);
295};
296
297}
298
299#define DECLARE_LOG4CXX_LEVEL(level)\
300 public:\
301 class Class##level : public Level::LevelClass\
302 {\
303 public:\
304 Class##level() : Level::LevelClass() {}\
305 virtual LogString getName() const { return LOG4CXX_STR(#level); } \
306 virtual LevelPtr toLevel(const LogString& sArg) const\
307 { return level::toLevelLS(sArg); }\
308 virtual LevelPtr toLevel(int val) const\
309 { return level::toLevel(val); }\
310 };\
311 DECLARE_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(level, Class##level)
312
313#define IMPLEMENT_LOG4CXX_LEVEL(level) \
314 IMPLEMENT_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(level, Class##level)
315
316#endif //_LOG4CXX_LEVEL_H
Definition: level.h:52
virtual LevelPtr toLevel(int val) const
Definition: level.h:66
virtual LevelPtr toLevel(const LogString &sArg) const
Definition: level.h:61
virtual LogString getName() const
Definition: level.h:56
LevelClass()
Definition: level.h:54
Defines the minimum set of levels recognized by the system, that is OFF, FATAL, ERROR,...
Definition: level.h:49
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 const DataPtr & getData()
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.
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:255
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.
std::shared_ptr< Data > DataPtr
Definition: level.h:232
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.
int getSyslogEquivalent() const
Return the syslog equivalent of this level as an integer.
Definition: level.h:263
bool operator==(const Level &level1) const
Definition: level.h:250
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:284
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:32
base class for java-like objects.
Definition: object.h:106
#define LOG4CXX_EXPORT
Definition: log4cxx.h:101
#define LOG4CXX_DECLARE_PRIVATE_MEMBER(T, V)
Definition: log4cxx.h:86
#define LOG4CXX_NS
Definition: log4cxx.h:104
const struct __CFString * CFStringRef
Definition: logstring.h:30
std::basic_string< logchar > LogString
Definition: logstring.h:60
std::shared_ptr< Level > LevelPtr
Definition: optionconverter.h:28
#define DECLARE_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(object, class)
Definition: object.h:60
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:158
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:152
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:146
Definition: level.h:222
LevelPtr Debug
Definition: level.h:228
LevelPtr Info
Definition: level.h:227
LevelPtr All
Definition: level.h:230
LevelPtr Trace
Definition: level.h:229
LevelPtr Warn
Definition: level.h:226
LevelPtr Off
Definition: level.h:223
LevelPtr Fatal
Definition: level.h:224
LevelPtr Error
Definition: level.h:225