~ubuntu-branches/ubuntu/wily/cxxtools/wily-proposed

« back to all changes in this revision

Viewing changes to include/cxxtools/log/log4cplus.h

  • Committer: Package Import Robot
  • Author(s): Kari Pahula
  • Date: 2012-04-28 10:30:29 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120428103029-qc8v0sb4yb8h1542
Tags: 2.1-1
* New upstream release (SONAME 8)
  - Removed patch gcc4.7_ftbfs_fix since upstream source is GCC 4.7 safe.
  - Patches iconvstream_size_t_fix, configure.in_fixes and
    arm_gcc4.6_ftbfs_fix removed since they have been implemented in
    upstream source.
* Standards-Version 3.9.3.
* Use dh-autoreconf.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2003, Tommi Maekitalo
3
 
 * 
4
 
 * This library is free software; you can redistribute it and/or
5
 
 * modify it under the terms of the GNU Lesser General Public
6
 
 * License as published by the Free Software Foundation; either
7
 
 * version 2.1 of the License, or (at your option) any later version.
8
 
 * 
9
 
 * As a special exception, you may use this file as part of a free
10
 
 * software library without restriction. Specifically, if other files
11
 
 * instantiate templates or use macros or inline functions from this
12
 
 * file, or you compile this file and link it with other files to
13
 
 * produce an executable, this file does not by itself cause the
14
 
 * resulting executable to be covered by the GNU General Public
15
 
 * License. This exception does not however invalidate any other
16
 
 * reasons why the executable file might be covered by the GNU Library
17
 
 * General Public License.
18
 
 * 
19
 
 * This library is distributed in the hope that it will be useful,
20
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22
 
 * Lesser General Public License for more details.
23
 
 * 
24
 
 * You should have received a copy of the GNU Lesser General Public
25
 
 * License along with this library; if not, write to the Free Software
26
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
27
 
 */
28
 
 
29
 
#ifndef CXXTOOLS_LOG_LOG4CPLUS_H
30
 
#define CXXTOOLS_LOG_LOG4CPLUS_H
31
 
 
32
 
#include <log4cplus/logger.h>
33
 
 
34
 
#define log_fatal_enabled()  getLogger().isEnabledFor(::log4cplus::FATAL_LOG_LEVEL)
35
 
#define log_error_enabled()  getLogger().isEnabledFor(::log4cplus::ERROR_LOG_LEVEL)
36
 
#define log_warn_enabled()   getLogger().isEnabledFor(::log4cplus::WARN_LOG_LEVEL)
37
 
#define log_info_enabled()   getLogger().isEnabledFor(::log4cplus::INFO_LOG_LEVEL)
38
 
#define log_debug_enabled()  getLogger().isEnabledFor(::log4cplus::DEBUG_LOG_LEVEL)
39
 
#define log_trace_enabled()  getLogger().isEnabledFor(::log4cplus::TRACE_LOG_LEVEL)
40
 
 
41
 
#define log_xxxx(level, expr)  \
42
 
    do { \
43
 
      if (getLogger().getRoot().getAllAppenders().size() > 0) \
44
 
      { \
45
 
        LOG4CPLUS_ ## level (getLogger(), expr) \
46
 
      } \
47
 
    } while(false)
48
 
 
49
 
#define log_fatal(expr)  log_xxxx(FATAL, expr)
50
 
#define log_error(expr)  log_xxxx(ERROR, expr)
51
 
#define log_warn(expr)   log_xxxx(WARN, expr)
52
 
#define log_info(expr)   log_xxxx(INFO, expr)
53
 
#define log_debug(expr)  log_xxxx(DEBUG, expr)
54
 
#define log_trace(expr) \
55
 
  ::cxxtools::log4cplus_tracer tracer ## __LINE__ (getLogger());  \
56
 
  if (log_trace_enabled()) \
57
 
  { \
58
 
    tracer ## __LINE__ .logentry() << expr;  \
59
 
    tracer ## __LINE__ .enter();  \
60
 
  }
61
 
 
62
 
#define log_define(category)   \
63
 
  static inline log4cplus::Logger& getLogger()   \
64
 
  {  \
65
 
    static log4cplus::Logger tntlogger = log4cplus::Logger::getInstance(category);  \
66
 
    return tntlogger;  \
67
 
  }
68
 
 
69
 
namespace cxxtools
70
 
{
71
 
  class log4cplus_tracer
72
 
  {
73
 
      log4cplus::Logger& l;
74
 
      std::ostringstream* msg;
75
 
 
76
 
      log4cplus::Logger& getLogger()  { return l; }
77
 
 
78
 
    public:
79
 
      log4cplus_tracer(::log4cplus::Logger& l_)
80
 
        : l(l_), msg(0)
81
 
      { }
82
 
      ~log4cplus_tracer()
83
 
      {
84
 
        if (msg && log_trace_enabled())
85
 
          LOG4CPLUS_TRACE(l, "EXIT " << msg->str());
86
 
      }
87
 
 
88
 
      std::ostream& logentry()
89
 
      {
90
 
        if (!msg)
91
 
          msg = new std::ostringstream();
92
 
        return *msg;
93
 
      }
94
 
 
95
 
      void enter()
96
 
      {
97
 
        if (msg && log_trace_enabled())
98
 
          LOG4CPLUS_TRACE(l, "ENTER " << msg->str());
99
 
      }
100
 
  };
101
 
}
102
 
 
103
 
#endif // CXXTOOLS_LOG_LOG4CPLUS_H