OFFIS DCMTK  Version 3.6.0
logger.h
Go to the documentation of this file.
1 // Module: Log4CPLUS
2 // File: logger.h
3 // Created: 6/2001
4 // Author: Tad E. Smith
5 //
6 //
7 // Copyright 2001-2009 Tad E. Smith
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // Unless required by applicable law or agreed to in writing, software
16 // distributed under the License is distributed on an "AS IS" BASIS,
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 // See the License for the specific language governing permissions and
19 // limitations under the License.
20 
24 #ifndef _LOG4CPLUS_LOGGERHEADER_
25 #define _LOG4CPLUS_LOGGERHEADER_
26 
27 #include "dcmtk/oflog/config.h"
28 #include "dcmtk/oflog/loglevel.h"
29 #include "dcmtk/oflog/tstring.h"
30 #include "dcmtk/oflog/streams.h"
33 
34 //#include <vector>
35 
36 
37 namespace log4cplus
38 {
39  // Forward declarations
40 
41  class Appender;
42  class Hierarchy;
43  class HierarchyLocker;
44  class DefaultLoggerFactory;
45 
46  namespace spi
47  {
48 
49  class LoggerImpl;
50 
51  }
52 
53 
56  typedef OFList<Logger> LoggerList;
57  typedef OFListIterator(Logger) LoggerListIterator;
58 
59 
68  class LOG4CPLUS_EXPORT Logger
69  : public log4cplus::spi::AppenderAttachable
70  {
71  public:
72  // Static Methods
79  static bool exists(const log4cplus::tstring& name);
80 
81  /*
82  * Returns all the currently defined loggers in the default
83  * hierarchy.
84  *
85  * The root logger is <em>not</em> included in the returned
86  * list.
87  */
88  static LoggerList getCurrentLoggers();
89 
93  static Hierarchy& getDefaultHierarchy();
94 
106  static Logger getInstance(const log4cplus::tstring& name);
107 
120  static Logger getInstance(const log4cplus::tstring& name, spi::LoggerFactory& factory);
121 
132  static Logger getRoot();
133 
148  static void shutdown();
149 
150  // Non-Static Methods
159  void assertion(bool assertionVal, const log4cplus::tstring& msg) const;
160 
165  void closeNestedAppenders() const;
166 
173  bool isEnabledFor(LogLevel ll) const;
174 
178  void log(LogLevel ll, const log4cplus::tstring& message,
179  const char* file=NULL, int line=-1,
180  const char* function=NULL) const;
181 
186  void forcedLog(LogLevel ll, const log4cplus::tstring& message,
187  const char* file=NULL, int line=-1,
188  const char* function=NULL) const;
189 
201  void callAppenders(const spi::InternalLoggingEvent& event) const;
202 
211  LogLevel getChainedLogLevel() const;
212 
218  LogLevel getLogLevel() const;
219 
223  void setLogLevel(LogLevel ll);
224 
229  Hierarchy& getHierarchy() const;
230 
234  log4cplus::tstring getName() const;
235 
239  bool getAdditivity() const;
240 
244  void setAdditivity(bool additive);
245 
246  // AppenderAttachable Methods
247  virtual void addAppender(SharedAppenderPtr newAppender);
248 
249  virtual SharedAppenderPtrList getAllAppenders();
250 
251  virtual SharedAppenderPtr getAppender(const log4cplus::tstring& name);
252 
253  virtual void removeAllAppenders();
254 
255  virtual void removeAppender(SharedAppenderPtr appender);
256 
257  virtual void removeAppender(const log4cplus::tstring& name);
258 
259  Logger ();
260  Logger(const Logger& rhs);
261  Logger& operator=(const Logger& rhs);
262  virtual ~Logger();
263 
264  void swap (Logger &);
265 
270  Logger getParent() const;
271 
272  protected:
273  // Data
276 
277  private:
278  // Ctors
288  Logger(spi::LoggerImpl * ptr);
289 
290  // Friends
291  friend class log4cplus::spi::LoggerImpl;
292  friend class log4cplus::Hierarchy;
293  friend class log4cplus::HierarchyLocker;
294  friend class log4cplus::DefaultLoggerFactory;
295  };
296 
297 
302  class LOG4CPLUS_EXPORT DefaultLoggerFactory : public spi::LoggerFactory {
303  public:
304  Logger makeNewLoggerInstance(const log4cplus::tstring& name, Hierarchy& h);
305  };
306 
307 
308 
320  {
321  public:
322  TraceLogger(const Logger& l, const log4cplus::tstring& _msg,
323  const char* _file=NULL, int _line=-1)
324  : logger(l), msg(_msg), file(_file), line(_line)
325  { if(logger.isEnabledFor(TRACE_LOG_LEVEL))
326  logger.forcedLog(TRACE_LOG_LEVEL, LOG4CPLUS_TEXT("ENTER: ") + msg, file, line);
327  }
328 
329  ~TraceLogger()
330  { if(logger.isEnabledFor(TRACE_LOG_LEVEL))
331  logger.forcedLog(TRACE_LOG_LEVEL, LOG4CPLUS_TEXT("EXIT: ") + msg, file, line);
332  }
333 
334  private:
335  TraceLogger(const TraceLogger&);
336  TraceLogger& operator=(const TraceLogger&);
337  Logger logger;
338  log4cplus::tstring msg;
339  const char* file;
340  int line;
341  };
342 
343 } // end namespace log4cplus
344 
345 
346 #include "dcmtk/oflog/logmacro.h"
347 
348 
349 #endif // _LOG4CPLUS_LOGGERHEADER_
350 


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2