Nemiver  0.3
nmv-log-stream-utils.h
Go to the documentation of this file.
1 /* -*- Mode: C++; indent-tabs-mode:nil; c-basic-offset: 4-*- */
2 
3 /*Copyright (c) 2005-2006 Dodji Seketeli
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of this
6  * software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute,
9  * sublicense, and/or sell copies of the Software, and to permit
10  * persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies
14  * or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS",
17  * WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18  * INCLUDING BUT NOT LIMITED TO THE
19  * WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE
21  * AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23  * HOLDERS BE LIABLE FOR ANY CLAIM,
24  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25  * CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
27  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28  *
29  */
30 #ifndef __NMV_LOG_STREAM_UTILS_H__
31 #define __NMV_LOG_STREAM_UTILS_H__
32 
33 #include <cassert>
34 #include <cstdlib>
35 #include "nmv-log-stream.h"
36 #include "nmv-scope-logger.h"
37 
38 #ifndef __ASSERT_FUNCTION
39 #define __ASSERT_FUNCTION __PRETTY_FUNCTION__
40 #endif
41 
42 #ifndef HERE
43 #define HERE __ASSERT_FUNCTION << ":" <<__FILE__<< ":" << __LINE__ << ":"
44 #endif
45 
46 #ifndef PRETY_FUNCTION_NAME_
47 #define PRETTY_FUNCTION_NAME_ __ASSERT_FUNCTION
48 #endif
49 
50 #ifndef LOG_STREAM
51 #define LOG_STREAM nemiver::common::LogStream::default_log_stream ()
52 #endif
53 
54 #ifndef LOG_MARKER_INFO
55 #define LOG_MARKER_INFO "|I|"
56 #endif
57 
58 #ifndef LOG_MARKER_ERROR
59 #define LOG_MARKER_ERROR "|E|"
60 #endif
61 
62 #ifndef LOG_MARKER_EXCEPTION
63 #define LOG_MARKER_EXCEPTION "|X|"
64 #endif
65 
66 #ifndef LOG_LEVEL_NORMAL___
67 #define LOG_LEVEL_NORMAL___ nemiver::common::level_normal
68 #endif
69 
70 #ifndef LOG_LEVEL_VERBOSE___
71 #define LOG_LEVEL_VERBOSE___ nemiver::common::level_verbose
72 #endif
73 
74 #ifndef LOG
75 #define LOG(message) \
76 LOG_STREAM << LOG_LEVEL_NORMAL___ << LOG_MARKER_INFO << HERE << message << nemiver::common::endl
77 #endif
78 
79 #ifndef MESSAGE
80 #define MESSAGE(message) \
81 LOG_STREAM << LOG_LEVEL_NORMAL___ << LOG_MARKER_INFO << message << nemiver::common::endl
82 #endif
83 
84 #ifndef LOG_D
85 #define LOG_D(message, domain) \
86  do { \
87  LOG_STREAM.push_domain (domain); \
88  LOG (message) ; \
89  LOG_STREAM.pop_domain (); \
90  } while (false)
91 #endif
92 
93 #ifndef LOG_DD
94 #define LOG_DD(message) LOG_D(message, NMV_DEFAULT_DOMAIN)
95 #endif
96 
97 #ifndef LOG_ERROR
98 #define LOG_ERROR(message) \
99 LOG_STREAM << LOG_LEVEL_NORMAL___ << LOG_MARKER_ERROR << HERE << message << nemiver::common::endl
100 #endif
101 
102 #ifndef LOG_EXCEPTION
103 #define LOG_EXCEPTION(message) \
104 LOG_STREAM << LOG_LEVEL_NORMAL___ << LOG_MARKER_EXCEPTION << HERE << message << nemiver::common::endl
105 #endif
106 
107 #ifndef LOG_ERROR_D
108 #define LOG_ERROR_D(message, domain) \
109  do { \
110  LOG_STREAM.push_domain (domain); \
111  LOG_ERROR (message) ; \
112  LOG_STREAM.pop_domain() ; \
113  } while (false)
114 #endif
115 
116 #ifndef LOG_ERROR_DD
117 #define LOG_ERROR_DD(message) LOG_ERROR_D (message, NMV_DEFAULT_DOMAIN)
118 #endif
119 
120 #ifndef LOG_VERBOSE
121 #define LOG_VERBOSE(message) \
122 LOG_STREAM << LOG_LEVEL_VERBOSE___ << LOG_MARKER_INFO << HERE << message << nemiver::common::endl
123 #endif
124 
125 #ifndef LOG_VERBOSE_D
126 #define LOG_VERBOSE_D(message) \
127  do { \
128  LOG_STREAM.push_domain (domain); \
129  LOG_VERBOSE(message) ; \
130  LOG_STREAM.pop_domain(); \
131  } while (false)
132 #endif
133 
134 #ifndef LOG_SCOPE_VERBOSE
135 #define LOG_SCOPE_VERBOSE(scopename) \
136 nemiver::common::ScopeLogger scope_logger (scopename, nemiver::common::LogStream::LOG_LEVEL_VERBOSE);
137 #endif
138 
139 #ifndef LOG_SCOPE
140 #define LOG_SCOPE(scopename) \
141 nemiver::common::ScopeLogger scope_logger (scopename, nemiver::common::LogStream::LOG_LEVEL_NORMAL);
142 #endif
143 
144 #ifndef LOG_SCOPE_D
145 #define LOG_SCOPE_D(scopename, domain) \
146 nemiver::common::ScopeLogger scope_logger \
147  (scopename, nemiver::common::LogStream::LOG_LEVEL_VERBOSE, domain);
148 #endif
149 
150 #ifndef LOG_SCOPE_NORMAL
151 #define LOG_SCOPE_NORMAL(scopename) \
152 nemiver::common::ScopeLogger scope_logger (scopename, nemiver::common::LogStream::LOG_LEVEL_NORMAL);
153 #endif
154 
155 #ifndef LOG_SCOPE_NORMAL_D
156 #define LOG_SCOPE_NORMAL_D(scopename, domain) \
157 nemiver::common::ScopeLogger scope_logger \
158  (scopename, nemiver::common::LogStream::LOG_LEVEL_NORMAL, domain);
159 #endif
160 
161 #ifndef LOG_FUNCTION_SCOPE
162 #define LOG_FUNCTION_SCOPE LOG_SCOPE(PRETTY_FUNCTION_NAME_)
163 #endif
164 
165 #ifndef LOG_FUNCTION_SCOPE_D
166 #define LOG_FUNCTION_SCOPE_D(domain) LOG_SCOPE_D(PRETTY_FUNCTION_NAME_, domain)
167 #endif
168 
169 #ifndef LOG_FUNCTION_SCOPE_NORMAL
170 #define LOG_FUNCTION_SCOPE_NORMAL LOG_SCOPE_NORMAL(PRETTY_FUNCTION_NAME_)
171 #endif
172 
173 #ifndef LOG_FUNCTION_SCOPE_VERBOSE
174 #define LOG_FUNCTION_SCOPE_VERBOSE LOG_SCOPE_VERBOSE(PRETTY_FUNCTION_NAME_)
175 #endif
176 
177 #ifndef LOG_FUNCTION_SCOPE_NORMAL_D
178 #define LOG_FUNCTION_SCOPE_NORMAL_D(domain) \
179  LOG_SCOPE_NORMAL_D(PRETTY_FUNCTION_NAME_, domain)
180 #endif
181 
182 #ifndef LOG_FUNCTION_SCOPE_NORMAL_DD
183 #define LOG_FUNCTION_SCOPE_NORMAL_DD LOG_FUNCTION_SCOPE_NORMAL_D(NMV_DEFAULT_DOMAIN)
184 #endif
185 
186 #ifndef LOG_REF_COUNT
187 #define LOG_REF_COUNT(a_object_ptr, a_name) \
188 LOG_D ("object '" \
189  << a_name \
190  << "' refcount: " \
191  << (int) a_object_ptr->get_refcount (), \
192  "refcount-domain");
193 #endif //LOG_REF_COUNT
194 
195 #endif // NMV_LOG_STREAM_UTILS_H__
196 
nmv-scope-logger.h
nmv-log-stream.h