Apache Log4cxx  Version 2.0.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
26namespace LOG4CXX_NS
27{
36class Level;
37typedef std::shared_ptr<Level> LevelPtr;
38
47class LOG4CXX_EXPORT Level : public helpers::Object
48{
49 public:
50 class LOG4CXX_EXPORT LevelClass : public helpers::Class
51 {
52 public:
54
55 LogString getName() const override
56 {
57 return LOG4CXX_STR("Level");
58 }
59
60 virtual LevelPtr toLevel(const LogString& sArg) const
61 {
62 return Level::toLevelLS(sArg);
63 }
64
65 virtual LevelPtr toLevel(int val) const
66 {
67 return Level::toLevel(val);
68 }
69 };
70
75
79 Level(int level,
80 const LogString& name,
81 int syslogEquivalent);
82
88 static LevelPtr toLevel(const std::string& sArg);
97 static LevelPtr toLevel(const std::string& sArg,
98 const LevelPtr& defaultLevel);
103 void toString(std::string& name) const;
104
105#if LOG4CXX_WCHAR_T_API
111 static LevelPtr toLevel(const std::wstring& sArg);
120 static LevelPtr toLevel(const std::wstring& sArg,
121 const LevelPtr& defaultLevel);
126 void toString(std::wstring& name) const;
127#endif
128#if LOG4CXX_CFSTRING_API
134 static LevelPtr toLevel(const CFStringRef& sArg);
143 static LevelPtr toLevel(const CFStringRef& sArg,
144 const LevelPtr& defaultLevel);
149 void toString(CFStringRef& name) const;
150#endif
156 static LevelPtr toLevelLS(const LogString& sArg);
165 static LevelPtr toLevelLS(const LogString& sArg,
166 const LevelPtr& defaultLevel);
172
177 static LevelPtr toLevel(int val);
178
183 static LevelPtr toLevel(int val, const LevelPtr& defaultLevel);
184
185 enum
186 {
187 OFF_INT = INT_MAX,
188 FATAL_INT = 50000,
189 ERROR_INT = 40000,
190 WARN_INT = 30000,
191 INFO_INT = 20000,
192 DEBUG_INT = 10000,
193 TRACE_INT = 5000,
194 ALL_INT = INT_MIN
195 };
196
208 using DataPtr = std::shared_ptr<Data>;
209
210 static const DataPtr& getData();
211 static LevelPtr getAll();
218 static LevelPtr getOff();
219
220
224 virtual bool equals(const LevelPtr& level) const;
225
226 inline bool operator==(const Level& level1) const
227 {
228 return (this->level == level1.level);
229 }
230
231 inline bool operator!=(const Level& level1) const
232 {
233 return (this->level != level1.level);
234 }
235
239 inline int getSyslogEquivalent() const
240 {
241 return syslogEquivalent;
242 }
243
244
254 virtual bool isGreaterOrEqual(const LevelPtr& level) const;
255
256
260 inline int toInt() const
261 {
262 return level;
263 }
264
265 private:
266 LOG4CXX_DECLARE_PRIVATE_MEMBER(LogString, name)
267 int level;
268 int syslogEquivalent;
269 Level(const Level&);
270 Level& operator=(const Level&);
271};
272
273}
274
275#define DECLARE_LOG4CXX_LEVEL(level)\
276 public:\
277 class Class##level : public Level::LevelClass\
278 {\
279 public:\
280 LogString getName() const override { return LOG4CXX_STR(#level); } \
281 LevelPtr toLevel(const LogString& sArg) const override\
282 { return level::toLevelLS(sArg); }\
283 LevelPtr toLevel(int val) const override\
284 { return level::toLevel(val); }\
285 };\
286 DECLARE_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(level, Class##level)
287
288#define IMPLEMENT_LOG4CXX_LEVEL(level) \
289 IMPLEMENT_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(level, Class##level)
290
291#endif //_LOG4CXX_LEVEL_H
virtual LevelPtr toLevel(int val) const
Definition level.h:65
virtual LevelPtr toLevel(const LogString &sArg) const
Definition level.h:60
LogString getName() const override
Definition level.h:55
LevelClass()
Definition level.h:53
Defines the minimum set of levels recognized by the system, that is OFF, FATAL, ERROR,...
Definition level.h:48
static LevelPtr getError()
@ DEBUG_INT
Definition level.h:192
@ OFF_INT
Definition level.h:187
@ ALL_INT
Definition level.h:194
@ WARN_INT
Definition level.h:190
@ INFO_INT
Definition level.h:191
@ ERROR_INT
Definition level.h:189
@ FATAL_INT
Definition level.h:188
@ TRACE_INT
Definition level.h:193
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.
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:231
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,...
void toString(std::string &name) const
Get the name of the level in the current encoding.
void toString(std::wstring &name) const
Get the name of the level.
std::shared_ptr< Data > DataPtr
Definition level.h:208
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:239
bool operator==(const Level &level1) const
Definition level.h:226
int toInt() const
Returns the integer representation of this level.
Definition level.h:260
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.
Level(int level, const LogString &name, int syslogEquivalent)
Instantiate a Level object.
Definition class.h:32
base class for java-like objects.
Definition object.h:101
const struct __CFString * CFStringRef
Definition logstring.h:30
Definition propertysetter.h:27
std::basic_string< logchar > LogString
Definition logstring.h:51
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
Definition level.h:198
LevelPtr Debug
Definition level.h:204
LevelPtr Info
Definition level.h:203
LevelPtr All
Definition level.h:206
LevelPtr Trace
Definition level.h:205
LevelPtr Warn
Definition level.h:202
LevelPtr Off
Definition level.h:199
LevelPtr Fatal
Definition level.h:200
LevelPtr Error
Definition level.h:201