| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef EASYLOGGINGPP_H |
| 18 |
#define EASYLOGGINGPP_H |
| 19 |
#include "ea_config.h" |
| 20 |
|
| 21 |
#if __cplusplus >= 201103L |
| 22 |
# define ELPP_CXX11 1 |
| 23 |
#endif |
| 24 |
#if (defined(__GNUC__)) |
| 25 |
# define ELPP_COMPILER_GCC 1 |
| 26 |
#else |
| 27 |
# define ELPP_COMPILER_GCC 0 |
| 28 |
#endif |
| 29 |
#if ELPP_COMPILER_GCC |
| 30 |
# define ELPP_GCC_VERSION (__GNUC__ * 10000 \ |
| 31 |
+ __GNUC_MINOR__ * 100 \ |
| 32 |
+ __GNUC_PATCHLEVEL__) |
| 33 |
# if defined(__GXX_EXPERIMENTAL_CXX0X__) |
| 34 |
# define ELPP_CXX0X 1 |
| 35 |
# endif |
| 36 |
#endif |
| 37 |
|
| 38 |
#if defined(_MSC_VER) |
| 39 |
# define ELPP_COMPILER_MSVC 1 |
| 40 |
#else |
| 41 |
# define ELPP_COMPILER_MSVC 0 |
| 42 |
#endif |
| 43 |
#define ELPP_CRT_DBG_WARNINGS ELPP_COMPILER_MSVC |
| 44 |
#if ELPP_COMPILER_MSVC |
| 45 |
# if (_MSC_VER == 1600) |
| 46 |
# define ELPP_CXX0X 1 |
| 47 |
# elif(_MSC_VER >= 1700) |
| 48 |
# define ELPP_CXX11 1 |
| 49 |
# endif |
| 50 |
#endif |
| 51 |
|
| 52 |
#if (defined(__clang__) && (__clang__ == 1)) |
| 53 |
# define ELPP_COMPILER_CLANG 1 |
| 54 |
#else |
| 55 |
# define ELPP_COMPILER_CLANG 0 |
| 56 |
#endif |
| 57 |
#if ELPP_COMPILER_CLANG |
| 58 |
# if __has_include(<thread>) |
| 59 |
# include <cstddef> |
| 60 |
# if !defined(__GLIBCXX__) || __GLIBCXX__ >= 20150426 |
| 61 |
# define ELPP_CLANG_SUPPORTS_THREAD |
| 62 |
# endif |
| 63 |
# endif |
| 64 |
#endif |
| 65 |
#if (defined(__MINGW32__) || defined(__MINGW64__)) |
| 66 |
# define ELPP_MINGW 1 |
| 67 |
#else |
| 68 |
# define ELPP_MINGW 0 |
| 69 |
#endif |
| 70 |
#if (defined(__CYGWIN__) && (__CYGWIN__ == 1)) |
| 71 |
# define ELPP_CYGWIN 1 |
| 72 |
#else |
| 73 |
# define ELPP_CYGWIN 0 |
| 74 |
#endif |
| 75 |
#if (defined(__INTEL_COMPILER)) |
| 76 |
# define ELPP_COMPILER_INTEL 1 |
| 77 |
#else |
| 78 |
# define ELPP_COMPILER_INTEL 0 |
| 79 |
#endif |
| 80 |
|
| 81 |
|
| 82 |
#if (defined(_WIN32) || defined(_WIN64)) |
| 83 |
# define ELPP_OS_WINDOWS 1 |
| 84 |
#else |
| 85 |
# define ELPP_OS_WINDOWS 0 |
| 86 |
#endif |
| 87 |
|
| 88 |
#if (defined(__linux) || defined(__linux__)) |
| 89 |
# define ELPP_OS_LINUX 1 |
| 90 |
#else |
| 91 |
# define ELPP_OS_LINUX 0 |
| 92 |
#endif |
| 93 |
#if (defined(__APPLE__)) |
| 94 |
# define ELPP_OS_MAC 1 |
| 95 |
#else |
| 96 |
# define ELPP_OS_MAC 0 |
| 97 |
#endif |
| 98 |
#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) |
| 99 |
# define ELPP_OS_FREEBSD 1 |
| 100 |
#else |
| 101 |
# define ELPP_OS_FREEBSD 0 |
| 102 |
#endif |
| 103 |
#if (defined(__OpenBSD__)) |
| 104 |
# define ELPP_OS_OPENBSD 1 |
| 105 |
#else |
| 106 |
# define ELPP_OS_OPENBSD 0 |
| 107 |
#endif |
| 108 |
#if (defined(__NetBSD__)) |
| 109 |
# define ELPP_OS_NETBSD 1 |
| 110 |
#else |
| 111 |
# define ELPP_OS_NETBSD 0 |
| 112 |
#endif |
| 113 |
#if (defined(__sun)) |
| 114 |
# define ELPP_OS_SOLARIS 1 |
| 115 |
#else |
| 116 |
# define ELPP_OS_SOLARIS 0 |
| 117 |
#endif |
| 118 |
#if (defined(_AIX)) |
| 119 |
# define ELPP_OS_AIX 1 |
| 120 |
#else |
| 121 |
# define ELPP_OS_AIX 0 |
| 122 |
#endif |
| 123 |
#if (defined(__NetBSD__)) |
| 124 |
# define ELPP_OS_NETBSD 1 |
| 125 |
#else |
| 126 |
# define ELPP_OS_NETBSD 0 |
| 127 |
#endif |
| 128 |
#if defined(__EMSCRIPTEN__) |
| 129 |
# define ELPP_OS_EMSCRIPTEN 1 |
| 130 |
#else |
| 131 |
# define ELPP_OS_EMSCRIPTEN 0 |
| 132 |
#endif |
| 133 |
#if (defined(__DragonFly__)) |
| 134 |
# define ELPP_OS_DRAGONFLY 1 |
| 135 |
#else |
| 136 |
# define ELPP_OS_DRAGONFLY 0 |
| 137 |
#endif |
| 138 |
|
| 139 |
#if ((ELPP_OS_LINUX || ELPP_OS_MAC || ELPP_OS_FREEBSD || ELPP_OS_NETBSD || ELPP_OS_SOLARIS || ELPP_OS_AIX || ELPP_OS_EMSCRIPTEN || ELPP_OS_DRAGONFLY || ELPP_OS_OPENBSD) && (!ELPP_OS_WINDOWS)) |
| 140 |
# define ELPP_OS_UNIX 1 |
| 141 |
#else |
| 142 |
# define ELPP_OS_UNIX 0 |
| 143 |
#endif |
| 144 |
#if (defined(__ANDROID__)) |
| 145 |
# define ELPP_OS_ANDROID 1 |
| 146 |
#else |
| 147 |
# define ELPP_OS_ANDROID 0 |
| 148 |
#endif |
| 149 |
|
| 150 |
#if !ELPP_OS_UNIX && !ELPP_OS_WINDOWS && ELPP_CYGWIN |
| 151 |
# undef ELPP_OS_UNIX |
| 152 |
# undef ELPP_OS_LINUX |
| 153 |
# define ELPP_OS_UNIX 1 |
| 154 |
# define ELPP_OS_LINUX 1 |
| 155 |
#endif |
| 156 |
#if !defined(ELPP_INTERNAL_DEBUGGING_OUT_INFO) |
| 157 |
# define ELPP_INTERNAL_DEBUGGING_OUT_INFO std::cout |
| 158 |
#endif |
| 159 |
#if !defined(ELPP_INTERNAL_DEBUGGING_OUT_ERROR) |
| 160 |
# define ELPP_INTERNAL_DEBUGGING_OUT_ERROR std::cerr |
| 161 |
#endif |
| 162 |
#if !defined(ELPP_INTERNAL_DEBUGGING_ENDL) |
| 163 |
# define ELPP_INTERNAL_DEBUGGING_ENDL std::endl |
| 164 |
#endif |
| 165 |
#if !defined(ELPP_INTERNAL_DEBUGGING_MSG) |
| 166 |
# define ELPP_INTERNAL_DEBUGGING_MSG(msg) msg |
| 167 |
#endif |
| 168 |
|
| 169 |
#if !defined(ELPP_DISABLE_ASSERT) |
| 170 |
# if (defined(ELPP_DEBUG_ASSERT_FAILURE)) |
| 171 |
# define ELPP_ASSERT(expr, msg) if (!(expr)) { \ |
| 172 |
std::stringstream internalInfoStream; internalInfoStream << msg; \ |
| 173 |
ELPP_INTERNAL_DEBUGGING_OUT_ERROR \ |
| 174 |
<< "EASYLOGGING++ ASSERTION FAILED (LINE: " << __LINE__ << ") [" #expr << "] WITH MESSAGE \"" \ |
| 175 |
<< ELPP_INTERNAL_DEBUGGING_MSG(internalInfoStream.str()) << "\"" << ELPP_INTERNAL_DEBUGGING_ENDL; base::utils::abort(1, \ |
| 176 |
"ELPP Assertion failure, please define ELPP_DEBUG_ASSERT_FAILURE"); } |
| 177 |
# else |
| 178 |
# define ELPP_ASSERT(expr, msg) if (!(expr)) { \ |
| 179 |
std::stringstream internalInfoStream; internalInfoStream << msg; \ |
| 180 |
ELPP_INTERNAL_DEBUGGING_OUT_ERROR\ |
| 181 |
<< "ASSERTION FAILURE FROM EASYLOGGING++ (LINE: " \ |
| 182 |
<< __LINE__ << ") [" #expr << "] WITH MESSAGE \"" << ELPP_INTERNAL_DEBUGGING_MSG(internalInfoStream.str()) << "\"" \ |
| 183 |
<< ELPP_INTERNAL_DEBUGGING_ENDL; } |
| 184 |
# endif |
| 185 |
#else |
| 186 |
# define ELPP_ASSERT(x, y) |
| 187 |
#endif |
| 188 |
#if ELPP_COMPILER_MSVC |
| 189 |
# define ELPP_INTERNAL_DEBUGGING_WRITE_PERROR \ |
| 190 |
{ char buff[256]; strerror_s(buff, 256, errno); \ |
| 191 |
ELPP_INTERNAL_DEBUGGING_OUT_ERROR << ": " << buff << " [" << errno << "]";} (void)0 |
| 192 |
#else |
| 193 |
# define ELPP_INTERNAL_DEBUGGING_WRITE_PERROR \ |
| 194 |
ELPP_INTERNAL_DEBUGGING_OUT_ERROR << ": " << strerror(errno) << " [" << errno << "]"; (void)0 |
| 195 |
#endif |
| 196 |
#if defined(ELPP_DEBUG_ERRORS) |
| 197 |
# if !defined(ELPP_INTERNAL_ERROR) |
| 198 |
# define ELPP_INTERNAL_ERROR(msg, pe) { \ |
| 199 |
std::stringstream internalInfoStream; internalInfoStream << "<ERROR> " << msg; \ |
| 200 |
ELPP_INTERNAL_DEBUGGING_OUT_ERROR \ |
| 201 |
<< "ERROR FROM EASYLOGGING++ (LINE: " << __LINE__ << ") " \ |
| 202 |
<< ELPP_INTERNAL_DEBUGGING_MSG(internalInfoStream.str()) << ELPP_INTERNAL_DEBUGGING_ENDL; \ |
| 203 |
if (pe) { ELPP_INTERNAL_DEBUGGING_OUT_ERROR << " "; ELPP_INTERNAL_DEBUGGING_WRITE_PERROR; }} (void)0 |
| 204 |
# endif |
| 205 |
#else |
| 206 |
# undef ELPP_INTERNAL_INFO |
| 207 |
# define ELPP_INTERNAL_ERROR(msg, pe) |
| 208 |
#endif |
| 209 |
#if (defined(ELPP_DEBUG_INFO)) |
| 210 |
# if !(defined(ELPP_INTERNAL_INFO_LEVEL)) |
| 211 |
# define ELPP_INTERNAL_INFO_LEVEL 9 |
| 212 |
# endif |
| 213 |
# if !defined(ELPP_INTERNAL_INFO) |
| 214 |
# define ELPP_INTERNAL_INFO(lvl, msg) { if (lvl <= ELPP_INTERNAL_INFO_LEVEL) { \ |
| 215 |
std::stringstream internalInfoStream; internalInfoStream << "<INFO> " << msg; \ |
| 216 |
ELPP_INTERNAL_DEBUGGING_OUT_INFO << ELPP_INTERNAL_DEBUGGING_MSG(internalInfoStream.str()) \ |
| 217 |
<< ELPP_INTERNAL_DEBUGGING_ENDL; }} |
| 218 |
# endif |
| 219 |
#else |
| 220 |
# undef ELPP_INTERNAL_INFO |
| 221 |
# define ELPP_INTERNAL_INFO(lvl, msg) |
| 222 |
#endif |
| 223 |
#if (defined(ELPP_FEATURE_ALL)) || (defined(ELPP_FEATURE_CRASH_LOG)) |
| 224 |
# if (ELPP_COMPILER_GCC && !ELPP_MINGW && !ELPP_OS_OPENBSD && !ELPP_OS_NETBSD && !ELPP_OS_ANDROID && !ELPP_OS_EMSCRIPTEN) |
| 225 |
# define ELPP_STACKTRACE 1 |
| 226 |
# else |
| 227 |
# define ELPP_STACKTRACE 0 |
| 228 |
# ifdef EASYLOGGING_CC |
| 229 |
# if ELPP_COMPILER_MSVC |
| 230 |
# pragma message("Stack trace not available for this compiler") |
| 231 |
# else |
| 232 |
# warning "Stack trace not available for this compiler"; |
| 233 |
# endif |
| 234 |
# endif |
| 235 |
# endif |
| 236 |
#else |
| 237 |
# define ELPP_STACKTRACE 0 |
| 238 |
#endif |
| 239 |
|
| 240 |
#define ELPP_UNUSED(x) (void)x |
| 241 |
#if ELPP_OS_UNIX |
| 242 |
|
| 243 |
# define ELPP_LOG_PERMS S_IRUSR | S_IWUSR | S_IXUSR | S_IWGRP | S_IRGRP | S_IXGRP | S_IWOTH | S_IXOTH |
| 244 |
#endif |
| 245 |
#if defined(ELPP_AS_DLL) && ELPP_COMPILER_MSVC |
| 246 |
# if defined(ELPP_EXPORT_SYMBOLS) |
| 247 |
# define ELPP_EXPORT __declspec(dllexport) |
| 248 |
# else |
| 249 |
# define ELPP_EXPORT __declspec(dllimport) |
| 250 |
# endif |
| 251 |
#else |
| 252 |
# define ELPP_EXPORT |
| 253 |
#endif |
| 254 |
|
| 255 |
#undef STRTOK |
| 256 |
#undef STRERROR |
| 257 |
#undef STRCAT |
| 258 |
#undef STRCPY |
| 259 |
#if ELPP_CRT_DBG_WARNINGS |
| 260 |
# define STRTOK(a, b, c) strtok_s(a, b, c) |
| 261 |
# define STRERROR(a, b, c) strerror_s(a, b, c) |
| 262 |
# define STRCAT(a, b, len) strcat_s(a, len, b) |
| 263 |
# define STRCPY(a, b, len) strcpy_s(a, len, b) |
| 264 |
#else |
| 265 |
# define STRTOK(a, b, c) strtok(a, b) |
| 266 |
# define STRERROR(a, b, c) strerror(c) |
| 267 |
# define STRCAT(a, b, len) strcat(a, b) |
| 268 |
# define STRCPY(a, b, len) strcpy(a, b) |
| 269 |
#endif |
| 270 |
|
| 271 |
#if (ELPP_MINGW && !defined(ELPP_FORCE_USE_STD_THREAD)) |
| 272 |
# define ELPP_USE_STD_THREADING 0 |
| 273 |
#else |
| 274 |
# if ((ELPP_COMPILER_CLANG && defined(ELPP_CLANG_SUPPORTS_THREAD)) || \ |
| 275 |
(!ELPP_COMPILER_CLANG && defined(ELPP_CXX11)) || \ |
| 276 |
defined(ELPP_FORCE_USE_STD_THREAD)) |
| 277 |
# define ELPP_USE_STD_THREADING 1 |
| 278 |
# else |
| 279 |
# define ELPP_USE_STD_THREADING 0 |
| 280 |
# endif |
| 281 |
#endif |
| 282 |
#undef ELPP_FINAL |
| 283 |
#if ELPP_COMPILER_INTEL || (ELPP_GCC_VERSION < 40702) |
| 284 |
# define ELPP_FINAL |
| 285 |
#else |
| 286 |
# define ELPP_FINAL final |
| 287 |
#endif |
| 288 |
#if defined(ELPP_EXPERIMENTAL_ASYNC) |
| 289 |
# define ELPP_ASYNC_LOGGING 1 |
| 290 |
#else |
| 291 |
# define ELPP_ASYNC_LOGGING 0 |
| 292 |
#endif |
| 293 |
#if defined(ELPP_THREAD_SAFE) || ELPP_ASYNC_LOGGING |
| 294 |
# define ELPP_THREADING_ENABLED 1 |
| 295 |
#else |
| 296 |
# define ELPP_THREADING_ENABLED 0 |
| 297 |
#endif |
| 298 |
|
| 299 |
#undef ELPP_FUNC |
| 300 |
#if ELPP_COMPILER_MSVC |
| 301 |
# define ELPP_FUNC __FUNCSIG__ |
| 302 |
#elif ELPP_COMPILER_GCC |
| 303 |
# define ELPP_FUNC __PRETTY_FUNCTION__ |
| 304 |
#elif ELPP_COMPILER_INTEL |
| 305 |
# define ELPP_FUNC __PRETTY_FUNCTION__ |
| 306 |
#elif ELPP_COMPILER_CLANG |
| 307 |
# define ELPP_FUNC __PRETTY_FUNCTION__ |
| 308 |
#else |
| 309 |
# if defined(__func__) |
| 310 |
# define ELPP_FUNC __func__ |
| 311 |
# else |
| 312 |
# define ELPP_FUNC "" |
| 313 |
# endif |
| 314 |
#endif |
| 315 |
#undef ELPP_VARIADIC_TEMPLATES_SUPPORTED |
| 316 |
|
| 317 |
#define ELPP_VARIADIC_TEMPLATES_SUPPORTED \ |
| 318 |
(ELPP_COMPILER_GCC || ELPP_COMPILER_CLANG || ELPP_COMPILER_INTEL || (ELPP_COMPILER_MSVC && _MSC_VER >= 1800)) |
| 319 |
|
| 320 |
#ifdef ELPP_DISABLE_LOGS |
| 321 |
# define ELPP_LOGGING_ENABLED 0 |
| 322 |
#else |
| 323 |
# define ELPP_LOGGING_ENABLED 1 |
| 324 |
#endif |
| 325 |
#if (!defined(ELPP_DISABLE_DEBUG_LOGS) && (ELPP_LOGGING_ENABLED)) |
| 326 |
# define ELPP_DEBUG_LOG 1 |
| 327 |
#else |
| 328 |
# define ELPP_DEBUG_LOG 0 |
| 329 |
#endif |
| 330 |
#if (!defined(ELPP_DISABLE_INFO_LOGS) && (ELPP_LOGGING_ENABLED)) |
| 331 |
# define ELPP_INFO_LOG 1 |
| 332 |
#else |
| 333 |
# define ELPP_INFO_LOG 0 |
| 334 |
#endif |
| 335 |
#if (!defined(ELPP_DISABLE_WARNING_LOGS) && (ELPP_LOGGING_ENABLED)) |
| 336 |
# define ELPP_WARNING_LOG 1 |
| 337 |
#else |
| 338 |
# define ELPP_WARNING_LOG 0 |
| 339 |
#endif |
| 340 |
#if (!defined(ELPP_DISABLE_ERROR_LOGS) && (ELPP_LOGGING_ENABLED)) |
| 341 |
# define ELPP_ERROR_LOG 1 |
| 342 |
#else |
| 343 |
# define ELPP_ERROR_LOG 0 |
| 344 |
#endif |
| 345 |
#if (!defined(ELPP_DISABLE_FATAL_LOGS) && (ELPP_LOGGING_ENABLED)) |
| 346 |
# define ELPP_FATAL_LOG 1 |
| 347 |
#else |
| 348 |
# define ELPP_FATAL_LOG 0 |
| 349 |
#endif |
| 350 |
#if (!defined(ELPP_DISABLE_TRACE_LOGS) && (ELPP_LOGGING_ENABLED)) |
| 351 |
# define ELPP_TRACE_LOG 1 |
| 352 |
#else |
| 353 |
# define ELPP_TRACE_LOG 0 |
| 354 |
#endif |
| 355 |
#if (!defined(ELPP_DISABLE_VERBOSE_LOGS) && (ELPP_LOGGING_ENABLED)) |
| 356 |
# define ELPP_VERBOSE_LOG 1 |
| 357 |
#else |
| 358 |
# define ELPP_VERBOSE_LOG 0 |
| 359 |
#endif |
| 360 |
#if (!(ELPP_CXX0X || ELPP_CXX11)) |
| 361 |
# error "C++0x (or higher) support not detected! (Is `-std=c++11' missing?)" |
| 362 |
#endif |
| 363 |
|
| 364 |
#if defined(ELPP_SYSLOG) |
| 365 |
# include <syslog.h> |
| 366 |
#endif |
| 367 |
#include <climits> |
| 368 |
#include <ctime> |
| 369 |
#include <cstring> |
| 370 |
#include <cstdlib> |
| 371 |
#include <cctype> |
| 372 |
#include <cwchar> |
| 373 |
#include <csignal> |
| 374 |
#include <cerrno> |
| 375 |
#include <cstdarg> |
| 376 |
#if defined(ELPP_UNICODE) |
| 377 |
# include <locale> |
| 378 |
# if ELPP_OS_WINDOWS |
| 379 |
# include <codecvt> |
| 380 |
# endif |
| 381 |
#endif |
| 382 |
#if ELPP_STACKTRACE |
| 383 |
# include <cxxabi.h> |
| 384 |
# include <execinfo.h> |
| 385 |
#endif |
| 386 |
#if ELPP_OS_ANDROID |
| 387 |
# include <sys/system_properties.h> |
| 388 |
#endif |
| 389 |
#if ELPP_OS_UNIX |
| 390 |
# include <sys/stat.h> |
| 391 |
# include <sys/time.h> |
| 392 |
#elif ELPP_OS_WINDOWS |
| 393 |
# include <direct.h> |
| 394 |
# include <windows.h> |
| 395 |
# if defined(WIN32_LEAN_AND_MEAN) |
| 396 |
# if defined(ELPP_WINSOCK2) |
| 397 |
# include <winsock2.h> |
| 398 |
# else |
| 399 |
# include <winsock.h> |
| 400 |
# endif |
| 401 |
# endif |
| 402 |
#endif |
| 403 |
#include <string> |
| 404 |
#include <vector> |
| 405 |
#include <map> |
| 406 |
#include <unordered_map> |
| 407 |
#include <utility> |
| 408 |
#include <functional> |
| 409 |
#include <algorithm> |
| 410 |
#include <fstream> |
| 411 |
#include <iostream> |
| 412 |
#include <sstream> |
| 413 |
#include <memory> |
| 414 |
#include <type_traits> |
| 415 |
#if ELPP_THREADING_ENABLED |
| 416 |
# if ELPP_USE_STD_THREADING |
| 417 |
# include <mutex> |
| 418 |
# include <thread> |
| 419 |
# else |
| 420 |
# if ELPP_OS_UNIX |
| 421 |
# include <pthread.h> |
| 422 |
# endif |
| 423 |
# endif |
| 424 |
#endif |
| 425 |
#if ELPP_ASYNC_LOGGING |
| 426 |
# if defined(ELPP_NO_SLEEP_FOR) |
| 427 |
# include <unistd.h> |
| 428 |
# endif |
| 429 |
# include <thread> |
| 430 |
# include <queue> |
| 431 |
# include <condition_variable> |
| 432 |
#endif |
| 433 |
#if defined(ELPP_STL_LOGGING) |
| 434 |
|
| 435 |
# include <list> |
| 436 |
# include <queue> |
| 437 |
# include <deque> |
| 438 |
# include <set> |
| 439 |
# include <bitset> |
| 440 |
# include <stack> |
| 441 |
# if defined(ELPP_LOG_STD_ARRAY) |
| 442 |
# include <array> |
| 443 |
# endif |
| 444 |
# if defined(ELPP_LOG_UNORDERED_SET) |
| 445 |
# include <unordered_set> |
| 446 |
# endif |
| 447 |
#endif |
| 448 |
#if defined(ELPP_QT_LOGGING) |
| 449 |
|
| 450 |
# include <QString> |
| 451 |
# include <QByteArray> |
| 452 |
# include <QVector> |
| 453 |
# include <QList> |
| 454 |
# include <QPair> |
| 455 |
# include <QMap> |
| 456 |
# include <QQueue> |
| 457 |
# include <QSet> |
| 458 |
# include <QLinkedList> |
| 459 |
# include <QHash> |
| 460 |
# include <QMultiHash> |
| 461 |
# include <QStack> |
| 462 |
#endif |
| 463 |
#if defined(ELPP_BOOST_LOGGING) |
| 464 |
|
| 465 |
# include <boost/container/vector.hpp> |
| 466 |
# include <boost/container/stable_vector.hpp> |
| 467 |
# include <boost/container/list.hpp> |
| 468 |
# include <boost/container/deque.hpp> |
| 469 |
# include <boost/container/map.hpp> |
| 470 |
# include <boost/container/flat_map.hpp> |
| 471 |
# include <boost/container/set.hpp> |
| 472 |
# include <boost/container/flat_set.hpp> |
| 473 |
#endif |
| 474 |
#if defined(ELPP_WXWIDGETS_LOGGING) |
| 475 |
|
| 476 |
# include <wx/vector.h> |
| 477 |
#endif |
| 478 |
#if defined(ELPP_UTC_DATETIME) |
| 479 |
# define elpptime_r gmtime_r |
| 480 |
# define elpptime_s gmtime_s |
| 481 |
# define elpptime gmtime |
| 482 |
#else |
| 483 |
# define elpptime_r localtime_r |
| 484 |
# define elpptime_s localtime_s |
| 485 |
# define elpptime localtime |
| 486 |
#endif |
| 487 |
|
| 488 |
namespace el { |
| 489 |
class Logger; |
| 490 |
class LogMessage; |
| 491 |
class PerformanceTrackingData; |
| 492 |
class Loggers; |
| 493 |
class Helpers; |
| 494 |
template <typename T> class Callback; |
| 495 |
class LogDispatchCallback; |
| 496 |
class PerformanceTrackingCallback; |
| 497 |
class LoggerRegistrationCallback; |
| 498 |
class LogDispatchData; |
| 499 |
namespace base { |
| 500 |
class Storage; |
| 501 |
class RegisteredLoggers; |
| 502 |
class PerformanceTracker; |
| 503 |
class MessageBuilder; |
| 504 |
class Writer; |
| 505 |
class PErrorWriter; |
| 506 |
class LogDispatcher; |
| 507 |
class DefaultLogBuilder; |
| 508 |
class DefaultLogDispatchCallback; |
| 509 |
#if ELPP_ASYNC_LOGGING |
| 510 |
class AsyncLogDispatchCallback; |
| 511 |
class AsyncDispatchWorker; |
| 512 |
#endif |
| 513 |
class DefaultPerformanceTrackingCallback; |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
namespace el { |
| 518 |
|
| 519 |
namespace base { |
| 520 |
|
| 521 |
namespace type { |
| 522 |
#undef ELPP_LITERAL |
| 523 |
#undef ELPP_STRLEN |
| 524 |
#undef ELPP_COUT |
| 525 |
#if defined(ELPP_UNICODE) |
| 526 |
# define ELPP_LITERAL(txt) L##txt |
| 527 |
# define ELPP_STRLEN wcslen |
| 528 |
# if defined ELPP_CUSTOM_COUT |
| 529 |
# define ELPP_COUT ELPP_CUSTOM_COUT |
| 530 |
# else |
| 531 |
# define ELPP_COUT std::wcout |
| 532 |
# endif |
| 533 |
typedef wchar_t char_t; |
| 534 |
typedef std::wstring string_t; |
| 535 |
typedef std::wstringstream stringstream_t; |
| 536 |
typedef std::wfstream fstream_t; |
| 537 |
typedef std::wostream ostream_t; |
| 538 |
#else |
| 539 |
# define ELPP_LITERAL(txt) txt |
| 540 |
# define ELPP_STRLEN strlen |
| 541 |
# if defined ELPP_CUSTOM_COUT |
| 542 |
# define ELPP_COUT ELPP_CUSTOM_COUT |
| 543 |
# else |
| 544 |
# define ELPP_COUT std::cout |
| 545 |
# endif |
| 546 |
typedef char char_t; |
| 547 |
typedef std::string string_t; |
| 548 |
typedef std::stringstream stringstream_t; |
| 549 |
typedef std::fstream fstream_t; |
| 550 |
typedef std::ostream ostream_t; |
| 551 |
#endif |
| 552 |
#if defined(ELPP_CUSTOM_COUT_LINE) |
| 553 |
# define ELPP_COUT_LINE(logLine) ELPP_CUSTOM_COUT_LINE(logLine) |
| 554 |
#else |
| 555 |
# define ELPP_COUT_LINE(logLine) logLine << std::flush |
| 556 |
#endif |
| 557 |
typedef unsigned int EnumType; |
| 558 |
typedef unsigned short VerboseLevel; |
| 559 |
typedef unsigned long int LineNumber; |
| 560 |
typedef base::Storage *StoragePointer; |
| 561 |
typedef std::shared_ptr<LogDispatchCallback> LogDispatchCallbackPtr; |
| 562 |
typedef std::shared_ptr<PerformanceTrackingCallback> PerformanceTrackingCallbackPtr; |
| 563 |
typedef std::shared_ptr<LoggerRegistrationCallback> LoggerRegistrationCallbackPtr; |
| 564 |
typedef std::unique_ptr<el::base::PerformanceTracker> PerformanceTrackerPtr; |
| 565 |
} |
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
class NoCopy { |
| 570 |
protected: |
| 571 |
NoCopy(void) {} |
| 572 |
private: |
| 573 |
NoCopy(const NoCopy&); |
| 574 |
NoCopy& operator=(const NoCopy&); |
| 575 |
}; |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
class StaticClass { |
| 581 |
private: |
| 582 |
StaticClass(void); |
| 583 |
StaticClass(const StaticClass&); |
| 584 |
StaticClass& operator=(const StaticClass&); |
| 585 |
}; |
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
enum class Level : base::type::EnumType { |
| 592 |
|
| 593 |
Global = 1, |
| 594 |
|
| 595 |
Trace = 2, |
| 596 |
|
| 597 |
Debug = 4, |
| 598 |
|
| 599 |
Fatal = 8, |
| 600 |
|
| 601 |
Error = 16, |
| 602 |
|
| 603 |
Warning = 32, |
| 604 |
|
| 605 |
Verbose = 64, |
| 606 |
|
| 607 |
Info = 128, |
| 608 |
|
| 609 |
Unknown = 1010 |
| 610 |
}; |
| 611 |
enum class Color : base::type::EnumType { |
| 612 |
Default, |
| 613 |
Red, |
| 614 |
Green, |
| 615 |
Yellow, |
| 616 |
Blue, |
| 617 |
Magenta, |
| 618 |
Cyan, |
| 619 |
}; |
| 620 |
} |
| 621 |
namespace std { |
| 622 |
template<> struct hash<el::Level> { |
| 623 |
public: |
| 624 |
std::size_t operator()(const el::Level& l) const { |
| 625 |
return hash<el::base::type::EnumType> {}(static_cast<el::base::type::EnumType>(l)); |
| 626 |
} |
| 627 |
}; |
| 628 |
} |
| 629 |
namespace el { |
| 630 |
|
| 631 |
class LevelHelper : base::StaticClass { |
| 632 |
public: |
| 633 |
|
| 634 |
static const base::type::EnumType kMinValid = static_cast<base::type::EnumType>(Level::Trace); |
| 635 |
|
| 636 |
static const base::type::EnumType kMaxValid = static_cast<base::type::EnumType>(Level::Info); |
| 637 |
|
| 638 |
static base::type::EnumType castToInt(Level level) { |
| 639 |
return static_cast<base::type::EnumType>(level); |
| 640 |
} |
| 641 |
|
| 642 |
static Level castFromInt(base::type::EnumType l) { |
| 643 |
return static_cast<Level>(l); |
| 644 |
} |
| 645 |
|
| 646 |
|
| 647 |
static const char* convertToString(Level level); |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
static Level convertFromStringPrefix(const char* levelStr); |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
static Level convertFromString(const char* levelStr); |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
static void forEachLevel(base::type::EnumType* startIndex, const std::function<bool(void)>& fn); |
| 661 |
}; |
| 662 |
|
| 663 |
|
| 664 |
enum class ConfigurationType : base::type::EnumType { |
| 665 |
|
| 666 |
|
| 667 |
Enabled = 1, |
| 668 |
|
| 669 |
ToFile = 2, |
| 670 |
|
| 671 |
|
| 672 |
ToStandardOutput = 4, |
| 673 |
|
| 674 |
Format = 8, |
| 675 |
|
| 676 |
Filename = 16, |
| 677 |
|
| 678 |
SubsecondPrecision = 32, |
| 679 |
|
| 680 |
MillisecondsWidth = SubsecondPrecision, |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
PerformanceTracking = 64, |
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
MaxLogFileSize = 128, |
| 690 |
|
| 691 |
LogFlushThreshold = 256, |
| 692 |
|
| 693 |
Unknown = 1010 |
| 694 |
}; |
| 695 |
|
| 696 |
class ConfigurationTypeHelper : base::StaticClass { |
| 697 |
public: |
| 698 |
|
| 699 |
static const base::type::EnumType kMinValid = static_cast<base::type::EnumType>(ConfigurationType::Enabled); |
| 700 |
|
| 701 |
static const base::type::EnumType kMaxValid = static_cast<base::type::EnumType>(ConfigurationType::MaxLogFileSize); |
| 702 |
|
| 703 |
static base::type::EnumType castToInt(ConfigurationType configurationType) { |
| 704 |
return static_cast<base::type::EnumType>(configurationType); |
| 705 |
} |
| 706 |
|
| 707 |
static ConfigurationType castFromInt(base::type::EnumType c) { |
| 708 |
return static_cast<ConfigurationType>(c); |
| 709 |
} |
| 710 |
|
| 711 |
|
| 712 |
static const char* convertToString(ConfigurationType configurationType); |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
static ConfigurationType convertFromString(const char* configStr); |
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
static inline void forEachConfigType(base::type::EnumType* startIndex, const std::function<bool(void)>& fn); |
| 723 |
}; |
| 724 |
|
| 725 |
enum class LoggingFlag : base::type::EnumType { |
| 726 |
|
| 727 |
NewLineForContainer = 1, |
| 728 |
|
| 729 |
|
| 730 |
AllowVerboseIfModuleNotSpecified = 2, |
| 731 |
|
| 732 |
LogDetailedCrashReason = 4, |
| 733 |
|
| 734 |
DisableApplicationAbortOnFatalLog = 8, |
| 735 |
|
| 736 |
ImmediateFlush = 16, |
| 737 |
|
| 738 |
StrictLogFileSizeCheck = 32, |
| 739 |
|
| 740 |
ColoredTerminalOutput = 64, |
| 741 |
|
| 742 |
MultiLoggerSupport = 128, |
| 743 |
|
| 744 |
DisablePerformanceTrackingCheckpointComparison = 256, |
| 745 |
|
| 746 |
DisableVModules = 512, |
| 747 |
|
| 748 |
DisableVModulesExtensions = 1024, |
| 749 |
|
| 750 |
HierarchicalLogging = 2048, |
| 751 |
|
| 752 |
CreateLoggerAutomatically = 4096, |
| 753 |
|
| 754 |
AutoSpacing = 8192, |
| 755 |
|
| 756 |
FixedTimeFormat = 16384, |
| 757 |
|
| 758 |
IgnoreSigInt = 32768, |
| 759 |
}; |
| 760 |
namespace base { |
| 761 |
|
| 762 |
namespace consts { |
| 763 |
static const char kFormatSpecifierCharValue = 'v'; |
| 764 |
static const char kFormatSpecifierChar = '%'; |
| 765 |
static const unsigned int kMaxLogPerCounter = 100000; |
| 766 |
static const unsigned int kMaxLogPerContainer = 100; |
| 767 |
static const unsigned int kDefaultSubsecondPrecision = 3; |
| 768 |
|
| 769 |
#ifdef ELPP_DEFAULT_LOGGER |
| 770 |
static const char* kDefaultLoggerId = ELPP_DEFAULT_LOGGER; |
| 771 |
#else |
| 772 |
static const char* kDefaultLoggerId = "default"; |
| 773 |
#endif |
| 774 |
|
| 775 |
#if defined(ELPP_FEATURE_ALL) || defined(ELPP_FEATURE_PERFORMANCE_TRACKING) |
| 776 |
#ifdef ELPP_DEFAULT_PERFORMANCE_LOGGER |
| 777 |
static const char* kPerformanceLoggerId = ELPP_DEFAULT_PERFORMANCE_LOGGER; |
| 778 |
#else |
| 779 |
static const char* kPerformanceLoggerId = "performance"; |
| 780 |
#endif |
| 781 |
#endif |
| 782 |
|
| 783 |
#if defined(ELPP_SYSLOG) |
| 784 |
static const char* kSysLogLoggerId = "syslog"; |
| 785 |
#endif |
| 786 |
|
| 787 |
#if ELPP_OS_WINDOWS |
| 788 |
static const char* kFilePathSeperator = "\\"; |
| 789 |
#else |
| 790 |
static const char* kFilePathSeperator = "/"; |
| 791 |
#endif |
| 792 |
|
| 793 |
static const std::size_t kSourceFilenameMaxLength = 100; |
| 794 |
static const std::size_t kSourceLineMaxLength = 10; |
| 795 |
static const Level kPerformanceTrackerDefaultLevel = Level::Info; |
| 796 |
const struct { |
| 797 |
double value; |
| 798 |
const base::type::char_t* unit; |
| 799 |
} kTimeFormats[] = { |
| 800 |
{ 1000.0f, ELPP_LITERAL("us") }, |
| 801 |
{ 1000.0f, ELPP_LITERAL("ms") }, |
| 802 |
{ 60.0f, ELPP_LITERAL("seconds") }, |
| 803 |
{ 60.0f, ELPP_LITERAL("minutes") }, |
| 804 |
{ 24.0f, ELPP_LITERAL("hours") }, |
| 805 |
{ 7.0f, ELPP_LITERAL("days") } |
| 806 |
}; |
| 807 |
static const int kTimeFormatsCount = sizeof(kTimeFormats) / sizeof(kTimeFormats[0]); |
| 808 |
const struct { |
| 809 |
int numb; |
| 810 |
const char* name; |
| 811 |
const char* brief; |
| 812 |
const char* detail; |
| 813 |
} kCrashSignals[] = { |
| 814 |
|
| 815 |
{ |
| 816 |
SIGABRT, "SIGABRT", "Abnormal termination", |
| 817 |
"Program was abnormally terminated." |
| 818 |
}, |
| 819 |
{ |
| 820 |
SIGFPE, "SIGFPE", "Erroneous arithmetic operation", |
| 821 |
"Arithemetic operation issue such as division by zero or operation resulting in overflow." |
| 822 |
}, |
| 823 |
{ |
| 824 |
SIGILL, "SIGILL", "Illegal instruction", |
| 825 |
"Generally due to a corruption in the code or to an attempt to execute data." |
| 826 |
}, |
| 827 |
{ |
| 828 |
SIGSEGV, "SIGSEGV", "Invalid access to memory", |
| 829 |
"Program is trying to read an invalid (unallocated, deleted or corrupted) or inaccessible memory." |
| 830 |
}, |
| 831 |
{ |
| 832 |
SIGINT, "SIGINT", "Interactive attention signal", |
| 833 |
"Interruption generated (generally) by user or operating system." |
| 834 |
}, |
| 835 |
}; |
| 836 |
static const int kCrashSignalsCount = sizeof(kCrashSignals) / sizeof(kCrashSignals[0]); |
| 837 |
} |
| 838 |
} |
| 839 |
typedef std::function<void(const char*, std::size_t)> PreRollOutCallback; |
| 840 |
namespace base { |
| 841 |
static inline void defaultPreRollOutCallback(const char*, std::size_t) {} |
| 842 |
|
| 843 |
enum class TimestampUnit : base::type::EnumType { |
| 844 |
Microsecond = 0, Millisecond = 1, Second = 2, Minute = 3, Hour = 4, Day = 5 |
| 845 |
}; |
| 846 |
|
| 847 |
enum class FormatFlags : base::type::EnumType { |
| 848 |
DateTime = 1 << 1, |
| 849 |
LoggerId = 1 << 2, |
| 850 |
File = 1 << 3, |
| 851 |
Line = 1 << 4, |
| 852 |
Location = 1 << 5, |
| 853 |
Function = 1 << 6, |
| 854 |
User = 1 << 7, |
| 855 |
Host = 1 << 8, |
| 856 |
LogMessage = 1 << 9, |
| 857 |
VerboseLevel = 1 << 10, |
| 858 |
AppName = 1 << 11, |
| 859 |
ThreadId = 1 << 12, |
| 860 |
Level = 1 << 13, |
| 861 |
FileBase = 1 << 14, |
| 862 |
LevelShort = 1 << 15 |
| 863 |
}; |
| 864 |
|
| 865 |
class SubsecondPrecision { |
| 866 |
public: |
| 867 |
SubsecondPrecision(void) { |
| 868 |
init(base::consts::kDefaultSubsecondPrecision); |
| 869 |
} |
| 870 |
explicit SubsecondPrecision(int width) { |
| 871 |
init(width); |
| 872 |
} |
| 873 |
bool operator==(const SubsecondPrecision& ssPrec) { |
| 874 |
return m_width == ssPrec.m_width && m_offset == ssPrec.m_offset; |
| 875 |
} |
| 876 |
int m_width; |
| 877 |
unsigned int m_offset; |
| 878 |
private: |
| 879 |
void init(int width); |
| 880 |
}; |
| 881 |
|
| 882 |
typedef SubsecondPrecision MillisecondsWidth; |
| 883 |
|
| 884 |
namespace utils { |
| 885 |
|
| 886 |
template <typename T> |
| 887 |
static |
| 888 |
typename std::enable_if<std::is_pointer<T*>::value, void>::type |
| 889 |
safeDelete(T*& pointer) { |
| 890 |
if (pointer == nullptr) |
| 891 |
return; |
| 892 |
delete pointer; |
| 893 |
pointer = nullptr; |
| 894 |
} |
| 895 |
|
| 896 |
|
| 897 |
namespace bitwise { |
| 898 |
template <typename Enum> |
| 899 |
static inline base::type::EnumType And(Enum e, base::type::EnumType flag) { |
| 900 |
return static_cast<base::type::EnumType>(flag) & static_cast<base::type::EnumType>(e); |
| 901 |
} |
| 902 |
template <typename Enum> |
| 903 |
static inline base::type::EnumType Not(Enum e, base::type::EnumType flag) { |
| 904 |
return static_cast<base::type::EnumType>(flag) & ~(static_cast<base::type::EnumType>(e)); |
| 905 |
} |
| 906 |
template <typename Enum> |
| 907 |
static inline base::type::EnumType Or(Enum e, base::type::EnumType flag) { |
| 908 |
return static_cast<base::type::EnumType>(flag) | static_cast<base::type::EnumType>(e); |
| 909 |
} |
| 910 |
} |
| 911 |
template <typename Enum> |
| 912 |
static inline void addFlag(Enum e, base::type::EnumType* flag) { |
| 913 |
*flag = base::utils::bitwise::Or<Enum>(e, *flag); |
| 914 |
} |
| 915 |
template <typename Enum> |
| 916 |
static inline void removeFlag(Enum e, base::type::EnumType* flag) { |
| 917 |
*flag = base::utils::bitwise::Not<Enum>(e, *flag); |
| 918 |
} |
| 919 |
template <typename Enum> |
| 920 |
static inline bool hasFlag(Enum e, base::type::EnumType flag) { |
| 921 |
return base::utils::bitwise::And<Enum>(e, flag) > 0x0; |
| 922 |
} |
| 923 |
} |
| 924 |
namespace threading { |
| 925 |
#if ELPP_THREADING_ENABLED |
| 926 |
# if !ELPP_USE_STD_THREADING |
| 927 |
namespace internal { |
| 928 |
|
| 929 |
class Mutex : base::NoCopy { |
| 930 |
public: |
| 931 |
Mutex(void) { |
| 932 |
# if ELPP_OS_UNIX |
| 933 |
pthread_mutexattr_t attr; |
| 934 |
pthread_mutexattr_init(&attr); |
| 935 |
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); |
| 936 |
pthread_mutex_init(&m_underlyingMutex, &attr); |
| 937 |
pthread_mutexattr_destroy(&attr); |
| 938 |
# elif ELPP_OS_WINDOWS |
| 939 |
InitializeCriticalSection(&m_underlyingMutex); |
| 940 |
# endif |
| 941 |
} |
| 942 |
|
| 943 |
virtual ~Mutex(void) { |
| 944 |
# if ELPP_OS_UNIX |
| 945 |
pthread_mutex_destroy(&m_underlyingMutex); |
| 946 |
# elif ELPP_OS_WINDOWS |
| 947 |
DeleteCriticalSection(&m_underlyingMutex); |
| 948 |
# endif |
| 949 |
} |
| 950 |
|
| 951 |
inline void lock(void) { |
| 952 |
# if ELPP_OS_UNIX |
| 953 |
pthread_mutex_lock(&m_underlyingMutex); |
| 954 |
# elif ELPP_OS_WINDOWS |
| 955 |
EnterCriticalSection(&m_underlyingMutex); |
| 956 |
# endif |
| 957 |
} |
| 958 |
|
| 959 |
inline bool try_lock(void) { |
| 960 |
# if ELPP_OS_UNIX |
| 961 |
return (pthread_mutex_trylock(&m_underlyingMutex) == 0); |
| 962 |
# elif ELPP_OS_WINDOWS |
| 963 |
return TryEnterCriticalSection(&m_underlyingMutex); |
| 964 |
# endif |
| 965 |
} |
| 966 |
|
| 967 |
inline void unlock(void) { |
| 968 |
# if ELPP_OS_UNIX |
| 969 |
pthread_mutex_unlock(&m_underlyingMutex); |
| 970 |
# elif ELPP_OS_WINDOWS |
| 971 |
LeaveCriticalSection(&m_underlyingMutex); |
| 972 |
# endif |
| 973 |
} |
| 974 |
|
| 975 |
private: |
| 976 |
# if ELPP_OS_UNIX |
| 977 |
pthread_mutex_t m_underlyingMutex; |
| 978 |
# elif ELPP_OS_WINDOWS |
| 979 |
CRITICAL_SECTION m_underlyingMutex; |
| 980 |
# endif |
| 981 |
}; |
| 982 |
|
| 983 |
template <typename M> |
| 984 |
class ScopedLock : base::NoCopy { |
| 985 |
public: |
| 986 |
explicit ScopedLock(M& mutex) { |
| 987 |
m_mutex = &mutex; |
| 988 |
m_mutex->lock(); |
| 989 |
} |
| 990 |
|
| 991 |
virtual ~ScopedLock(void) { |
| 992 |
m_mutex->unlock(); |
| 993 |
} |
| 994 |
private: |
| 995 |
M* m_mutex; |
| 996 |
ScopedLock(void); |
| 997 |
}; |
| 998 |
} |
| 999 |
typedef base::threading::internal::Mutex Mutex; |
| 1000 |
typedef base::threading::internal::ScopedLock<base::threading::Mutex> ScopedLock; |
| 1001 |
# else |
| 1002 |
typedef std::recursive_mutex Mutex; |
| 1003 |
typedef std::lock_guard<base::threading::Mutex> ScopedLock; |
| 1004 |
# endif |
| 1005 |
#else |
| 1006 |
namespace internal { |
| 1007 |
|
| 1008 |
class NoMutex : base::NoCopy { |
| 1009 |
public: |
| 1010 |
NoMutex(void) {} |
| 1011 |
inline void lock(void) {} |
| 1012 |
inline bool try_lock(void) { |
| 1013 |
return true; |
| 1014 |
} |
| 1015 |
inline void unlock(void) {} |
| 1016 |
}; |
| 1017 |
|
| 1018 |
template <typename Mutex> |
| 1019 |
class NoScopedLock : base::NoCopy { |
| 1020 |
public: |
| 1021 |
explicit NoScopedLock(Mutex&) { |
| 1022 |
} |
| 1023 |
virtual ~NoScopedLock(void) { |
| 1024 |
} |
| 1025 |
private: |
| 1026 |
NoScopedLock(void); |
| 1027 |
}; |
| 1028 |
} |
| 1029 |
typedef base::threading::internal::NoMutex Mutex; |
| 1030 |
typedef base::threading::internal::NoScopedLock<base::threading::Mutex> ScopedLock; |
| 1031 |
#endif |
| 1032 |
|
| 1033 |
class ThreadSafe { |
| 1034 |
public: |
| 1035 |
virtual inline void acquireLock(void) ELPP_FINAL { m_mutex.lock(); } |
| 1036 |
virtual inline void releaseLock(void) ELPP_FINAL { m_mutex.unlock(); } |
| 1037 |
virtual inline base::threading::Mutex& lock(void) ELPP_FINAL { return m_mutex; } |
| 1038 |
protected: |
| 1039 |
ThreadSafe(void) {} |
| 1040 |
virtual ~ThreadSafe(void) {} |
| 1041 |
private: |
| 1042 |
base::threading::Mutex m_mutex; |
| 1043 |
}; |
| 1044 |
|
| 1045 |
#if ELPP_THREADING_ENABLED |
| 1046 |
# if !ELPP_USE_STD_THREADING |
| 1047 |
|
| 1048 |
static std::string getCurrentThreadId(void) { |
| 1049 |
std::stringstream ss; |
| 1050 |
# if (ELPP_OS_WINDOWS) |
| 1051 |
ss << GetCurrentThreadId(); |
| 1052 |
# endif |
| 1053 |
return ss.str(); |
| 1054 |
} |
| 1055 |
# else |
| 1056 |
|
| 1057 |
static std::string getCurrentThreadId(void) { |
| 1058 |
std::stringstream ss; |
| 1059 |
char prev_fill = ss.fill(' '); |
| 1060 |
auto prev_flags = ss.flags(std::ios::hex); |
| 1061 |
|
| 1062 |
auto prev_width = ss.width(16); |
| 1063 |
ss << std::this_thread::get_id(); |
| 1064 |
ss.fill(prev_fill); |
| 1065 |
ss.flags(prev_flags); |
| 1066 |
ss.width(prev_width); |
| 1067 |
return ss.str(); |
| 1068 |
} |
| 1069 |
# endif |
| 1070 |
#else |
| 1071 |
static inline std::string getCurrentThreadId(void) { |
| 1072 |
return std::string(); |
| 1073 |
} |
| 1074 |
#endif |
| 1075 |
} |
| 1076 |
namespace utils { |
| 1077 |
class File : base::StaticClass { |
| 1078 |
public: |
| 1079 |
|
| 1080 |
|
| 1081 |
static base::type::fstream_t* newFileStream(const std::string& filename); |
| 1082 |
|
| 1083 |
|
| 1084 |
static std::size_t getSizeOfFile(base::type::fstream_t* fs); |
| 1085 |
|
| 1086 |
|
| 1087 |
static bool pathExists(const char* path, bool considerFile = false); |
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
static bool createPath(const std::string& path); |
| 1092 |
|
| 1093 |
static std::string extractPathFromFilename(const std::string& fullPath, |
| 1094 |
const char* seperator = base::consts::kFilePathSeperator); |
| 1095 |
|
| 1096 |
static void buildStrippedFilename(const char* filename, char buff[], const std::string &commonPrefix = NULL, |
| 1097 |
std::size_t limit = base::consts::kSourceFilenameMaxLength); |
| 1098 |
|
| 1099 |
static void buildBaseFilename(const std::string& fullPath, char buff[], |
| 1100 |
std::size_t limit = base::consts::kSourceFilenameMaxLength, |
| 1101 |
const char* seperator = base::consts::kFilePathSeperator); |
| 1102 |
}; |
| 1103 |
|
| 1104 |
class Str : base::StaticClass { |
| 1105 |
public: |
| 1106 |
|
| 1107 |
static inline bool isDigit(char c) { |
| 1108 |
return c >= '0' && c <= '9'; |
| 1109 |
} |
| 1110 |
|
| 1111 |
|
| 1112 |
static bool wildCardMatch(const char* str, const char* pattern); |
| 1113 |
|
| 1114 |
static std::string& ltrim(std::string& str); |
| 1115 |
static std::string& rtrim(std::string& str); |
| 1116 |
static std::string& trim(std::string& str); |
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
static bool startsWith(const std::string& str, const std::string& start); |
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
static bool endsWith(const std::string& str, const std::string& end); |
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
static std::string& replaceAll(std::string& str, char replaceWhat, char replaceWith); |
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
static std::string& replaceAll(std::string& str, const std::string& replaceWhat, |
| 1143 |
const std::string& replaceWith); |
| 1144 |
|
| 1145 |
static void replaceFirstWithEscape(base::type::string_t& str, const base::type::string_t& replaceWhat, |
| 1146 |
const base::type::string_t& replaceWith); |
| 1147 |
#if defined(ELPP_UNICODE) |
| 1148 |
static void replaceFirstWithEscape(base::type::string_t& str, const base::type::string_t& replaceWhat, |
| 1149 |
const std::string& replaceWith); |
| 1150 |
#endif |
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
static std::string& toUpper(std::string& str); |
| 1155 |
|
| 1156 |
|
| 1157 |
static bool cStringEq(const char* s1, const char* s2); |
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
static bool cStringCaseEq(const char* s1, const char* s2); |
| 1162 |
|
| 1163 |
|
| 1164 |
static bool contains(const char* str, char c); |
| 1165 |
|
| 1166 |
static char* convertAndAddToBuff(std::size_t n, int len, char* buf, const char* bufLim, bool zeroPadded = true); |
| 1167 |
static char* addToBuff(const char* str, char* buf, const char* bufLim); |
| 1168 |
static char* clearBuff(char buff[], std::size_t lim); |
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
static char* wcharPtrToCharPtr(const wchar_t* line); |
| 1173 |
}; |
| 1174 |
|
| 1175 |
class OS : base::StaticClass { |
| 1176 |
public: |
| 1177 |
#if ELPP_OS_WINDOWS |
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
static const char* getWindowsEnvironmentVariable(const char* varname); |
| 1183 |
#endif |
| 1184 |
#if ELPP_OS_ANDROID |
| 1185 |
|
| 1186 |
static std::string getProperty(const char* prop); |
| 1187 |
|
| 1188 |
|
| 1189 |
static std::string getDeviceName(void); |
| 1190 |
#endif |
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
static const std::string getBashOutput(const char* command); |
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
static std::string getEnvironmentVariable(const char* variableName, const char* defaultVal, |
| 1205 |
const char* alternativeBashCommand = nullptr); |
| 1206 |
|
| 1207 |
static std::string currentUser(void); |
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
static std::string currentHost(void); |
| 1213 |
|
| 1214 |
static bool termSupportsColor(std::string& term); |
| 1215 |
|
| 1216 |
static bool termSupportsColor(void); |
| 1217 |
}; |
| 1218 |
|
| 1219 |
class DateTime : base::StaticClass { |
| 1220 |
public: |
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
static void gettimeofday(struct timeval* tv); |
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
static std::string getDateTime(const char* format, const base::SubsecondPrecision* ssPrec); |
| 1232 |
|
| 1233 |
|
| 1234 |
static std::string timevalToString(struct timeval tval, const char* format, |
| 1235 |
const el::base::SubsecondPrecision* ssPrec); |
| 1236 |
|
| 1237 |
|
| 1238 |
static base::type::string_t formatTime(unsigned long long time, base::TimestampUnit timestampUnit); |
| 1239 |
|
| 1240 |
|
| 1241 |
static unsigned long long getTimeDifference(const struct timeval& endTime, const struct timeval& startTime, |
| 1242 |
base::TimestampUnit timestampUnit); |
| 1243 |
|
| 1244 |
|
| 1245 |
static struct ::tm* buildTimeInfo(struct timeval* currTime, struct ::tm* timeInfo); |
| 1246 |
private: |
| 1247 |
static char* parseFormat(char* buf, std::size_t bufSz, const char* format, const struct tm* tInfo, |
| 1248 |
std::size_t msec, const base::SubsecondPrecision* ssPrec); |
| 1249 |
}; |
| 1250 |
|
| 1251 |
class CommandLineArgs { |
| 1252 |
public: |
| 1253 |
CommandLineArgs(void) { |
| 1254 |
setArgs(0, static_cast<char**>(nullptr)); |
| 1255 |
} |
| 1256 |
CommandLineArgs(int argc, const char** argv) { |
| 1257 |
setArgs(argc, argv); |
| 1258 |
} |
| 1259 |
CommandLineArgs(int argc, char** argv) { |
| 1260 |
setArgs(argc, argv); |
| 1261 |
} |
| 1262 |
virtual ~CommandLineArgs(void) {} |
| 1263 |
|
| 1264 |
inline void setArgs(int argc, const char** argv) { |
| 1265 |
setArgs(argc, const_cast<char**>(argv)); |
| 1266 |
} |
| 1267 |
|
| 1268 |
void setArgs(int argc, char** argv); |
| 1269 |
|
| 1270 |
bool hasParamWithValue(const char* paramKey) const; |
| 1271 |
|
| 1272 |
|
| 1273 |
const char* getParamValue(const char* paramKey) const; |
| 1274 |
|
| 1275 |
bool hasParam(const char* paramKey) const; |
| 1276 |
|
| 1277 |
bool empty(void) const; |
| 1278 |
|
| 1279 |
std::size_t size(void) const; |
| 1280 |
friend base::type::ostream_t& operator<<(base::type::ostream_t& os, const CommandLineArgs& c); |
| 1281 |
|
| 1282 |
private: |
| 1283 |
int m_argc; |
| 1284 |
char** m_argv; |
| 1285 |
std::unordered_map<std::string, std::string> m_paramsWithValue; |
| 1286 |
std::vector<std::string> m_params; |
| 1287 |
}; |
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
template <typename T_Ptr, typename Container> |
| 1295 |
class AbstractRegistry : public base::threading::ThreadSafe { |
| 1296 |
public: |
| 1297 |
typedef typename Container::iterator iterator; |
| 1298 |
typedef typename Container::const_iterator const_iterator; |
| 1299 |
|
| 1300 |
|
| 1301 |
AbstractRegistry(void) {} |
| 1302 |
|
| 1303 |
|
| 1304 |
AbstractRegistry(AbstractRegistry&& sr) { |
| 1305 |
if (this == &sr) { |
| 1306 |
return; |
| 1307 |
} |
| 1308 |
unregisterAll(); |
| 1309 |
m_list = std::move(sr.m_list); |
| 1310 |
} |
| 1311 |
|
| 1312 |
bool operator==(const AbstractRegistry<T_Ptr, Container>& other) { |
| 1313 |
if (size() != other.size()) { |
| 1314 |
return false; |
| 1315 |
} |
| 1316 |
for (std::size_t i = 0; i < m_list.size(); ++i) { |
| 1317 |
if (m_list.at(i) != other.m_list.at(i)) { |
| 1318 |
return false; |
| 1319 |
} |
| 1320 |
} |
| 1321 |
return true; |
| 1322 |
} |
| 1323 |
|
| 1324 |
bool operator!=(const AbstractRegistry<T_Ptr, Container>& other) { |
| 1325 |
if (size() != other.size()) { |
| 1326 |
return true; |
| 1327 |
} |
| 1328 |
for (std::size_t i = 0; i < m_list.size(); ++i) { |
| 1329 |
if (m_list.at(i) != other.m_list.at(i)) { |
| 1330 |
return true; |
| 1331 |
} |
| 1332 |
} |
| 1333 |
return false; |
| 1334 |
} |
| 1335 |
|
| 1336 |
|
| 1337 |
AbstractRegistry& operator=(AbstractRegistry&& sr) { |
| 1338 |
if (this == &sr) { |
| 1339 |
return *this; |
| 1340 |
} |
| 1341 |
unregisterAll(); |
| 1342 |
m_list = std::move(sr.m_list); |
| 1343 |
return *this; |
| 1344 |
} |
| 1345 |
|
| 1346 |
virtual ~AbstractRegistry(void) { |
| 1347 |
} |
| 1348 |
|
| 1349 |
|
| 1350 |
virtual inline iterator begin(void) ELPP_FINAL { |
| 1351 |
return m_list.begin(); |
| 1352 |
} |
| 1353 |
|
| 1354 |
|
| 1355 |
virtual inline iterator end(void) ELPP_FINAL { |
| 1356 |
return m_list.end(); |
| 1357 |
} |
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
virtual inline const_iterator cbegin(void) const ELPP_FINAL { |
| 1362 |
return m_list.cbegin(); |
| 1363 |
} |
| 1364 |
|
| 1365 |
|
| 1366 |
virtual inline const_iterator cend(void) const ELPP_FINAL { |
| 1367 |
return m_list.cend(); |
| 1368 |
} |
| 1369 |
|
| 1370 |
|
| 1371 |
virtual inline bool empty(void) const ELPP_FINAL { |
| 1372 |
return m_list.empty(); |
| 1373 |
} |
| 1374 |
|
| 1375 |
|
| 1376 |
virtual inline std::size_t size(void) const ELPP_FINAL { |
| 1377 |
return m_list.size(); |
| 1378 |
} |
| 1379 |
|
| 1380 |
|
| 1381 |
virtual inline Container& list(void) ELPP_FINAL { |
| 1382 |
return m_list; |
| 1383 |
} |
| 1384 |
|
| 1385 |
|
| 1386 |
virtual inline const Container& list(void) const ELPP_FINAL { |
| 1387 |
return m_list; |
| 1388 |
} |
| 1389 |
|
| 1390 |
|
| 1391 |
virtual void unregisterAll(void) = 0; |
| 1392 |
|
| 1393 |
protected: |
| 1394 |
virtual void deepCopy(const AbstractRegistry<T_Ptr, Container>&) = 0; |
| 1395 |
void reinitDeepCopy(const AbstractRegistry<T_Ptr, Container>& sr) { |
| 1396 |
unregisterAll(); |
| 1397 |
deepCopy(sr); |
| 1398 |
} |
| 1399 |
|
| 1400 |
private: |
| 1401 |
Container m_list; |
| 1402 |
}; |
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
template <typename T_Ptr, typename T_Key = const char*> |
| 1410 |
class Registry : public AbstractRegistry<T_Ptr, std::unordered_map<T_Key, T_Ptr*>> { |
| 1411 |
public: |
| 1412 |
typedef typename Registry<T_Ptr, T_Key>::iterator iterator; |
| 1413 |
typedef typename Registry<T_Ptr, T_Key>::const_iterator const_iterator; |
| 1414 |
|
| 1415 |
Registry(void) {} |
| 1416 |
|
| 1417 |
|
| 1418 |
Registry(const Registry& sr) : AbstractRegistry<T_Ptr, std::vector<T_Ptr*>>() { |
| 1419 |
if (this == &sr) { |
| 1420 |
return; |
| 1421 |
} |
| 1422 |
this->reinitDeepCopy(sr); |
| 1423 |
} |
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
Registry& operator=(const Registry& sr) { |
| 1429 |
if (this == &sr) { |
| 1430 |
return *this; |
| 1431 |
} |
| 1432 |
this->reinitDeepCopy(sr); |
| 1433 |
return *this; |
| 1434 |
} |
| 1435 |
|
| 1436 |
virtual ~Registry(void) { |
| 1437 |
unregisterAll(); |
| 1438 |
} |
| 1439 |
|
| 1440 |
protected: |
| 1441 |
virtual void unregisterAll(void) ELPP_FINAL { |
| 1442 |
if (!this->empty()) { |
| 1443 |
for (auto&& curr : this->list()) { |
| 1444 |
base::utils::safeDelete(curr.second); |
| 1445 |
} |
| 1446 |
this->list().clear(); |
| 1447 |
} |
| 1448 |
} |
| 1449 |
|
| 1450 |
|
| 1451 |
virtual void registerNew(const T_Key& uniqKey, T_Ptr* ptr) ELPP_FINAL { |
| 1452 |
unregister(uniqKey); |
| 1453 |
this->list().insert(std::make_pair(uniqKey, ptr)); |
| 1454 |
} |
| 1455 |
|
| 1456 |
|
| 1457 |
void unregister(const T_Key& uniqKey) { |
| 1458 |
T_Ptr* existing = get(uniqKey); |
| 1459 |
if (existing != nullptr) { |
| 1460 |
this->list().erase(uniqKey); |
| 1461 |
base::utils::safeDelete(existing); |
| 1462 |
} |
| 1463 |
} |
| 1464 |
|
| 1465 |
|
| 1466 |
T_Ptr* get(const T_Key& uniqKey) { |
| 1467 |
iterator it = this->list().find(uniqKey); |
| 1468 |
return it == this->list().end() |
| 1469 |
? nullptr |
| 1470 |
: it->second; |
| 1471 |
} |
| 1472 |
|
| 1473 |
private: |
| 1474 |
virtual void deepCopy(const AbstractRegistry<T_Ptr, std::unordered_map<T_Key, T_Ptr*>>& sr) ELPP_FINAL { |
| 1475 |
for (const_iterator it = sr.cbegin(); it != sr.cend(); ++it) { |
| 1476 |
registerNew(it->first, new T_Ptr(*it->second)); |
| 1477 |
} |
| 1478 |
} |
| 1479 |
}; |
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
template <typename T_Ptr, typename Pred> |
| 1486 |
class RegistryWithPred : public AbstractRegistry<T_Ptr, std::vector<T_Ptr*>> { |
| 1487 |
public: |
| 1488 |
typedef typename RegistryWithPred<T_Ptr, Pred>::iterator iterator; |
| 1489 |
typedef typename RegistryWithPred<T_Ptr, Pred>::const_iterator const_iterator; |
| 1490 |
|
| 1491 |
RegistryWithPred(void) { |
| 1492 |
} |
| 1493 |
|
| 1494 |
virtual ~RegistryWithPred(void) { |
| 1495 |
unregisterAll(); |
| 1496 |
} |
| 1497 |
|
| 1498 |
|
| 1499 |
RegistryWithPred(const RegistryWithPred& sr) : AbstractRegistry<T_Ptr, std::vector<T_Ptr*>>() { |
| 1500 |
if (this == &sr) { |
| 1501 |
return; |
| 1502 |
} |
| 1503 |
this->reinitDeepCopy(sr); |
| 1504 |
} |
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
RegistryWithPred& operator=(const RegistryWithPred& sr) { |
| 1510 |
if (this == &sr) { |
| 1511 |
return *this; |
| 1512 |
} |
| 1513 |
this->reinitDeepCopy(sr); |
| 1514 |
return *this; |
| 1515 |
} |
| 1516 |
|
| 1517 |
friend base::type::ostream_t& operator<<(base::type::ostream_t& os, const RegistryWithPred& sr) { |
| 1518 |
for (const_iterator it = sr.list().begin(); it != sr.list().end(); ++it) { |
| 1519 |
os << ELPP_LITERAL(" ") << **it << ELPP_LITERAL("\n"); |
| 1520 |
} |
| 1521 |
return os; |
| 1522 |
} |
| 1523 |
|
| 1524 |
protected: |
| 1525 |
virtual void unregisterAll(void) ELPP_FINAL { |
| 1526 |
if (!this->empty()) { |
| 1527 |
for (auto&& curr : this->list()) { |
| 1528 |
base::utils::safeDelete(curr); |
| 1529 |
} |
| 1530 |
this->list().clear(); |
| 1531 |
} |
| 1532 |
} |
| 1533 |
|
| 1534 |
virtual void unregister(T_Ptr*& ptr) ELPP_FINAL { |
| 1535 |
if (ptr) { |
| 1536 |
iterator iter = this->begin(); |
| 1537 |
for (; iter != this->end(); ++iter) { |
| 1538 |
if (ptr == *iter) { |
| 1539 |
break; |
| 1540 |
} |
| 1541 |
} |
| 1542 |
if (iter != this->end() && *iter != nullptr) { |
| 1543 |
this->list().erase(iter); |
| 1544 |
base::utils::safeDelete(*iter); |
| 1545 |
} |
| 1546 |
} |
| 1547 |
} |
| 1548 |
|
| 1549 |
virtual inline void registerNew(T_Ptr* ptr) ELPP_FINAL { |
| 1550 |
this->list().push_back(ptr); |
| 1551 |
} |
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
template <typename T, typename T2> |
| 1556 |
T_Ptr* get(const T& arg1, const T2 arg2) { |
| 1557 |
iterator iter = std::find_if(this->list().begin(), this->list().end(), Pred(arg1, arg2)); |
| 1558 |
if (iter != this->list().end() && *iter != nullptr) { |
| 1559 |
return *iter; |
| 1560 |
} |
| 1561 |
return nullptr; |
| 1562 |
} |
| 1563 |
|
| 1564 |
private: |
| 1565 |
virtual void deepCopy(const AbstractRegistry<T_Ptr, std::vector<T_Ptr*>>& sr) { |
| 1566 |
for (const_iterator it = sr.list().begin(); it != sr.list().end(); ++it) { |
| 1567 |
registerNew(new T_Ptr(**it)); |
| 1568 |
} |
| 1569 |
} |
| 1570 |
}; |
| 1571 |
class Utils { |
| 1572 |
public: |
| 1573 |
template <typename T, typename TPtr> |
| 1574 |
static bool installCallback(const std::string& id, std::unordered_map<std::string, TPtr>* mapT) { |
| 1575 |
if (mapT->find(id) == mapT->end()) { |
| 1576 |
mapT->insert(std::make_pair(id, TPtr(new T()))); |
| 1577 |
return true; |
| 1578 |
} |
| 1579 |
return false; |
| 1580 |
} |
| 1581 |
|
| 1582 |
template <typename T, typename TPtr> |
| 1583 |
static void uninstallCallback(const std::string& id, std::unordered_map<std::string, TPtr>* mapT) { |
| 1584 |
if (mapT->find(id) != mapT->end()) { |
| 1585 |
mapT->erase(id); |
| 1586 |
} |
| 1587 |
} |
| 1588 |
|
| 1589 |
template <typename T, typename TPtr> |
| 1590 |
static T* callback(const std::string& id, std::unordered_map<std::string, TPtr>* mapT) { |
| 1591 |
typename std::unordered_map<std::string, TPtr>::iterator iter = mapT->find(id); |
| 1592 |
if (iter != mapT->end()) { |
| 1593 |
return static_cast<T*>(iter->second.get()); |
| 1594 |
} |
| 1595 |
return nullptr; |
| 1596 |
} |
| 1597 |
}; |
| 1598 |
} |
| 1599 |
} |
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
class Loggable { |
| 1604 |
public: |
| 1605 |
virtual ~Loggable(void) {} |
| 1606 |
virtual void log(el::base::type::ostream_t&) const = 0; |
| 1607 |
private: |
| 1608 |
friend inline el::base::type::ostream_t& operator<<(el::base::type::ostream_t& os, const Loggable& loggable) { |
| 1609 |
loggable.log(os); |
| 1610 |
return os; |
| 1611 |
} |
| 1612 |
}; |
| 1613 |
namespace base { |
| 1614 |
|
| 1615 |
class LogFormat : public Loggable { |
| 1616 |
public: |
| 1617 |
LogFormat(void); |
| 1618 |
LogFormat(Level level, const base::type::string_t& format); |
| 1619 |
LogFormat(const LogFormat& logFormat); |
| 1620 |
LogFormat(LogFormat&& logFormat); |
| 1621 |
LogFormat& operator=(const LogFormat& logFormat); |
| 1622 |
virtual ~LogFormat(void) {} |
| 1623 |
bool operator==(const LogFormat& other); |
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
void parseFromFormat(const base::type::string_t& userFormat); |
| 1628 |
|
| 1629 |
inline Level level(void) const { |
| 1630 |
return m_level; |
| 1631 |
} |
| 1632 |
|
| 1633 |
inline const base::type::string_t& userFormat(void) const { |
| 1634 |
return m_userFormat; |
| 1635 |
} |
| 1636 |
|
| 1637 |
inline const base::type::string_t& format(void) const { |
| 1638 |
return m_format; |
| 1639 |
} |
| 1640 |
|
| 1641 |
inline const std::string& dateTimeFormat(void) const { |
| 1642 |
return m_dateTimeFormat; |
| 1643 |
} |
| 1644 |
|
| 1645 |
inline base::type::EnumType flags(void) const { |
| 1646 |
return m_flags; |
| 1647 |
} |
| 1648 |
|
| 1649 |
inline bool hasFlag(base::FormatFlags flag) const { |
| 1650 |
return base::utils::hasFlag(flag, m_flags); |
| 1651 |
} |
| 1652 |
|
| 1653 |
virtual void log(el::base::type::ostream_t& os) const { |
| 1654 |
os << m_format; |
| 1655 |
} |
| 1656 |
|
| 1657 |
protected: |
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
virtual void updateDateFormat(std::size_t index, base::type::string_t& currFormat) ELPP_FINAL; |
| 1662 |
|
| 1663 |
|
| 1664 |
virtual void updateFormatSpec(void) ELPP_FINAL; |
| 1665 |
|
| 1666 |
inline void addFlag(base::FormatFlags flag) { |
| 1667 |
base::utils::addFlag(flag, &m_flags); |
| 1668 |
} |
| 1669 |
|
| 1670 |
private: |
| 1671 |
Level m_level; |
| 1672 |
base::type::string_t m_userFormat; |
| 1673 |
base::type::string_t m_format; |
| 1674 |
std::string m_dateTimeFormat; |
| 1675 |
base::type::EnumType m_flags; |
| 1676 |
std::string m_currentUser; |
| 1677 |
std::string m_currentHost; |
| 1678 |
friend class el::Logger; |
| 1679 |
}; |
| 1680 |
} |
| 1681 |
|
| 1682 |
typedef std::function<std::string(const LogMessage*)> FormatSpecifierValueResolver; |
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
class CustomFormatSpecifier { |
| 1687 |
public: |
| 1688 |
CustomFormatSpecifier(const char* formatSpecifier, const FormatSpecifierValueResolver& resolver) : |
| 1689 |
m_formatSpecifier(formatSpecifier), m_resolver(resolver) {} |
| 1690 |
inline const char* formatSpecifier(void) const { |
| 1691 |
return m_formatSpecifier; |
| 1692 |
} |
| 1693 |
inline const FormatSpecifierValueResolver& resolver(void) const { |
| 1694 |
return m_resolver; |
| 1695 |
} |
| 1696 |
inline bool operator==(const char* formatSpecifier) { |
| 1697 |
return strcmp(m_formatSpecifier, formatSpecifier) == 0; |
| 1698 |
} |
| 1699 |
|
| 1700 |
private: |
| 1701 |
const char* m_formatSpecifier; |
| 1702 |
FormatSpecifierValueResolver m_resolver; |
| 1703 |
}; |
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
class Configuration : public Loggable { |
| 1714 |
public: |
| 1715 |
Configuration(const Configuration& c); |
| 1716 |
Configuration& operator=(const Configuration& c); |
| 1717 |
|
| 1718 |
virtual ~Configuration(void) { |
| 1719 |
} |
| 1720 |
|
| 1721 |
|
| 1722 |
Configuration(Level level, ConfigurationType configurationType, const std::string& value); |
| 1723 |
|
| 1724 |
|
| 1725 |
inline Level level(void) const { |
| 1726 |
return m_level; |
| 1727 |
} |
| 1728 |
|
| 1729 |
|
| 1730 |
inline ConfigurationType configurationType(void) const { |
| 1731 |
return m_configurationType; |
| 1732 |
} |
| 1733 |
|
| 1734 |
|
| 1735 |
inline const std::string& value(void) const { |
| 1736 |
return m_value; |
| 1737 |
} |
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
inline void setValue(const std::string& value) { |
| 1743 |
m_value = value; |
| 1744 |
} |
| 1745 |
|
| 1746 |
virtual void log(el::base::type::ostream_t& os) const; |
| 1747 |
|
| 1748 |
|
| 1749 |
class Predicate { |
| 1750 |
public: |
| 1751 |
Predicate(Level level, ConfigurationType configurationType); |
| 1752 |
|
| 1753 |
bool operator()(const Configuration* conf) const; |
| 1754 |
|
| 1755 |
private: |
| 1756 |
Level m_level; |
| 1757 |
ConfigurationType m_configurationType; |
| 1758 |
}; |
| 1759 |
|
| 1760 |
private: |
| 1761 |
Level m_level; |
| 1762 |
ConfigurationType m_configurationType; |
| 1763 |
std::string m_value; |
| 1764 |
}; |
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
class Configurations : public base::utils::RegistryWithPred<Configuration, Configuration::Predicate> { |
| 1770 |
public: |
| 1771 |
|
| 1772 |
Configurations(void); |
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
Configurations(const std::string& configurationFile, bool useDefaultsForRemaining = true, |
| 1781 |
Configurations* base = nullptr); |
| 1782 |
|
| 1783 |
virtual ~Configurations(void) { |
| 1784 |
} |
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
bool parseFromFile(const std::string& configurationFile, Configurations* base = nullptr); |
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
bool parseFromText(const std::string& configurationsString, Configurations* base = nullptr); |
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
void setFromBase(Configurations* base); |
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
bool hasConfiguration(ConfigurationType configurationType); |
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
bool hasConfiguration(Level level, ConfigurationType configurationType); |
| 1818 |
|
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
void set(Level level, ConfigurationType configurationType, const std::string& value); |
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
void set(Configuration* conf); |
| 1836 |
|
| 1837 |
inline Configuration* get(Level level, ConfigurationType configurationType) { |
| 1838 |
base::threading::ScopedLock scopedLock(lock()); |
| 1839 |
return RegistryWithPred<Configuration, Configuration::Predicate>::get(level, configurationType); |
| 1840 |
} |
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
inline void setGlobally(ConfigurationType configurationType, const std::string& value) { |
| 1847 |
setGlobally(configurationType, value, false); |
| 1848 |
} |
| 1849 |
|
| 1850 |
|
| 1851 |
inline void clear(void) { |
| 1852 |
base::threading::ScopedLock scopedLock(lock()); |
| 1853 |
unregisterAll(); |
| 1854 |
} |
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
inline const std::string& configurationFile(void) const { |
| 1860 |
return m_configurationFile; |
| 1861 |
} |
| 1862 |
|
| 1863 |
|
| 1864 |
void setToDefault(void); |
| 1865 |
|
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
void setRemainingToDefault(void); |
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
class Parser : base::StaticClass { |
| 1880 |
public: |
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
static bool parseFromFile(const std::string& configurationFile, Configurations* sender, |
| 1889 |
Configurations* base = nullptr); |
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
static bool parseFromText(const std::string& configurationsString, Configurations* sender, |
| 1902 |
Configurations* base = nullptr); |
| 1903 |
|
| 1904 |
private: |
| 1905 |
friend class el::Loggers; |
| 1906 |
static void ignoreComments(std::string* line); |
| 1907 |
static bool isLevel(const std::string& line); |
| 1908 |
static bool isComment(const std::string& line); |
| 1909 |
static inline bool isConfig(const std::string& line); |
| 1910 |
static bool parseLine(std::string* line, std::string* currConfigStr, std::string* currLevelStr, Level* currLevel, |
| 1911 |
Configurations* conf); |
| 1912 |
}; |
| 1913 |
|
| 1914 |
private: |
| 1915 |
std::string m_configurationFile; |
| 1916 |
bool m_isFromFile; |
| 1917 |
friend class el::Loggers; |
| 1918 |
|
| 1919 |
|
| 1920 |
void unsafeSetIfNotExist(Level level, ConfigurationType configurationType, const std::string& value); |
| 1921 |
|
| 1922 |
|
| 1923 |
void unsafeSet(Level level, ConfigurationType configurationType, const std::string& value); |
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
void setGlobally(ConfigurationType configurationType, const std::string& value, bool includeGlobalLevel); |
| 1928 |
|
| 1929 |
|
| 1930 |
|
| 1931 |
void unsafeSetGlobally(ConfigurationType configurationType, const std::string& value, bool includeGlobalLevel); |
| 1932 |
}; |
| 1933 |
|
| 1934 |
namespace base { |
| 1935 |
typedef std::shared_ptr<base::type::fstream_t> FileStreamPtr; |
| 1936 |
typedef std::unordered_map<std::string, FileStreamPtr> LogStreamsReferenceMap; |
| 1937 |
|
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
class TypedConfigurations : public base::threading::ThreadSafe { |
| 1944 |
public: |
| 1945 |
|
| 1946 |
|
| 1947 |
|
| 1948 |
TypedConfigurations(Configurations* configurations, base::LogStreamsReferenceMap* logStreamsReference); |
| 1949 |
|
| 1950 |
TypedConfigurations(const TypedConfigurations& other); |
| 1951 |
|
| 1952 |
virtual ~TypedConfigurations(void) { |
| 1953 |
} |
| 1954 |
|
| 1955 |
const Configurations* configurations(void) const { |
| 1956 |
return m_configurations; |
| 1957 |
} |
| 1958 |
|
| 1959 |
bool enabled(Level level); |
| 1960 |
bool toFile(Level level); |
| 1961 |
const std::string& filename(Level level); |
| 1962 |
bool toStandardOutput(Level level); |
| 1963 |
const base::LogFormat& logFormat(Level level); |
| 1964 |
const base::SubsecondPrecision& subsecondPrecision(Level level = Level::Global); |
| 1965 |
const base::MillisecondsWidth& millisecondsWidth(Level level = Level::Global); |
| 1966 |
bool performanceTracking(Level level = Level::Global); |
| 1967 |
base::type::fstream_t* fileStream(Level level); |
| 1968 |
std::size_t maxLogFileSize(Level level); |
| 1969 |
std::size_t logFlushThreshold(Level level); |
| 1970 |
|
| 1971 |
private: |
| 1972 |
Configurations* m_configurations; |
| 1973 |
std::unordered_map<Level, bool> m_enabledMap; |
| 1974 |
std::unordered_map<Level, bool> m_toFileMap; |
| 1975 |
std::unordered_map<Level, std::string> m_filenameMap; |
| 1976 |
std::unordered_map<Level, bool> m_toStandardOutputMap; |
| 1977 |
std::unordered_map<Level, base::LogFormat> m_logFormatMap; |
| 1978 |
std::unordered_map<Level, base::SubsecondPrecision> m_subsecondPrecisionMap; |
| 1979 |
std::unordered_map<Level, bool> m_performanceTrackingMap; |
| 1980 |
std::unordered_map<Level, base::FileStreamPtr> m_fileStreamMap; |
| 1981 |
std::unordered_map<Level, std::size_t> m_maxLogFileSizeMap; |
| 1982 |
std::unordered_map<Level, std::size_t> m_logFlushThresholdMap; |
| 1983 |
base::LogStreamsReferenceMap* m_logStreamsReference; |
| 1984 |
|
| 1985 |
friend class el::Helpers; |
| 1986 |
friend class el::base::MessageBuilder; |
| 1987 |
friend class el::base::Writer; |
| 1988 |
friend class el::base::DefaultLogDispatchCallback; |
| 1989 |
friend class el::base::LogDispatcher; |
| 1990 |
|
| 1991 |
template <typename Conf_T> |
| 1992 |
inline Conf_T getConfigByVal(Level level, const std::unordered_map<Level, Conf_T>* confMap, const char* confName) { |
| 1993 |
base::threading::ScopedLock scopedLock(lock()); |
| 1994 |
return unsafeGetConfigByVal(level, confMap, confName); |
| 1995 |
} |
| 1996 |
|
| 1997 |
template <typename Conf_T> |
| 1998 |
inline Conf_T& getConfigByRef(Level level, std::unordered_map<Level, Conf_T>* confMap, const char* confName) { |
| 1999 |
base::threading::ScopedLock scopedLock(lock()); |
| 2000 |
return unsafeGetConfigByRef(level, confMap, confName); |
| 2001 |
} |
| 2002 |
|
| 2003 |
template <typename Conf_T> |
| 2004 |
Conf_T unsafeGetConfigByVal(Level level, const std::unordered_map<Level, Conf_T>* confMap, const char* confName) { |
| 2005 |
ELPP_UNUSED(confName); |
| 2006 |
typename std::unordered_map<Level, Conf_T>::const_iterator it = confMap->find(level); |
| 2007 |
if (it == confMap->end()) { |
| 2008 |
try { |
| 2009 |
return confMap->at(Level::Global); |
| 2010 |
} catch (...) { |
| 2011 |
ELPP_INTERNAL_ERROR("Unable to get configuration [" << confName << "] for level [" |
| 2012 |
<< LevelHelper::convertToString(level) << "]" |
| 2013 |
<< std::endl << "Please ensure you have properly configured logger.", false); |
| 2014 |
return Conf_T(); |
| 2015 |
} |
| 2016 |
} |
| 2017 |
return it->second; |
| 2018 |
} |
| 2019 |
|
| 2020 |
template <typename Conf_T> |
| 2021 |
Conf_T& unsafeGetConfigByRef(Level level, std::unordered_map<Level, Conf_T>* confMap, const char* confName) { |
| 2022 |
ELPP_UNUSED(confName); |
| 2023 |
typename std::unordered_map<Level, Conf_T>::iterator it = confMap->find(level); |
| 2024 |
if (it == confMap->end()) { |
| 2025 |
try { |
| 2026 |
return confMap->at(Level::Global); |
| 2027 |
} catch (...) { |
| 2028 |
ELPP_INTERNAL_ERROR("Unable to get configuration [" << confName << "] for level [" |
| 2029 |
<< LevelHelper::convertToString(level) << "]" |
| 2030 |
<< std::endl << "Please ensure you have properly configured logger.", false); |
| 2031 |
throw; |
| 2032 |
} |
| 2033 |
} |
| 2034 |
return it->second; |
| 2035 |
} |
| 2036 |
|
| 2037 |
template <typename Conf_T> |
| 2038 |
void setValue(Level level, const Conf_T& value, std::unordered_map<Level, Conf_T>* confMap, |
| 2039 |
bool includeGlobalLevel = true) { |
| 2040 |
|
| 2041 |
if (confMap->empty() && includeGlobalLevel) { |
| 2042 |
confMap->insert(std::make_pair(Level::Global, value)); |
| 2043 |
return; |
| 2044 |
} |
| 2045 |
|
| 2046 |
typename std::unordered_map<Level, Conf_T>::iterator it = confMap->find(Level::Global); |
| 2047 |
if (it != confMap->end() && it->second == value) { |
| 2048 |
return; |
| 2049 |
} |
| 2050 |
|
| 2051 |
it = confMap->find(level); |
| 2052 |
if (it == confMap->end()) { |
| 2053 |
|
| 2054 |
confMap->insert(std::make_pair(level, value)); |
| 2055 |
} else { |
| 2056 |
|
| 2057 |
confMap->at(level) = value; |
| 2058 |
} |
| 2059 |
} |
| 2060 |
|
| 2061 |
void build(Configurations* configurations); |
| 2062 |
unsigned long getULong(std::string confVal); |
| 2063 |
std::string resolveFilename(const std::string& filename); |
| 2064 |
void insertFile(Level level, const std::string& fullFilename); |
| 2065 |
bool unsafeValidateFileRolling(Level level, const PreRollOutCallback& preRollOutCallback); |
| 2066 |
|
| 2067 |
inline bool validateFileRolling(Level level, const PreRollOutCallback& preRollOutCallback) { |
| 2068 |
base::threading::ScopedLock scopedLock(lock()); |
| 2069 |
return unsafeValidateFileRolling(level, preRollOutCallback); |
| 2070 |
} |
| 2071 |
}; |
| 2072 |
|
| 2073 |
class HitCounter { |
| 2074 |
public: |
| 2075 |
HitCounter(void) : |
| 2076 |
m_filename(""), |
| 2077 |
m_lineNumber(0), |
| 2078 |
m_hitCounts(0) { |
| 2079 |
} |
| 2080 |
|
| 2081 |
HitCounter(const char* filename, base::type::LineNumber lineNumber) : |
| 2082 |
m_filename(filename), |
| 2083 |
m_lineNumber(lineNumber), |
| 2084 |
m_hitCounts(0) { |
| 2085 |
} |
| 2086 |
|
| 2087 |
HitCounter(const HitCounter& hitCounter) : |
| 2088 |
m_filename(hitCounter.m_filename), |
| 2089 |
m_lineNumber(hitCounter.m_lineNumber), |
| 2090 |
m_hitCounts(hitCounter.m_hitCounts) { |
| 2091 |
} |
| 2092 |
|
| 2093 |
HitCounter& operator=(const HitCounter& hitCounter) { |
| 2094 |
if (&hitCounter != this) { |
| 2095 |
m_filename = hitCounter.m_filename; |
| 2096 |
m_lineNumber = hitCounter.m_lineNumber; |
| 2097 |
m_hitCounts = hitCounter.m_hitCounts; |
| 2098 |
} |
| 2099 |
return *this; |
| 2100 |
} |
| 2101 |
|
| 2102 |
virtual ~HitCounter(void) { |
| 2103 |
} |
| 2104 |
|
| 2105 |
|
| 2106 |
inline void resetLocation(const char* filename, base::type::LineNumber lineNumber) { |
| 2107 |
m_filename = filename; |
| 2108 |
m_lineNumber = lineNumber; |
| 2109 |
} |
| 2110 |
|
| 2111 |
|
| 2112 |
inline void validateHitCounts(std::size_t n) { |
| 2113 |
if (m_hitCounts >= base::consts::kMaxLogPerCounter) { |
| 2114 |
m_hitCounts = (n >= 1 ? base::consts::kMaxLogPerCounter % n : 0); |
| 2115 |
} |
| 2116 |
++m_hitCounts; |
| 2117 |
} |
| 2118 |
|
| 2119 |
inline const char* filename(void) const { |
| 2120 |
return m_filename; |
| 2121 |
} |
| 2122 |
|
| 2123 |
inline base::type::LineNumber lineNumber(void) const { |
| 2124 |
return m_lineNumber; |
| 2125 |
} |
| 2126 |
|
| 2127 |
inline std::size_t hitCounts(void) const { |
| 2128 |
return m_hitCounts; |
| 2129 |
} |
| 2130 |
|
| 2131 |
inline void increment(void) { |
| 2132 |
++m_hitCounts; |
| 2133 |
} |
| 2134 |
|
| 2135 |
class Predicate { |
| 2136 |
public: |
| 2137 |
Predicate(const char* filename, base::type::LineNumber lineNumber) |
| 2138 |
: m_filename(filename), |
| 2139 |
m_lineNumber(lineNumber) { |
| 2140 |
} |
| 2141 |
inline bool operator()(const HitCounter* counter) { |
| 2142 |
return ((counter != nullptr) && |
| 2143 |
(strcmp(counter->m_filename, m_filename) == 0) && |
| 2144 |
(counter->m_lineNumber == m_lineNumber)); |
| 2145 |
} |
| 2146 |
|
| 2147 |
private: |
| 2148 |
const char* m_filename; |
| 2149 |
base::type::LineNumber m_lineNumber; |
| 2150 |
}; |
| 2151 |
|
| 2152 |
private: |
| 2153 |
const char* m_filename; |
| 2154 |
base::type::LineNumber m_lineNumber; |
| 2155 |
std::size_t m_hitCounts; |
| 2156 |
}; |
| 2157 |
|
| 2158 |
class RegisteredHitCounters : public base::utils::RegistryWithPred<base::HitCounter, base::HitCounter::Predicate> { |
| 2159 |
public: |
| 2160 |
|
| 2161 |
|
| 2162 |
bool validateEveryN(const char* filename, base::type::LineNumber lineNumber, std::size_t n); |
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
bool validateAfterN(const char* filename, base::type::LineNumber lineNumber, std::size_t n); |
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
bool validateNTimes(const char* filename, base::type::LineNumber lineNumber, std::size_t n); |
| 2171 |
|
| 2172 |
|
| 2173 |
inline const base::HitCounter* getCounter(const char* filename, base::type::LineNumber lineNumber) { |
| 2174 |
base::threading::ScopedLock scopedLock(lock()); |
| 2175 |
return get(filename, lineNumber); |
| 2176 |
} |
| 2177 |
}; |
| 2178 |
|
| 2179 |
enum class DispatchAction : base::type::EnumType { |
| 2180 |
None = 1, NormalLog = 2, SysLog = 4, FileOnlyLog = 8, |
| 2181 |
}; |
| 2182 |
} |
| 2183 |
template <typename T> |
| 2184 |
class Callback : protected base::threading::ThreadSafe { |
| 2185 |
public: |
| 2186 |
Callback(void) : m_enabled(true) {} |
| 2187 |
inline bool enabled(void) const { |
| 2188 |
return m_enabled; |
| 2189 |
} |
| 2190 |
inline void setEnabled(bool enabled) { |
| 2191 |
base::threading::ScopedLock scopedLock(lock()); |
| 2192 |
m_enabled = enabled; |
| 2193 |
} |
| 2194 |
protected: |
| 2195 |
virtual void handle(const T* handlePtr) = 0; |
| 2196 |
private: |
| 2197 |
bool m_enabled; |
| 2198 |
}; |
| 2199 |
class LogDispatchData { |
| 2200 |
public: |
| 2201 |
LogDispatchData() : m_logMessage(nullptr), m_dispatchAction(base::DispatchAction::None) {} |
| 2202 |
inline const LogMessage* logMessage(void) const { |
| 2203 |
return m_logMessage; |
| 2204 |
} |
| 2205 |
inline base::DispatchAction dispatchAction(void) const { |
| 2206 |
return m_dispatchAction; |
| 2207 |
} |
| 2208 |
inline void setLogMessage(LogMessage* logMessage) { |
| 2209 |
m_logMessage = logMessage; |
| 2210 |
} |
| 2211 |
inline void setDispatchAction(base::DispatchAction dispatchAction) { |
| 2212 |
m_dispatchAction = dispatchAction; |
| 2213 |
} |
| 2214 |
private: |
| 2215 |
LogMessage* m_logMessage; |
| 2216 |
base::DispatchAction m_dispatchAction; |
| 2217 |
friend class base::LogDispatcher; |
| 2218 |
|
| 2219 |
}; |
| 2220 |
class LogDispatchCallback : public Callback<LogDispatchData> { |
| 2221 |
protected: |
| 2222 |
virtual void handle(const LogDispatchData* data); |
| 2223 |
base::threading::Mutex& fileHandle(const LogDispatchData* data); |
| 2224 |
private: |
| 2225 |
friend class base::LogDispatcher; |
| 2226 |
std::unordered_map<std::string, std::unique_ptr<base::threading::Mutex>> m_fileLocks; |
| 2227 |
base::threading::Mutex m_fileLocksMapLock; |
| 2228 |
}; |
| 2229 |
class PerformanceTrackingCallback : public Callback<PerformanceTrackingData> { |
| 2230 |
private: |
| 2231 |
friend class base::PerformanceTracker; |
| 2232 |
}; |
| 2233 |
class LoggerRegistrationCallback : public Callback<Logger> { |
| 2234 |
private: |
| 2235 |
friend class base::RegisteredLoggers; |
| 2236 |
}; |
| 2237 |
class LogBuilder : base::NoCopy { |
| 2238 |
public: |
| 2239 |
LogBuilder() : m_termSupportsColor(base::utils::OS::termSupportsColor()) {} |
| 2240 |
virtual ~LogBuilder(void) { |
| 2241 |
ELPP_INTERNAL_INFO(3, "Destroying log builder...") |
| 2242 |
} |
| 2243 |
virtual base::type::string_t build(const LogMessage* logMessage, bool appendNewLine) const = 0; |
| 2244 |
void convertToColoredOutput(base::type::string_t* logLine, Level level, Color color); |
| 2245 |
void setColor(Color color, bool bright); |
| 2246 |
private: |
| 2247 |
bool m_termSupportsColor; |
| 2248 |
friend class el::base::DefaultLogDispatchCallback; |
| 2249 |
}; |
| 2250 |
typedef std::shared_ptr<LogBuilder> LogBuilderPtr; |
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
class Logger : public base::threading::ThreadSafe, public Loggable { |
| 2255 |
public: |
| 2256 |
Logger(const std::string& id, base::LogStreamsReferenceMap* logStreamsReference); |
| 2257 |
Logger(const std::string& id, const Configurations& configurations, base::LogStreamsReferenceMap* logStreamsReference); |
| 2258 |
Logger(const Logger& logger); |
| 2259 |
Logger& operator=(const Logger& logger); |
| 2260 |
|
| 2261 |
virtual ~Logger(void) { |
| 2262 |
base::utils::safeDelete(m_typedConfigurations); |
| 2263 |
} |
| 2264 |
|
| 2265 |
virtual inline void log(el::base::type::ostream_t& os) const { |
| 2266 |
os << m_id.c_str(); |
| 2267 |
} |
| 2268 |
|
| 2269 |
|
| 2270 |
void configure(const Configurations& configurations); |
| 2271 |
|
| 2272 |
|
| 2273 |
void reconfigure(void); |
| 2274 |
|
| 2275 |
inline const std::string& id(void) const { |
| 2276 |
return m_id; |
| 2277 |
} |
| 2278 |
|
| 2279 |
inline const std::string& parentApplicationName(void) const { |
| 2280 |
return m_parentApplicationName; |
| 2281 |
} |
| 2282 |
|
| 2283 |
inline void setParentApplicationName(const std::string& parentApplicationName) { |
| 2284 |
m_parentApplicationName = parentApplicationName; |
| 2285 |
} |
| 2286 |
|
| 2287 |
inline Configurations* configurations(void) { |
| 2288 |
return &m_configurations; |
| 2289 |
} |
| 2290 |
|
| 2291 |
inline base::TypedConfigurations* typedConfigurations(void) { |
| 2292 |
return m_typedConfigurations; |
| 2293 |
} |
| 2294 |
|
| 2295 |
static bool isValidId(const std::string& id); |
| 2296 |
|
| 2297 |
|
| 2298 |
void flush(void); |
| 2299 |
|
| 2300 |
void flush(Level level, base::type::fstream_t* fs); |
| 2301 |
|
| 2302 |
inline bool isFlushNeeded(Level level) { |
| 2303 |
return ++m_unflushedCount.find(level)->second >= m_typedConfigurations->logFlushThreshold(level); |
| 2304 |
} |
| 2305 |
|
| 2306 |
inline LogBuilder* logBuilder(void) const { |
| 2307 |
return m_logBuilder.get(); |
| 2308 |
} |
| 2309 |
|
| 2310 |
inline void setLogBuilder(const LogBuilderPtr& logBuilder) { |
| 2311 |
m_logBuilder = logBuilder; |
| 2312 |
} |
| 2313 |
|
| 2314 |
inline bool enabled(Level level) const { |
| 2315 |
return m_typedConfigurations->enabled(level); |
| 2316 |
} |
| 2317 |
|
| 2318 |
#if ELPP_VARIADIC_TEMPLATES_SUPPORTED |
| 2319 |
# define LOGGER_LEVEL_WRITERS_SIGNATURES(FUNCTION_NAME)\ |
| 2320 |
template <typename T, typename... Args>\ |
| 2321 |
inline void FUNCTION_NAME(const char*, const T&, const Args&...);\ |
| 2322 |
template <typename T>\ |
| 2323 |
inline void FUNCTION_NAME(const T&); |
| 2324 |
|
| 2325 |
template <typename T, typename... Args> |
| 2326 |
inline void verbose(int, const char*, const T&, const Args&...); |
| 2327 |
|
| 2328 |
template <typename T> |
| 2329 |
inline void verbose(int, const T&); |
| 2330 |
|
| 2331 |
LOGGER_LEVEL_WRITERS_SIGNATURES(info) |
| 2332 |
LOGGER_LEVEL_WRITERS_SIGNATURES(debug) |
| 2333 |
LOGGER_LEVEL_WRITERS_SIGNATURES(warn) |
| 2334 |
LOGGER_LEVEL_WRITERS_SIGNATURES(error) |
| 2335 |
LOGGER_LEVEL_WRITERS_SIGNATURES(fatal) |
| 2336 |
LOGGER_LEVEL_WRITERS_SIGNATURES(trace) |
| 2337 |
# undef LOGGER_LEVEL_WRITERS_SIGNATURES |
| 2338 |
#endif |
| 2339 |
private: |
| 2340 |
std::string m_id; |
| 2341 |
base::TypedConfigurations* m_typedConfigurations; |
| 2342 |
base::type::stringstream_t m_stream; |
| 2343 |
std::string m_parentApplicationName; |
| 2344 |
bool m_isConfigured; |
| 2345 |
Configurations m_configurations; |
| 2346 |
std::unordered_map<Level, unsigned int> m_unflushedCount; |
| 2347 |
base::LogStreamsReferenceMap* m_logStreamsReference; |
| 2348 |
LogBuilderPtr m_logBuilder; |
| 2349 |
|
| 2350 |
friend class el::LogMessage; |
| 2351 |
friend class el::Loggers; |
| 2352 |
friend class el::Helpers; |
| 2353 |
friend class el::base::RegisteredLoggers; |
| 2354 |
friend class el::base::DefaultLogDispatchCallback; |
| 2355 |
friend class el::base::MessageBuilder; |
| 2356 |
friend class el::base::Writer; |
| 2357 |
friend class el::base::PErrorWriter; |
| 2358 |
friend class el::base::Storage; |
| 2359 |
friend class el::base::PerformanceTracker; |
| 2360 |
friend class el::base::LogDispatcher; |
| 2361 |
|
| 2362 |
Logger(void); |
| 2363 |
|
| 2364 |
#if ELPP_VARIADIC_TEMPLATES_SUPPORTED |
| 2365 |
template <typename T, typename... Args> |
| 2366 |
void log_(Level, int, const char*, const T&, const Args&...); |
| 2367 |
|
| 2368 |
template <typename T> |
| 2369 |
inline void log_(Level, int, const T&); |
| 2370 |
|
| 2371 |
template <typename T, typename... Args> |
| 2372 |
void log(Level, const char*, const T&, const Args&...); |
| 2373 |
|
| 2374 |
template <typename T> |
| 2375 |
inline void log(Level, const T&); |
| 2376 |
#endif |
| 2377 |
|
| 2378 |
void initUnflushedCount(void); |
| 2379 |
|
| 2380 |
inline base::type::stringstream_t& stream(void) { |
| 2381 |
return m_stream; |
| 2382 |
} |
| 2383 |
|
| 2384 |
void resolveLoggerFormatSpec(void) const; |
| 2385 |
}; |
| 2386 |
namespace base { |
| 2387 |
|
| 2388 |
class RegisteredLoggers : public base::utils::Registry<Logger, std::string> { |
| 2389 |
public: |
| 2390 |
explicit RegisteredLoggers(const LogBuilderPtr& defaultLogBuilder); |
| 2391 |
|
| 2392 |
virtual ~RegisteredLoggers(void) { |
| 2393 |
unsafeFlushAll(); |
| 2394 |
} |
| 2395 |
|
| 2396 |
inline void setDefaultConfigurations(const Configurations& configurations) { |
| 2397 |
base::threading::ScopedLock scopedLock(lock()); |
| 2398 |
m_defaultConfigurations.setFromBase(const_cast<Configurations*>(&configurations)); |
| 2399 |
} |
| 2400 |
|
| 2401 |
inline Configurations* defaultConfigurations(void) { |
| 2402 |
return &m_defaultConfigurations; |
| 2403 |
} |
| 2404 |
|
| 2405 |
Logger* get(const std::string& id, bool forceCreation = true); |
| 2406 |
|
| 2407 |
template <typename T> |
| 2408 |
inline bool installLoggerRegistrationCallback(const std::string& id) { |
| 2409 |
return base::utils::Utils::installCallback<T, base::type::LoggerRegistrationCallbackPtr>(id, |
| 2410 |
&m_loggerRegistrationCallbacks); |
| 2411 |
} |
| 2412 |
|
| 2413 |
template <typename T> |
| 2414 |
inline void uninstallLoggerRegistrationCallback(const std::string& id) { |
| 2415 |
base::utils::Utils::uninstallCallback<T, base::type::LoggerRegistrationCallbackPtr>(id, &m_loggerRegistrationCallbacks); |
| 2416 |
} |
| 2417 |
|
| 2418 |
template <typename T> |
| 2419 |
inline T* loggerRegistrationCallback(const std::string& id) { |
| 2420 |
return base::utils::Utils::callback<T, base::type::LoggerRegistrationCallbackPtr>(id, &m_loggerRegistrationCallbacks); |
| 2421 |
} |
| 2422 |
|
| 2423 |
bool remove(const std::string& id); |
| 2424 |
|
| 2425 |
inline bool has(const std::string& id) { |
| 2426 |
return get(id, false) != nullptr; |
| 2427 |
} |
| 2428 |
|
| 2429 |
inline void unregister(Logger*& logger) { |
| 2430 |
base::threading::ScopedLock scopedLock(lock()); |
| 2431 |
base::utils::Registry<Logger, std::string>::unregister(logger->id()); |
| 2432 |
} |
| 2433 |
|
| 2434 |
inline base::LogStreamsReferenceMap* logStreamsReference(void) { |
| 2435 |
return &m_logStreamsReference; |
| 2436 |
} |
| 2437 |
|
| 2438 |
inline void flushAll(void) { |
| 2439 |
base::threading::ScopedLock scopedLock(lock()); |
| 2440 |
unsafeFlushAll(); |
| 2441 |
} |
| 2442 |
|
| 2443 |
inline void setDefaultLogBuilder(LogBuilderPtr& logBuilderPtr) { |
| 2444 |
base::threading::ScopedLock scopedLock(lock()); |
| 2445 |
m_defaultLogBuilder = logBuilderPtr; |
| 2446 |
} |
| 2447 |
|
| 2448 |
private: |
| 2449 |
LogBuilderPtr m_defaultLogBuilder; |
| 2450 |
Configurations m_defaultConfigurations; |
| 2451 |
base::LogStreamsReferenceMap m_logStreamsReference; |
| 2452 |
std::unordered_map<std::string, base::type::LoggerRegistrationCallbackPtr> m_loggerRegistrationCallbacks; |
| 2453 |
friend class el::base::Storage; |
| 2454 |
|
| 2455 |
void unsafeFlushAll(void); |
| 2456 |
}; |
| 2457 |
|
| 2458 |
class VRegistry : base::NoCopy, public base::threading::ThreadSafe { |
| 2459 |
public: |
| 2460 |
explicit VRegistry(base::type::VerboseLevel level, base::type::EnumType* pFlags); |
| 2461 |
|
| 2462 |
|
| 2463 |
void setLevel(base::type::VerboseLevel level); |
| 2464 |
|
| 2465 |
inline base::type::VerboseLevel level(void) const { |
| 2466 |
return m_level; |
| 2467 |
} |
| 2468 |
|
| 2469 |
void clearCategories(void); |
| 2470 |
|
| 2471 |
inline void clearModules(void) { |
| 2472 |
base::threading::ScopedLock scopedLock(lock()); |
| 2473 |
m_modules.clear(); |
| 2474 |
} |
| 2475 |
|
| 2476 |
void setCategories(const char* categories, bool clear = true); |
| 2477 |
|
| 2478 |
std::string getCategories(); |
| 2479 |
|
| 2480 |
void setModules(const char* modules); |
| 2481 |
|
| 2482 |
bool priority_allowed(int priority, const std::string &category); |
| 2483 |
bool allowed(Level level, const std::string &category); |
| 2484 |
|
| 2485 |
bool allowed(base::type::VerboseLevel vlevel, const char* file); |
| 2486 |
|
| 2487 |
inline const std::unordered_map<std::string, base::type::VerboseLevel>& modules(void) const { |
| 2488 |
return m_modules; |
| 2489 |
} |
| 2490 |
|
| 2491 |
void setFromArgs(const base::utils::CommandLineArgs* commandLineArgs); |
| 2492 |
|
| 2493 |
|
| 2494 |
inline bool vModulesEnabled(void) { |
| 2495 |
return !base::utils::hasFlag(LoggingFlag::DisableVModules, *m_pFlags); |
| 2496 |
} |
| 2497 |
|
| 2498 |
inline void setFilenameCommonPrefix(const std::string &prefix) { |
| 2499 |
m_filenameCommonPrefix = prefix; |
| 2500 |
} |
| 2501 |
|
| 2502 |
inline const std::string &getFilenameCommonPrefix() const { |
| 2503 |
return m_filenameCommonPrefix; |
| 2504 |
} |
| 2505 |
|
| 2506 |
private: |
| 2507 |
base::type::VerboseLevel m_level; |
| 2508 |
base::type::EnumType* m_pFlags; |
| 2509 |
std::unordered_map<std::string, base::type::VerboseLevel> m_modules; |
| 2510 |
std::vector<std::pair<std::string, Level>> m_categories; |
| 2511 |
std::map<std::string, int> m_cached_allowed_categories; |
| 2512 |
std::string m_categoriesString; |
| 2513 |
std::string m_filenameCommonPrefix; |
| 2514 |
}; |
| 2515 |
} |
| 2516 |
class LogMessage { |
| 2517 |
public: |
| 2518 |
LogMessage(Level level, Color color, const std::string& file, base::type::LineNumber line, const std::string& func, |
| 2519 |
base::type::VerboseLevel verboseLevel, Logger* logger, const base::type::string_t *msg = nullptr) : |
| 2520 |
m_level(level), m_color(color), m_file(file), m_line(line), m_func(func), |
| 2521 |
m_verboseLevel(verboseLevel), m_logger(logger), m_message(msg ? *msg : logger->stream().str()) { |
| 2522 |
} |
| 2523 |
inline Level level(void) const { |
| 2524 |
return m_level; |
| 2525 |
} |
| 2526 |
inline Color color(void) const { |
| 2527 |
return m_color; |
| 2528 |
} |
| 2529 |
inline const std::string& file(void) const { |
| 2530 |
return m_file; |
| 2531 |
} |
| 2532 |
inline base::type::LineNumber line(void) const { |
| 2533 |
return m_line; |
| 2534 |
} |
| 2535 |
inline const std::string& func(void) const { |
| 2536 |
return m_func; |
| 2537 |
} |
| 2538 |
inline base::type::VerboseLevel verboseLevel(void) const { |
| 2539 |
return m_verboseLevel; |
| 2540 |
} |
| 2541 |
inline Logger* logger(void) const { |
| 2542 |
return m_logger; |
| 2543 |
} |
| 2544 |
inline const base::type::string_t& message(void) const { |
| 2545 |
return m_message; |
| 2546 |
} |
| 2547 |
private: |
| 2548 |
Level m_level; |
| 2549 |
Color m_color; |
| 2550 |
std::string m_file; |
| 2551 |
base::type::LineNumber m_line; |
| 2552 |
std::string m_func; |
| 2553 |
base::type::VerboseLevel m_verboseLevel; |
| 2554 |
Logger* m_logger; |
| 2555 |
base::type::string_t m_message; |
| 2556 |
}; |
| 2557 |
namespace base { |
| 2558 |
#if ELPP_ASYNC_LOGGING |
| 2559 |
class AsyncLogItem { |
| 2560 |
public: |
| 2561 |
explicit AsyncLogItem(const LogMessage& logMessage, const LogDispatchData& data, const base::type::string_t& logLine) |
| 2562 |
: m_logMessage(logMessage), m_dispatchData(data), m_logLine(logLine) {} |
| 2563 |
virtual ~AsyncLogItem() {} |
| 2564 |
inline LogMessage* logMessage(void) { |
| 2565 |
return &m_logMessage; |
| 2566 |
} |
| 2567 |
inline LogDispatchData* data(void) { |
| 2568 |
return &m_dispatchData; |
| 2569 |
} |
| 2570 |
inline base::type::string_t logLine(void) { |
| 2571 |
return m_logLine; |
| 2572 |
} |
| 2573 |
private: |
| 2574 |
LogMessage m_logMessage; |
| 2575 |
LogDispatchData m_dispatchData; |
| 2576 |
base::type::string_t m_logLine; |
| 2577 |
}; |
| 2578 |
class AsyncLogQueue : public base::threading::ThreadSafe { |
| 2579 |
public: |
| 2580 |
virtual ~AsyncLogQueue() { |
| 2581 |
ELPP_INTERNAL_INFO(6, "~AsyncLogQueue"); |
| 2582 |
} |
| 2583 |
|
| 2584 |
inline AsyncLogItem next(void) { |
| 2585 |
base::threading::ScopedLock scopedLock(lock()); |
| 2586 |
AsyncLogItem result = m_queue.front(); |
| 2587 |
m_queue.pop(); |
| 2588 |
return result; |
| 2589 |
} |
| 2590 |
|
| 2591 |
inline void push(const AsyncLogItem& item) { |
| 2592 |
base::threading::ScopedLock scopedLock(lock()); |
| 2593 |
m_queue.push(item); |
| 2594 |
} |
| 2595 |
inline void pop(void) { |
| 2596 |
base::threading::ScopedLock scopedLock(lock()); |
| 2597 |
m_queue.pop(); |
| 2598 |
} |
| 2599 |
inline AsyncLogItem front(void) { |
| 2600 |
base::threading::ScopedLock scopedLock(lock()); |
| 2601 |
return m_queue.front(); |
| 2602 |
} |
| 2603 |
inline bool empty(void) { |
| 2604 |
base::threading::ScopedLock scopedLock(lock()); |
| 2605 |
return m_queue.empty(); |
| 2606 |
} |
| 2607 |
private: |
| 2608 |
std::queue<AsyncLogItem> m_queue; |
| 2609 |
}; |
| 2610 |
class IWorker { |
| 2611 |
public: |
| 2612 |
virtual ~IWorker() {} |
| 2613 |
virtual void start() = 0; |
| 2614 |
}; |
| 2615 |
#endif |
| 2616 |
|
| 2617 |
class Storage : base::NoCopy, public base::threading::ThreadSafe { |
| 2618 |
public: |
| 2619 |
#if ELPP_ASYNC_LOGGING |
| 2620 |
Storage(const LogBuilderPtr& defaultLogBuilder, base::IWorker* asyncDispatchWorker); |
| 2621 |
#else |
| 2622 |
explicit Storage(const LogBuilderPtr& defaultLogBuilder); |
| 2623 |
#endif |
| 2624 |
|
| 2625 |
virtual ~Storage(void); |
| 2626 |
|
| 2627 |
inline bool validateEveryNCounter(const char* filename, base::type::LineNumber lineNumber, std::size_t occasion) { |
| 2628 |
return hitCounters()->validateEveryN(filename, lineNumber, occasion); |
| 2629 |
} |
| 2630 |
|
| 2631 |
inline bool validateAfterNCounter(const char* filename, base::type::LineNumber lineNumber, std::size_t n) { |
| 2632 |
return hitCounters()->validateAfterN(filename, lineNumber, n); |
| 2633 |
} |
| 2634 |
|
| 2635 |
inline bool validateNTimesCounter(const char* filename, base::type::LineNumber lineNumber, std::size_t n) { |
| 2636 |
return hitCounters()->validateNTimes(filename, lineNumber, n); |
| 2637 |
} |
| 2638 |
|
| 2639 |
inline base::RegisteredHitCounters* hitCounters(void) const { |
| 2640 |
return m_registeredHitCounters; |
| 2641 |
} |
| 2642 |
|
| 2643 |
inline base::RegisteredLoggers* registeredLoggers(void) const { |
| 2644 |
return m_registeredLoggers; |
| 2645 |
} |
| 2646 |
|
| 2647 |
inline base::VRegistry* vRegistry(void) const { |
| 2648 |
return m_vRegistry; |
| 2649 |
} |
| 2650 |
|
| 2651 |
#if ELPP_ASYNC_LOGGING |
| 2652 |
inline base::AsyncLogQueue* asyncLogQueue(void) const { |
| 2653 |
return m_asyncLogQueue; |
| 2654 |
} |
| 2655 |
#endif |
| 2656 |
|
| 2657 |
inline const base::utils::CommandLineArgs* commandLineArgs(void) const { |
| 2658 |
return &m_commandLineArgs; |
| 2659 |
} |
| 2660 |
|
| 2661 |
inline void addFlag(LoggingFlag flag) { |
| 2662 |
base::utils::addFlag(flag, &m_flags); |
| 2663 |
} |
| 2664 |
|
| 2665 |
inline void removeFlag(LoggingFlag flag) { |
| 2666 |
base::utils::removeFlag(flag, &m_flags); |
| 2667 |
} |
| 2668 |
|
| 2669 |
inline bool hasFlag(LoggingFlag flag) const { |
| 2670 |
return base::utils::hasFlag(flag, m_flags); |
| 2671 |
} |
| 2672 |
|
| 2673 |
inline base::type::EnumType flags(void) const { |
| 2674 |
return m_flags; |
| 2675 |
} |
| 2676 |
|
| 2677 |
inline void setFlags(base::type::EnumType flags) { |
| 2678 |
m_flags = flags; |
| 2679 |
} |
| 2680 |
|
| 2681 |
inline void setPreRollOutCallback(const PreRollOutCallback& callback) { |
| 2682 |
m_preRollOutCallback = callback; |
| 2683 |
} |
| 2684 |
|
| 2685 |
inline void unsetPreRollOutCallback(void) { |
| 2686 |
m_preRollOutCallback = base::defaultPreRollOutCallback; |
| 2687 |
} |
| 2688 |
|
| 2689 |
inline PreRollOutCallback& preRollOutCallback(void) { |
| 2690 |
return m_preRollOutCallback; |
| 2691 |
} |
| 2692 |
|
| 2693 |
bool hasCustomFormatSpecifier(const char* formatSpecifier); |
| 2694 |
void installCustomFormatSpecifier(const CustomFormatSpecifier& customFormatSpecifier); |
| 2695 |
bool uninstallCustomFormatSpecifier(const char* formatSpecifier); |
| 2696 |
|
| 2697 |
const std::vector<CustomFormatSpecifier>* customFormatSpecifiers(void) const { |
| 2698 |
return &m_customFormatSpecifiers; |
| 2699 |
} |
| 2700 |
|
| 2701 |
base::threading::Mutex& customFormatSpecifiersLock() { |
| 2702 |
return m_customFormatSpecifiersLock; |
| 2703 |
} |
| 2704 |
|
| 2705 |
inline void setLoggingLevel(Level level) { |
| 2706 |
m_loggingLevel = level; |
| 2707 |
} |
| 2708 |
|
| 2709 |
template <typename T> |
| 2710 |
inline bool installLogDispatchCallback(const std::string& id) { |
| 2711 |
return base::utils::Utils::installCallback<T, base::type::LogDispatchCallbackPtr>(id, &m_logDispatchCallbacks); |
| 2712 |
} |
| 2713 |
|
| 2714 |
template <typename T> |
| 2715 |
inline void uninstallLogDispatchCallback(const std::string& id) { |
| 2716 |
base::utils::Utils::uninstallCallback<T, base::type::LogDispatchCallbackPtr>(id, &m_logDispatchCallbacks); |
| 2717 |
} |
| 2718 |
template <typename T> |
| 2719 |
inline T* logDispatchCallback(const std::string& id) { |
| 2720 |
return base::utils::Utils::callback<T, base::type::LogDispatchCallbackPtr>(id, &m_logDispatchCallbacks); |
| 2721 |
} |
| 2722 |
|
| 2723 |
#if defined(ELPP_FEATURE_ALL) || defined(ELPP_FEATURE_PERFORMANCE_TRACKING) |
| 2724 |
template <typename T> |
| 2725 |
inline bool installPerformanceTrackingCallback(const std::string& id) { |
| 2726 |
return base::utils::Utils::installCallback<T, base::type::PerformanceTrackingCallbackPtr>(id, |
| 2727 |
&m_performanceTrackingCallbacks); |
| 2728 |
} |
| 2729 |
|
| 2730 |
template <typename T> |
| 2731 |
inline void uninstallPerformanceTrackingCallback(const std::string& id) { |
| 2732 |
base::utils::Utils::uninstallCallback<T, base::type::PerformanceTrackingCallbackPtr>(id, |
| 2733 |
&m_performanceTrackingCallbacks); |
| 2734 |
} |
| 2735 |
|
| 2736 |
template <typename T> |
| 2737 |
inline T* performanceTrackingCallback(const std::string& id) { |
| 2738 |
return base::utils::Utils::callback<T, base::type::PerformanceTrackingCallbackPtr>(id, &m_performanceTrackingCallbacks); |
| 2739 |
} |
| 2740 |
#endif |
| 2741 |
|
| 2742 |
|
| 2743 |
inline void setThreadName(const std::string& name) { |
| 2744 |
if (name.empty()) return; |
| 2745 |
base::threading::ScopedLock scopedLock(m_threadNamesLock); |
| 2746 |
m_threadNames[base::threading::getCurrentThreadId()] = name; |
| 2747 |
} |
| 2748 |
|
| 2749 |
inline std::string getThreadName(const std::string& threadId) { |
| 2750 |
base::threading::ScopedLock scopedLock(m_threadNamesLock); |
| 2751 |
std::unordered_map<std::string, std::string>::const_iterator it = m_threadNames.find(threadId); |
| 2752 |
if (it == m_threadNames.end()) { |
| 2753 |
return threadId; |
| 2754 |
} |
| 2755 |
return it->second; |
| 2756 |
} |
| 2757 |
|
| 2758 |
static el::base::type::StoragePointer &getELPP(); |
| 2759 |
|
| 2760 |
private: |
| 2761 |
base::RegisteredHitCounters* m_registeredHitCounters; |
| 2762 |
base::RegisteredLoggers* m_registeredLoggers; |
| 2763 |
base::type::EnumType m_flags; |
| 2764 |
base::VRegistry* m_vRegistry; |
| 2765 |
#if ELPP_ASYNC_LOGGING |
| 2766 |
base::AsyncLogQueue* m_asyncLogQueue; |
| 2767 |
base::IWorker* m_asyncDispatchWorker; |
| 2768 |
#endif |
| 2769 |
base::utils::CommandLineArgs m_commandLineArgs; |
| 2770 |
PreRollOutCallback m_preRollOutCallback; |
| 2771 |
std::unordered_map<std::string, base::type::LogDispatchCallbackPtr> m_logDispatchCallbacks; |
| 2772 |
std::unordered_map<std::string, base::type::PerformanceTrackingCallbackPtr> m_performanceTrackingCallbacks; |
| 2773 |
std::unordered_map<std::string, std::string> m_threadNames; |
| 2774 |
std::vector<CustomFormatSpecifier> m_customFormatSpecifiers; |
| 2775 |
base::threading::Mutex m_customFormatSpecifiersLock; |
| 2776 |
base::threading::Mutex m_threadNamesLock; |
| 2777 |
Level m_loggingLevel; |
| 2778 |
|
| 2779 |
friend class el::Helpers; |
| 2780 |
friend class el::base::DefaultLogDispatchCallback; |
| 2781 |
friend class el::LogBuilder; |
| 2782 |
friend class el::base::MessageBuilder; |
| 2783 |
friend class el::base::Writer; |
| 2784 |
friend class el::base::PerformanceTracker; |
| 2785 |
friend class el::base::LogDispatcher; |
| 2786 |
|
| 2787 |
void setApplicationArguments(int argc, char** argv); |
| 2788 |
|
| 2789 |
inline void setApplicationArguments(int argc, const char** argv) { |
| 2790 |
setApplicationArguments(argc, const_cast<char**>(argv)); |
| 2791 |
} |
| 2792 |
}; |
| 2793 |
extern ELPP_EXPORT base::type::StoragePointer elStorage; |
| 2794 |
#define ELPP el::base::Storage::getELPP() |
| 2795 |
class DefaultLogDispatchCallback : public LogDispatchCallback { |
| 2796 |
protected: |
| 2797 |
void handle(const LogDispatchData* data); |
| 2798 |
private: |
| 2799 |
const LogDispatchData* m_data; |
| 2800 |
void dispatch(base::type::string_t&& rawLinePrefix, base::type::string_t&& rawLinePayload, base::type::string_t&& logLine); |
| 2801 |
}; |
| 2802 |
#if ELPP_ASYNC_LOGGING |
| 2803 |
class AsyncLogDispatchCallback : public LogDispatchCallback { |
| 2804 |
protected: |
| 2805 |
void handle(const LogDispatchData* data); |
| 2806 |
}; |
| 2807 |
class AsyncDispatchWorker : public base::IWorker, public base::threading::ThreadSafe { |
| 2808 |
public: |
| 2809 |
AsyncDispatchWorker(); |
| 2810 |
virtual ~AsyncDispatchWorker(); |
| 2811 |
|
| 2812 |
bool clean(void); |
| 2813 |
void emptyQueue(void); |
| 2814 |
virtual void start(void); |
| 2815 |
void handle(AsyncLogItem* logItem); |
| 2816 |
void run(void); |
| 2817 |
|
| 2818 |
void setContinueRunning(bool value) { |
| 2819 |
base::threading::ScopedLock scopedLock(m_continueRunningLock); |
| 2820 |
m_continueRunning = value; |
| 2821 |
} |
| 2822 |
|
| 2823 |
bool continueRunning(void) const { |
| 2824 |
return m_continueRunning; |
| 2825 |
} |
| 2826 |
private: |
| 2827 |
std::condition_variable cv; |
| 2828 |
bool m_continueRunning; |
| 2829 |
base::threading::Mutex m_continueRunningLock; |
| 2830 |
}; |
| 2831 |
#endif |
| 2832 |
} |
| 2833 |
namespace base { |
| 2834 |
class DefaultLogBuilder : public LogBuilder { |
| 2835 |
public: |
| 2836 |
base::type::string_t build(const LogMessage* logMessage, bool appendNewLine) const; |
| 2837 |
}; |
| 2838 |
|
| 2839 |
class LogDispatcher : base::NoCopy { |
| 2840 |
public: |
| 2841 |
LogDispatcher(bool proceed, LogMessage* logMessage, base::DispatchAction dispatchAction) : |
| 2842 |
m_proceed(proceed), |
| 2843 |
m_logMessage(logMessage), |
| 2844 |
m_dispatchAction(std::move(dispatchAction)) { |
| 2845 |
} |
| 2846 |
|
| 2847 |
void dispatch(void); |
| 2848 |
|
| 2849 |
private: |
| 2850 |
bool m_proceed; |
| 2851 |
LogMessage* m_logMessage; |
| 2852 |
base::DispatchAction m_dispatchAction; |
| 2853 |
}; |
| 2854 |
#if defined(ELPP_STL_LOGGING) |
| 2855 |
|
| 2856 |
|
| 2857 |
|
| 2858 |
|
| 2859 |
|
| 2860 |
|
| 2861 |
namespace workarounds { |
| 2862 |
|
| 2863 |
template <typename T, typename Container> |
| 2864 |
class IterableContainer { |
| 2865 |
public: |
| 2866 |
typedef typename Container::iterator iterator; |
| 2867 |
typedef typename Container::const_iterator const_iterator; |
| 2868 |
IterableContainer(void) {} |
| 2869 |
virtual ~IterableContainer(void) {} |
| 2870 |
iterator begin(void) { |
| 2871 |
return getContainer().begin(); |
| 2872 |
} |
| 2873 |
iterator end(void) { |
| 2874 |
return getContainer().end(); |
| 2875 |
} |
| 2876 |
private: |
| 2877 |
virtual Container& getContainer(void) = 0; |
| 2878 |
}; |
| 2879 |
|
| 2880 |
template<typename T, typename Container = std::vector<T>, typename Comparator = std::less<typename Container::value_type>> |
| 2881 |
class IterablePriorityQueue : public IterableContainer<T, Container>, |
| 2882 |
public std::priority_queue<T, Container, Comparator> { |
| 2883 |
public: |
| 2884 |
IterablePriorityQueue(std::priority_queue<T, Container, Comparator> queue_) { |
| 2885 |
std::size_t count_ = 0; |
| 2886 |
while (++count_ < base::consts::kMaxLogPerContainer && !queue_.empty()) { |
| 2887 |
this->push(queue_.top()); |
| 2888 |
queue_.pop(); |
| 2889 |
} |
| 2890 |
} |
| 2891 |
private: |
| 2892 |
inline Container& getContainer(void) { |
| 2893 |
return this->c; |
| 2894 |
} |
| 2895 |
}; |
| 2896 |
|
| 2897 |
template<typename T, typename Container = std::deque<T>> |
| 2898 |
class IterableQueue : public IterableContainer<T, Container>, public std::queue<T, Container> { |
| 2899 |
public: |
| 2900 |
IterableQueue(std::queue<T, Container> queue_) { |
| 2901 |
std::size_t count_ = 0; |
| 2902 |
while (++count_ < base::consts::kMaxLogPerContainer && !queue_.empty()) { |
| 2903 |
this->push(queue_.front()); |
| 2904 |
queue_.pop(); |
| 2905 |
} |
| 2906 |
} |
| 2907 |
private: |
| 2908 |
inline Container& getContainer(void) { |
| 2909 |
return this->c; |
| 2910 |
} |
| 2911 |
}; |
| 2912 |
|
| 2913 |
template<typename T, typename Container = std::deque<T>> |
| 2914 |
class IterableStack : public IterableContainer<T, Container>, public std::stack<T, Container> { |
| 2915 |
public: |
| 2916 |
IterableStack(std::stack<T, Container> stack_) { |
| 2917 |
std::size_t count_ = 0; |
| 2918 |
while (++count_ < base::consts::kMaxLogPerContainer && !stack_.empty()) { |
| 2919 |
this->push(stack_.top()); |
| 2920 |
stack_.pop(); |
| 2921 |
} |
| 2922 |
} |
| 2923 |
private: |
| 2924 |
inline Container& getContainer(void) { |
| 2925 |
return this->c; |
| 2926 |
} |
| 2927 |
}; |
| 2928 |
} |
| 2929 |
#endif |
| 2930 |
|
| 2931 |
class MessageBuilder { |
| 2932 |
public: |
| 2933 |
MessageBuilder(void) : m_logger(nullptr), m_containerLogSeperator(ELPP_LITERAL("")) {} |
| 2934 |
void initialize(Logger* logger); |
| 2935 |
|
| 2936 |
# define ELPP_SIMPLE_LOG(LOG_TYPE)\ |
| 2937 |
MessageBuilder& operator<<(LOG_TYPE msg) {\ |
| 2938 |
m_logger->stream() << msg;\ |
| 2939 |
if (ELPP->hasFlag(LoggingFlag::AutoSpacing)) {\ |
| 2940 |
m_logger->stream() << " ";\ |
| 2941 |
}\ |
| 2942 |
return *this;\ |
| 2943 |
} |
| 2944 |
|
| 2945 |
inline MessageBuilder& operator<<(const std::string& msg) { |
| 2946 |
return operator<<(msg.c_str()); |
| 2947 |
} |
| 2948 |
ELPP_SIMPLE_LOG(char) |
| 2949 |
ELPP_SIMPLE_LOG(bool) |
| 2950 |
ELPP_SIMPLE_LOG(signed short) |
| 2951 |
ELPP_SIMPLE_LOG(unsigned short) |
| 2952 |
ELPP_SIMPLE_LOG(signed int) |
| 2953 |
ELPP_SIMPLE_LOG(unsigned int) |
| 2954 |
ELPP_SIMPLE_LOG(signed long) |
| 2955 |
ELPP_SIMPLE_LOG(unsigned long) |
| 2956 |
ELPP_SIMPLE_LOG(float) |
| 2957 |
ELPP_SIMPLE_LOG(double) |
| 2958 |
ELPP_SIMPLE_LOG(char*) |
| 2959 |
ELPP_SIMPLE_LOG(const char*) |
| 2960 |
ELPP_SIMPLE_LOG(const void*) |
| 2961 |
ELPP_SIMPLE_LOG(long double) |
| 2962 |
inline MessageBuilder& operator<<(const std::wstring& msg) { |
| 2963 |
return operator<<(msg.c_str()); |
| 2964 |
} |
| 2965 |
MessageBuilder& operator<<(const wchar_t* msg); |
| 2966 |
|
| 2967 |
inline MessageBuilder& operator<<(std::ostream& (*OStreamMani)(std::ostream&)) { |
| 2968 |
m_logger->stream() << OStreamMani; |
| 2969 |
return *this; |
| 2970 |
} |
| 2971 |
#define ELPP_ITERATOR_CONTAINER_LOG_ONE_ARG(temp) \ |
| 2972 |
template <typename T> \ |
| 2973 |
inline MessageBuilder& operator<<(const temp<T>& template_inst) { \ |
| 2974 |
return writeIterator(template_inst.begin(), template_inst.end(), template_inst.size()); \ |
| 2975 |
} |
| 2976 |
#define ELPP_ITERATOR_CONTAINER_LOG_TWO_ARG(temp) \ |
| 2977 |
template <typename T1, typename T2> \ |
| 2978 |
inline MessageBuilder& operator<<(const temp<T1, T2>& template_inst) { \ |
| 2979 |
return writeIterator(template_inst.begin(), template_inst.end(), template_inst.size()); \ |
| 2980 |
} |
| 2981 |
#define ELPP_ITERATOR_CONTAINER_LOG_THREE_ARG(temp) \ |
| 2982 |
template <typename T1, typename T2, typename T3> \ |
| 2983 |
inline MessageBuilder& operator<<(const temp<T1, T2, T3>& template_inst) { \ |
| 2984 |
return writeIterator(template_inst.begin(), template_inst.end(), template_inst.size()); \ |
| 2985 |
} |
| 2986 |
#define ELPP_ITERATOR_CONTAINER_LOG_FOUR_ARG(temp) \ |
| 2987 |
template <typename T1, typename T2, typename T3, typename T4> \ |
| 2988 |
inline MessageBuilder& operator<<(const temp<T1, T2, T3, T4>& template_inst) { \ |
| 2989 |
return writeIterator(template_inst.begin(), template_inst.end(), template_inst.size()); \ |
| 2990 |
} |
| 2991 |
#define ELPP_ITERATOR_CONTAINER_LOG_FIVE_ARG(temp) \ |
| 2992 |
template <typename T1, typename T2, typename T3, typename T4, typename T5> \ |
| 2993 |
inline MessageBuilder& operator<<(const temp<T1, T2, T3, T4, T5>& template_inst) { \ |
| 2994 |
return writeIterator(template_inst.begin(), template_inst.end(), template_inst.size()); \ |
| 2995 |
} |
| 2996 |
|
| 2997 |
#if defined(ELPP_STL_LOGGING) |
| 2998 |
ELPP_ITERATOR_CONTAINER_LOG_TWO_ARG(std::vector) |
| 2999 |
ELPP_ITERATOR_CONTAINER_LOG_TWO_ARG(std::list) |
| 3000 |
ELPP_ITERATOR_CONTAINER_LOG_TWO_ARG(std::deque) |
| 3001 |
ELPP_ITERATOR_CONTAINER_LOG_THREE_ARG(std::set) |
| 3002 |
ELPP_ITERATOR_CONTAINER_LOG_THREE_ARG(std::multiset) |
| 3003 |
ELPP_ITERATOR_CONTAINER_LOG_FOUR_ARG(std::map) |
| 3004 |
ELPP_ITERATOR_CONTAINER_LOG_FOUR_ARG(std::multimap) |
| 3005 |
template <class T, class Container> |
| 3006 |
inline MessageBuilder& operator<<(const std::queue<T, Container>& queue_) { |
| 3007 |
base::workarounds::IterableQueue<T, Container> iterableQueue_ = |
| 3008 |
static_cast<base::workarounds::IterableQueue<T, Container> >(queue_); |
| 3009 |
return writeIterator(iterableQueue_.begin(), iterableQueue_.end(), iterableQueue_.size()); |
| 3010 |
} |
| 3011 |
template <class T, class Container> |
| 3012 |
inline MessageBuilder& operator<<(const std::stack<T, Container>& stack_) { |
| 3013 |
base::workarounds::IterableStack<T, Container> iterableStack_ = |
| 3014 |
static_cast<base::workarounds::IterableStack<T, Container> >(stack_); |
| 3015 |
return writeIterator(iterableStack_.begin(), iterableStack_.end(), iterableStack_.size()); |
| 3016 |
} |
| 3017 |
template <class T, class Container, class Comparator> |
| 3018 |
inline MessageBuilder& operator<<(const std::priority_queue<T, Container, Comparator>& priorityQueue_) { |
| 3019 |
base::workarounds::IterablePriorityQueue<T, Container, Comparator> iterablePriorityQueue_ = |
| 3020 |
static_cast<base::workarounds::IterablePriorityQueue<T, Container, Comparator> >(priorityQueue_); |
| 3021 |
return writeIterator(iterablePriorityQueue_.begin(), iterablePriorityQueue_.end(), iterablePriorityQueue_.size()); |
| 3022 |
} |
| 3023 |
template <class First, class Second> |
| 3024 |
MessageBuilder& operator<<(const std::pair<First, Second>& pair_) { |
| 3025 |
m_logger->stream() << ELPP_LITERAL("("); |
| 3026 |
operator << (static_cast<First>(pair_.first)); |
| 3027 |
m_logger->stream() << ELPP_LITERAL(", "); |
| 3028 |
operator << (static_cast<Second>(pair_.second)); |
| 3029 |
m_logger->stream() << ELPP_LITERAL(")"); |
| 3030 |
return *this; |
| 3031 |
} |
| 3032 |
template <std::size_t Size> |
| 3033 |
MessageBuilder& operator<<(const std::bitset<Size>& bitset_) { |
| 3034 |
m_logger->stream() << ELPP_LITERAL("["); |
| 3035 |
operator << (bitset_.to_string()); |
| 3036 |
m_logger->stream() << ELPP_LITERAL("]"); |
| 3037 |
return *this; |
| 3038 |
} |
| 3039 |
# if defined(ELPP_LOG_STD_ARRAY) |
| 3040 |
template <class T, std::size_t Size> |
| 3041 |
inline MessageBuilder& operator<<(const std::array<T, Size>& array) { |
| 3042 |
return writeIterator(array.begin(), array.end(), array.size()); |
| 3043 |
} |
| 3044 |
# endif |
| 3045 |
# if defined(ELPP_LOG_UNORDERED_MAP) |
| 3046 |
ELPP_ITERATOR_CONTAINER_LOG_FIVE_ARG(std::unordered_map) |
| 3047 |
ELPP_ITERATOR_CONTAINER_LOG_FIVE_ARG(std::unordered_multimap) |
| 3048 |
# endif |
| 3049 |
# if defined(ELPP_LOG_UNORDERED_SET) |
| 3050 |
ELPP_ITERATOR_CONTAINER_LOG_FOUR_ARG(std::unordered_set) |
| 3051 |
ELPP_ITERATOR_CONTAINER_LOG_FOUR_ARG(std::unordered_multiset) |
| 3052 |
# endif |
| 3053 |
#endif |
| 3054 |
#if defined(ELPP_QT_LOGGING) |
| 3055 |
inline MessageBuilder& operator<<(const QString& msg) { |
| 3056 |
# if defined(ELPP_UNICODE) |
| 3057 |
m_logger->stream() << msg.toStdWString(); |
| 3058 |
# else |
| 3059 |
m_logger->stream() << msg.toStdString(); |
| 3060 |
# endif |
| 3061 |
return *this; |
| 3062 |
} |
| 3063 |
inline MessageBuilder& operator<<(const QByteArray& msg) { |
| 3064 |
return operator << (QString(msg)); |
| 3065 |
} |
| 3066 |
inline MessageBuilder& operator<<(const QStringRef& msg) { |
| 3067 |
return operator<<(msg.toString()); |
| 3068 |
} |
| 3069 |
inline MessageBuilder& operator<<(qint64 msg) { |
| 3070 |
# if defined(ELPP_UNICODE) |
| 3071 |
m_logger->stream() << QString::number(msg).toStdWString(); |
| 3072 |
# else |
| 3073 |
m_logger->stream() << QString::number(msg).toStdString(); |
| 3074 |
# endif |
| 3075 |
return *this; |
| 3076 |
} |
| 3077 |
inline MessageBuilder& operator<<(quint64 msg) { |
| 3078 |
# if defined(ELPP_UNICODE) |
| 3079 |
m_logger->stream() << QString::number(msg).toStdWString(); |
| 3080 |
# else |
| 3081 |
m_logger->stream() << QString::number(msg).toStdString(); |
| 3082 |
# endif |
| 3083 |
return *this; |
| 3084 |
} |
| 3085 |
inline MessageBuilder& operator<<(QChar msg) { |
| 3086 |
m_logger->stream() << msg.toLatin1(); |
| 3087 |
return *this; |
| 3088 |
} |
| 3089 |
inline MessageBuilder& operator<<(const QLatin1String& msg) { |
| 3090 |
m_logger->stream() << msg.latin1(); |
| 3091 |
return *this; |
| 3092 |
} |
| 3093 |
ELPP_ITERATOR_CONTAINER_LOG_ONE_ARG(QList) |
| 3094 |
ELPP_ITERATOR_CONTAINER_LOG_ONE_ARG(QVector) |
| 3095 |
ELPP_ITERATOR_CONTAINER_LOG_ONE_ARG(QQueue) |
| 3096 |
ELPP_ITERATOR_CONTAINER_LOG_ONE_ARG(QSet) |
| 3097 |
ELPP_ITERATOR_CONTAINER_LOG_ONE_ARG(QLinkedList) |
| 3098 |
ELPP_ITERATOR_CONTAINER_LOG_ONE_ARG(QStack) |
| 3099 |
template <typename First, typename Second> |
| 3100 |
MessageBuilder& operator<<(const QPair<First, Second>& pair_) { |
| 3101 |
m_logger->stream() << ELPP_LITERAL("("); |
| 3102 |
operator << (static_cast<First>(pair_.first)); |
| 3103 |
m_logger->stream() << ELPP_LITERAL(", "); |
| 3104 |
operator << (static_cast<Second>(pair_.second)); |
| 3105 |
m_logger->stream() << ELPP_LITERAL(")"); |
| 3106 |
return *this; |
| 3107 |
} |
| 3108 |
template <typename K, typename V> |
| 3109 |
MessageBuilder& operator<<(const QMap<K, V>& map_) { |
| 3110 |
m_logger->stream() << ELPP_LITERAL("["); |
| 3111 |
QList<K> keys = map_.keys(); |
| 3112 |
typename QList<K>::const_iterator begin = keys.begin(); |
| 3113 |
typename QList<K>::const_iterator end = keys.end(); |
| 3114 |
int max_ = static_cast<int>(base::consts::kMaxLogPerContainer); |
| 3115 |
for (int index_ = 0; begin != end && index_ < max_; ++index_, ++begin) { |
| 3116 |
m_logger->stream() << ELPP_LITERAL("("); |
| 3117 |
operator << (static_cast<K>(*begin)); |
| 3118 |
m_logger->stream() << ELPP_LITERAL(", "); |
| 3119 |
operator << (static_cast<V>(map_.value(*begin))); |
| 3120 |
m_logger->stream() << ELPP_LITERAL(")"); |
| 3121 |
m_logger->stream() << ((index_ < keys.size() -1) ? m_containerLogSeperator : ELPP_LITERAL("")); |
| 3122 |
} |
| 3123 |
if (begin != end) { |
| 3124 |
m_logger->stream() << ELPP_LITERAL("..."); |
| 3125 |
} |
| 3126 |
m_logger->stream() << ELPP_LITERAL("]"); |
| 3127 |
return *this; |
| 3128 |
} |
| 3129 |
template <typename K, typename V> |
| 3130 |
inline MessageBuilder& operator<<(const QMultiMap<K, V>& map_) { |
| 3131 |
operator << (static_cast<QMap<K, V>>(map_)); |
| 3132 |
return *this; |
| 3133 |
} |
| 3134 |
template <typename K, typename V> |
| 3135 |
MessageBuilder& operator<<(const QHash<K, V>& hash_) { |
| 3136 |
m_logger->stream() << ELPP_LITERAL("["); |
| 3137 |
QList<K> keys = hash_.keys(); |
| 3138 |
typename QList<K>::const_iterator begin = keys.begin(); |
| 3139 |
typename QList<K>::const_iterator end = keys.end(); |
| 3140 |
int max_ = static_cast<int>(base::consts::kMaxLogPerContainer); |
| 3141 |
for (int index_ = 0; begin != end && index_ < max_; ++index_, ++begin) { |
| 3142 |
m_logger->stream() << ELPP_LITERAL("("); |
| 3143 |
operator << (static_cast<K>(*begin)); |
| 3144 |
m_logger->stream() << ELPP_LITERAL(", "); |
| 3145 |
operator << (static_cast<V>(hash_.value(*begin))); |
| 3146 |
m_logger->stream() << ELPP_LITERAL(")"); |
| 3147 |
m_logger->stream() << ((index_ < keys.size() -1) ? m_containerLogSeperator : ELPP_LITERAL("")); |
| 3148 |
} |
| 3149 |
if (begin != end) { |
| 3150 |
m_logger->stream() << ELPP_LITERAL("..."); |
| 3151 |
} |
| 3152 |
m_logger->stream() << ELPP_LITERAL("]"); |
| 3153 |
return *this; |
| 3154 |
} |
| 3155 |
template <typename K, typename V> |
| 3156 |
inline MessageBuilder& operator<<(const QMultiHash<K, V>& multiHash_) { |
| 3157 |
operator << (static_cast<QHash<K, V>>(multiHash_)); |
| 3158 |
return *this; |
| 3159 |
} |
| 3160 |
#endif |
| 3161 |
#if defined(ELPP_BOOST_LOGGING) |
| 3162 |
ELPP_ITERATOR_CONTAINER_LOG_TWO_ARG(boost::container::vector) |
| 3163 |
ELPP_ITERATOR_CONTAINER_LOG_TWO_ARG(boost::container::stable_vector) |
| 3164 |
ELPP_ITERATOR_CONTAINER_LOG_TWO_ARG(boost::container::list) |
| 3165 |
ELPP_ITERATOR_CONTAINER_LOG_TWO_ARG(boost::container::deque) |
| 3166 |
ELPP_ITERATOR_CONTAINER_LOG_FOUR_ARG(boost::container::map) |
| 3167 |
ELPP_ITERATOR_CONTAINER_LOG_FOUR_ARG(boost::container::flat_map) |
| 3168 |
ELPP_ITERATOR_CONTAINER_LOG_THREE_ARG(boost::container::set) |
| 3169 |
ELPP_ITERATOR_CONTAINER_LOG_THREE_ARG(boost::container::flat_set) |
| 3170 |
#endif |
| 3171 |
|
| 3172 |
|
| 3173 |
|
| 3174 |
|
| 3175 |
|
| 3176 |
|
| 3177 |
|
| 3178 |
|
| 3179 |
|
| 3180 |
#define MAKE_CONTAINERELPP_FRIENDLY(ContainerType, SizeMethod, ElementInstance) \ |
| 3181 |
el::base::type::ostream_t& operator<<(el::base::type::ostream_t& ss, const ContainerType& container) {\ |
| 3182 |
const el::base::type::char_t* sep = ELPP->hasFlag(el::LoggingFlag::NewLineForContainer) ? \ |
| 3183 |
ELPP_LITERAL("\n ") : ELPP_LITERAL(", ");\ |
| 3184 |
ContainerType::const_iterator elem = container.begin();\ |
| 3185 |
ContainerType::const_iterator endElem = container.end();\ |
| 3186 |
std::size_t size_ = container.SizeMethod; \ |
| 3187 |
ss << ELPP_LITERAL("[");\ |
| 3188 |
for (std::size_t i = 0; elem != endElem && i < el::base::consts::kMaxLogPerContainer; ++i, ++elem) { \ |
| 3189 |
ss << ElementInstance;\ |
| 3190 |
ss << ((i < size_ - 1) ? sep : ELPP_LITERAL(""));\ |
| 3191 |
}\ |
| 3192 |
if (elem != endElem) {\ |
| 3193 |
ss << ELPP_LITERAL("...");\ |
| 3194 |
}\ |
| 3195 |
ss << ELPP_LITERAL("]");\ |
| 3196 |
return ss;\ |
| 3197 |
} |
| 3198 |
#if defined(ELPP_WXWIDGETS_LOGGING) |
| 3199 |
ELPP_ITERATOR_CONTAINER_LOG_ONE_ARG(wxVector) |
| 3200 |
# define ELPP_WX_PTR_ENABLED(ContainerType) MAKE_CONTAINERELPP_FRIENDLY(ContainerType, size(), *(*elem)) |
| 3201 |
# define ELPP_WX_ENABLED(ContainerType) MAKE_CONTAINERELPP_FRIENDLY(ContainerType, size(), (*elem)) |
| 3202 |
# define ELPP_WX_HASH_MAP_ENABLED(ContainerType) MAKE_CONTAINERELPP_FRIENDLY(ContainerType, size(), \ |
| 3203 |
ELPP_LITERAL("(") << elem->first << ELPP_LITERAL(", ") << elem->second << ELPP_LITERAL(")") |
| 3204 |
#else |
| 3205 |
# define ELPP_WX_PTR_ENABLED(ContainerType) |
| 3206 |
# define ELPP_WX_ENABLED(ContainerType) |
| 3207 |
# define ELPP_WX_HASH_MAP_ENABLED(ContainerType) |
| 3208 |
#endif |
| 3209 |
|
| 3210 |
template <class Class> |
| 3211 |
ELPP_SIMPLE_LOG(const Class&) |
| 3212 |
#undef ELPP_SIMPLE_LOG |
| 3213 |
#undef ELPP_ITERATOR_CONTAINER_LOG_ONE_ARG |
| 3214 |
#undef ELPP_ITERATOR_CONTAINER_LOG_TWO_ARG |
| 3215 |
#undef ELPP_ITERATOR_CONTAINER_LOG_THREE_ARG |
| 3216 |
#undef ELPP_ITERATOR_CONTAINER_LOG_FOUR_ARG |
| 3217 |
#undef ELPP_ITERATOR_CONTAINER_LOG_FIVE_ARG |
| 3218 |
private: |
| 3219 |
Logger* m_logger; |
| 3220 |
const base::type::char_t* m_containerLogSeperator; |
| 3221 |
|
| 3222 |
template<class Iterator> |
| 3223 |
MessageBuilder& writeIterator(Iterator begin_, Iterator end_, std::size_t size_) { |
| 3224 |
m_logger->stream() << ELPP_LITERAL("["); |
| 3225 |
for (std::size_t i = 0; begin_ != end_ && i < base::consts::kMaxLogPerContainer; ++i, ++begin_) { |
| 3226 |
operator << (*begin_); |
| 3227 |
m_logger->stream() << ((i < size_ - 1) ? m_containerLogSeperator : ELPP_LITERAL("")); |
| 3228 |
} |
| 3229 |
if (begin_ != end_) { |
| 3230 |
m_logger->stream() << ELPP_LITERAL("..."); |
| 3231 |
} |
| 3232 |
m_logger->stream() << ELPP_LITERAL("]"); |
| 3233 |
if (ELPP->hasFlag(LoggingFlag::AutoSpacing)) { |
| 3234 |
m_logger->stream() << " "; |
| 3235 |
} |
| 3236 |
return *this; |
| 3237 |
} |
| 3238 |
}; |
| 3239 |
|
| 3240 |
class NullWriter : base::NoCopy { |
| 3241 |
public: |
| 3242 |
NullWriter(void) {} |
| 3243 |
|
| 3244 |
|
| 3245 |
inline NullWriter& operator<<(std::ostream& (*)(std::ostream&)) { |
| 3246 |
return *this; |
| 3247 |
} |
| 3248 |
|
| 3249 |
template <typename T> |
| 3250 |
inline NullWriter& operator<<(const T&) { |
| 3251 |
return *this; |
| 3252 |
} |
| 3253 |
|
| 3254 |
inline operator bool() { |
| 3255 |
return true; |
| 3256 |
} |
| 3257 |
}; |
| 3258 |
|
| 3259 |
class Writer : base::NoCopy { |
| 3260 |
public: |
| 3261 |
Writer(Level level, Color color, const char* file, base::type::LineNumber line, |
| 3262 |
const char* func, base::DispatchAction dispatchAction = base::DispatchAction::NormalLog, |
| 3263 |
base::type::VerboseLevel verboseLevel = 0) : |
| 3264 |
m_msg(nullptr), m_level(level), m_color(color), m_file(file), m_line(line), m_func(func), m_verboseLevel(verboseLevel), |
| 3265 |
m_logger(nullptr), m_proceed(false), m_dispatchAction(dispatchAction), m_sync(ELPP->lock()) { |
| 3266 |
} |
| 3267 |
|
| 3268 |
Writer(LogMessage* msg, base::DispatchAction dispatchAction = base::DispatchAction::NormalLog) : |
| 3269 |
m_msg(msg), m_level(msg != nullptr ? msg->level() : Level::Unknown), |
| 3270 |
m_line(0), m_logger(nullptr), m_proceed(false), m_dispatchAction(dispatchAction), m_sync(ELPP->lock()) { |
| 3271 |
} |
| 3272 |
|
| 3273 |
virtual ~Writer(void) { |
| 3274 |
processDispatch(); |
| 3275 |
} |
| 3276 |
|
| 3277 |
Writer& operator<<(const std::string &log) { |
| 3278 |
#if ELPP_LOGGING_ENABLED |
| 3279 |
if (m_proceed) { |
| 3280 |
m_messageBuilder << log; |
| 3281 |
} |
| 3282 |
#endif |
| 3283 |
return *this; |
| 3284 |
} |
| 3285 |
|
| 3286 |
inline operator bool() { |
| 3287 |
return true; |
| 3288 |
} |
| 3289 |
|
| 3290 |
Writer& construct(Logger* logger, bool needLock = true); |
| 3291 |
Writer& construct(int count, const char* loggerIds, ...); |
| 3292 |
Writer& construct(const char *loggerId); |
| 3293 |
protected: |
| 3294 |
LogMessage* m_msg; |
| 3295 |
Level m_level; |
| 3296 |
Color m_color; |
| 3297 |
const char* m_file; |
| 3298 |
const base::type::LineNumber m_line; |
| 3299 |
const char* m_func; |
| 3300 |
base::type::VerboseLevel m_verboseLevel; |
| 3301 |
Logger* m_logger; |
| 3302 |
bool m_proceed; |
| 3303 |
base::MessageBuilder m_messageBuilder; |
| 3304 |
base::DispatchAction m_dispatchAction; |
| 3305 |
std::vector<std::string> m_loggerIds; |
| 3306 |
base::threading::ScopedLock m_sync; |
| 3307 |
friend class el::Helpers; |
| 3308 |
|
| 3309 |
void initializeLogger(const std::string& loggerId, bool lookup = true, bool needLock = true); |
| 3310 |
void initializeLogger(Logger *logger, bool needLock = true); |
| 3311 |
void processDispatch(); |
| 3312 |
void triggerDispatch(void); |
| 3313 |
}; |
| 3314 |
class PErrorWriter : public base::Writer { |
| 3315 |
public: |
| 3316 |
PErrorWriter(Level level, Color color, const char* file, base::type::LineNumber line, |
| 3317 |
const char* func, base::DispatchAction dispatchAction = base::DispatchAction::NormalLog, |
| 3318 |
base::type::VerboseLevel verboseLevel = 0) : |
| 3319 |
base::Writer(level, color, file, line, func, dispatchAction, verboseLevel) { |
| 3320 |
} |
| 3321 |
|
| 3322 |
virtual ~PErrorWriter(void); |
| 3323 |
}; |
| 3324 |
} |
| 3325 |
|
| 3326 |
#if ELPP_VARIADIC_TEMPLATES_SUPPORTED |
| 3327 |
template <typename T, typename... Args> |
| 3328 |
void Logger::log_(Level level, int vlevel, const char* s, const T& value, const Args&... args) { |
| 3329 |
base::MessageBuilder b; |
| 3330 |
b.initialize(this); |
| 3331 |
while (*s) { |
| 3332 |
if (*s == base::consts::kFormatSpecifierChar) { |
| 3333 |
if (*(s + 1) == base::consts::kFormatSpecifierChar) { |
| 3334 |
++s; |
| 3335 |
} else { |
| 3336 |
if (*(s + 1) == base::consts::kFormatSpecifierCharValue) { |
| 3337 |
++s; |
| 3338 |
b << value; |
| 3339 |
log_(level, vlevel, ++s, args...); |
| 3340 |
return; |
| 3341 |
} |
| 3342 |
} |
| 3343 |
} |
| 3344 |
b << *s++; |
| 3345 |
} |
| 3346 |
ELPP_INTERNAL_ERROR("Too many arguments provided. Unable to handle. Please provide more format specifiers", false); |
| 3347 |
} |
| 3348 |
template <typename T> |
| 3349 |
void Logger::log_(Level level, int vlevel, const T& log) { |
| 3350 |
if (level == Level::Verbose) { |
| 3351 |
if (ELPP->vRegistry()->allowed(vlevel, __FILE__)) { |
| 3352 |
base::Writer(Level::Verbose, Color::Default, "FILE", 0, "FUNCTION", |
| 3353 |
base::DispatchAction::NormalLog, vlevel).construct(this, false) << log; |
| 3354 |
} else { |
| 3355 |
stream().str(ELPP_LITERAL("")); |
| 3356 |
releaseLock(); |
| 3357 |
} |
| 3358 |
} else { |
| 3359 |
base::Writer(level, Color::Default, "FILE", 0, "FUNCTION").construct(this, false) << log; |
| 3360 |
} |
| 3361 |
} |
| 3362 |
template <typename T, typename... Args> |
| 3363 |
inline void Logger::log(Level level, const char* s, const T& value, const Args&... args) { |
| 3364 |
acquireLock(); |
| 3365 |
log_(level, 0, s, value, args...); |
| 3366 |
} |
| 3367 |
template <typename T> |
| 3368 |
inline void Logger::log(Level level, const T& log) { |
| 3369 |
acquireLock(); |
| 3370 |
log_(level, 0, log); |
| 3371 |
} |
| 3372 |
# if ELPP_VERBOSE_LOG |
| 3373 |
template <typename T, typename... Args> |
| 3374 |
inline void Logger::verbose(int vlevel, const char* s, const T& value, const Args&... args) { |
| 3375 |
acquireLock(); |
| 3376 |
log_(el::Level::Verbose, vlevel, s, value, args...); |
| 3377 |
} |
| 3378 |
template <typename T> |
| 3379 |
inline void Logger::verbose(int vlevel, const T& log) { |
| 3380 |
acquireLock(); |
| 3381 |
log_(el::Level::Verbose, vlevel, log); |
| 3382 |
} |
| 3383 |
# else |
| 3384 |
template <typename T, typename... Args> |
| 3385 |
inline void Logger::verbose(int, const char*, const T&, const Args&...) { |
| 3386 |
return; |
| 3387 |
} |
| 3388 |
template <typename T> |
| 3389 |
inline void Logger::verbose(int, const T&) { |
| 3390 |
return; |
| 3391 |
} |
| 3392 |
# endif |
| 3393 |
# define LOGGER_LEVEL_WRITERS(FUNCTION_NAME, LOG_LEVEL)\ |
| 3394 |
template <typename T, typename... Args>\ |
| 3395 |
inline void Logger::FUNCTION_NAME(const char* s, const T& value, const Args&... args) {\ |
| 3396 |
log(LOG_LEVEL, s, value, args...);\ |
| 3397 |
}\ |
| 3398 |
template <typename T>\ |
| 3399 |
inline void Logger::FUNCTION_NAME(const T& value) {\ |
| 3400 |
log(LOG_LEVEL, value);\ |
| 3401 |
} |
| 3402 |
# define LOGGER_LEVEL_WRITERS_DISABLED(FUNCTION_NAME, LOG_LEVEL)\ |
| 3403 |
template <typename T, typename... Args>\ |
| 3404 |
inline void Logger::FUNCTION_NAME(const char*, const T&, const Args&...) {\ |
| 3405 |
return;\ |
| 3406 |
}\ |
| 3407 |
template <typename T>\ |
| 3408 |
inline void Logger::FUNCTION_NAME(const T&) {\ |
| 3409 |
return;\ |
| 3410 |
} |
| 3411 |
|
| 3412 |
# if ELPP_INFO_LOG |
| 3413 |
LOGGER_LEVEL_WRITERS(info, Level::Info) |
| 3414 |
# else |
| 3415 |
LOGGER_LEVEL_WRITERS_DISABLED(info, Level::Info) |
| 3416 |
# endif |
| 3417 |
# if ELPP_DEBUG_LOG |
| 3418 |
LOGGER_LEVEL_WRITERS(debug, Level::Debug) |
| 3419 |
# else |
| 3420 |
LOGGER_LEVEL_WRITERS_DISABLED(debug, Level::Debug) |
| 3421 |
# endif |
| 3422 |
# if ELPP_WARNING_LOG |
| 3423 |
LOGGER_LEVEL_WRITERS(warn, Level::Warning) |
| 3424 |
# else |
| 3425 |
LOGGER_LEVEL_WRITERS_DISABLED(warn, Level::Warning) |
| 3426 |
# endif |
| 3427 |
# if ELPP_ERROR_LOG |
| 3428 |
LOGGER_LEVEL_WRITERS(error, Level::Error) |
| 3429 |
# else |
| 3430 |
LOGGER_LEVEL_WRITERS_DISABLED(error, Level::Error) |
| 3431 |
# endif |
| 3432 |
# if ELPP_FATAL_LOG |
| 3433 |
LOGGER_LEVEL_WRITERS(fatal, Level::Fatal) |
| 3434 |
# else |
| 3435 |
LOGGER_LEVEL_WRITERS_DISABLED(fatal, Level::Fatal) |
| 3436 |
# endif |
| 3437 |
# if ELPP_TRACE_LOG |
| 3438 |
LOGGER_LEVEL_WRITERS(trace, Level::Trace) |
| 3439 |
# else |
| 3440 |
LOGGER_LEVEL_WRITERS_DISABLED(trace, Level::Trace) |
| 3441 |
# endif |
| 3442 |
# undef LOGGER_LEVEL_WRITERS |
| 3443 |
# undef LOGGER_LEVEL_WRITERS_DISABLED |
| 3444 |
#endif |
| 3445 |
#if ELPP_COMPILER_MSVC |
| 3446 |
# define ELPP_VARIADIC_FUNC_MSVC(variadicFunction, variadicArgs) variadicFunction variadicArgs |
| 3447 |
# define ELPP_VARIADIC_FUNC_MSVC_RUN(variadicFunction, ...) ELPP_VARIADIC_FUNC_MSVC(variadicFunction, (__VA_ARGS__)) |
| 3448 |
# define el_getVALength(...) ELPP_VARIADIC_FUNC_MSVC_RUN(el_resolveVALength, 0, ## __VA_ARGS__,\ |
| 3449 |
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) |
| 3450 |
#else |
| 3451 |
# if ELPP_COMPILER_CLANG |
| 3452 |
# define el_getVALength(...) el_resolveVALength(0, __VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) |
| 3453 |
# else |
| 3454 |
# define el_getVALength(...) el_resolveVALength(0, ## __VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) |
| 3455 |
# endif |
| 3456 |
#endif |
| 3457 |
#define el_resolveVALength(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N |
| 3458 |
#define ELPP_WRITE_LOG(writer, level, dispatchAction, ...) \ |
| 3459 |
writer(level, el::Color::Default, __FILE__, __LINE__, ELPP_FUNC, dispatchAction).construct(el_getVALength(__VA_ARGS__), __VA_ARGS__) |
| 3460 |
#define ELPP_WRITE_LOG_IF(writer, condition, level, dispatchAction, ...) if (condition) \ |
| 3461 |
writer(level, el::Color::Default, __FILE__, __LINE__, ELPP_FUNC, dispatchAction).construct(el_getVALength(__VA_ARGS__), __VA_ARGS__) |
| 3462 |
#define ELPP_WRITE_LOG_EVERY_N(writer, occasion, level, dispatchAction, ...) \ |
| 3463 |
ELPP->validateEveryNCounter(__FILE__, __LINE__, occasion) && \ |
| 3464 |
writer(level, el::Color::Default, __FILE__, __LINE__, ELPP_FUNC, dispatchAction).construct(el_getVALength(__VA_ARGS__), __VA_ARGS__) |
| 3465 |
#define ELPP_WRITE_LOG_AFTER_N(writer, n, level, dispatchAction, ...) \ |
| 3466 |
ELPP->validateAfterNCounter(__FILE__, __LINE__, n) && \ |
| 3467 |
writer(level, el::Color::Default, __FILE__, __LINE__, ELPP_FUNC, dispatchAction).construct(el_getVALength(__VA_ARGS__), __VA_ARGS__) |
| 3468 |
#define ELPP_WRITE_LOG_N_TIMES(writer, n, level, dispatchAction, ...) \ |
| 3469 |
ELPP->validateNTimesCounter(__FILE__, __LINE__, n) && \ |
| 3470 |
writer(level, el::Color::Default, __FILE__, __LINE__, ELPP_FUNC, dispatchAction).construct(el_getVALength(__VA_ARGS__), __VA_ARGS__) |
| 3471 |
#if defined(ELPP_FEATURE_ALL) || defined(ELPP_FEATURE_PERFORMANCE_TRACKING) |
| 3472 |
class PerformanceTrackingData { |
| 3473 |
public: |
| 3474 |
enum class DataType : base::type::EnumType { |
| 3475 |
Checkpoint = 1, Complete = 2 |
| 3476 |
}; |
| 3477 |
|
| 3478 |
explicit PerformanceTrackingData(DataType dataType) : m_performanceTracker(nullptr), |
| 3479 |
m_dataType(dataType), m_firstCheckpoint(false), m_file(""), m_line(0), m_func("") {} |
| 3480 |
inline const std::string* blockName(void) const; |
| 3481 |
inline const struct timeval* startTime(void) const; |
| 3482 |
inline const struct timeval* endTime(void) const; |
| 3483 |
inline const struct timeval* lastCheckpointTime(void) const; |
| 3484 |
inline const base::PerformanceTracker* performanceTracker(void) const { |
| 3485 |
return m_performanceTracker; |
| 3486 |
} |
| 3487 |
inline PerformanceTrackingData::DataType dataType(void) const { |
| 3488 |
return m_dataType; |
| 3489 |
} |
| 3490 |
inline bool firstCheckpoint(void) const { |
| 3491 |
return m_firstCheckpoint; |
| 3492 |
} |
| 3493 |
inline std::string checkpointId(void) const { |
| 3494 |
return m_checkpointId; |
| 3495 |
} |
| 3496 |
inline const char* file(void) const { |
| 3497 |
return m_file; |
| 3498 |
} |
| 3499 |
inline base::type::LineNumber line(void) const { |
| 3500 |
return m_line; |
| 3501 |
} |
| 3502 |
inline const char* func(void) const { |
| 3503 |
return m_func; |
| 3504 |
} |
| 3505 |
inline const base::type::string_t* formattedTimeTaken() const { |
| 3506 |
return &m_formattedTimeTaken; |
| 3507 |
} |
| 3508 |
inline const std::string& loggerId(void) const; |
| 3509 |
private: |
| 3510 |
base::PerformanceTracker* m_performanceTracker; |
| 3511 |
base::type::string_t m_formattedTimeTaken; |
| 3512 |
PerformanceTrackingData::DataType m_dataType; |
| 3513 |
bool m_firstCheckpoint; |
| 3514 |
std::string m_checkpointId; |
| 3515 |
const char* m_file; |
| 3516 |
base::type::LineNumber m_line; |
| 3517 |
const char* m_func; |
| 3518 |
inline void init(base::PerformanceTracker* performanceTracker, bool firstCheckpoint = false) { |
| 3519 |
m_performanceTracker = performanceTracker; |
| 3520 |
m_firstCheckpoint = firstCheckpoint; |
| 3521 |
} |
| 3522 |
|
| 3523 |
friend class el::base::PerformanceTracker; |
| 3524 |
}; |
| 3525 |
namespace base { |
| 3526 |
|
| 3527 |
|
| 3528 |
class PerformanceTracker : public base::threading::ThreadSafe, public Loggable { |
| 3529 |
public: |
| 3530 |
PerformanceTracker(const std::string& blockName, |
| 3531 |
base::TimestampUnit timestampUnit = base::TimestampUnit::Millisecond, |
| 3532 |
const std::string& loggerId = std::string(el::base::consts::kPerformanceLoggerId), |
| 3533 |
bool scopedLog = true, Level level = base::consts::kPerformanceTrackerDefaultLevel); |
| 3534 |
|
| 3535 |
PerformanceTracker(const PerformanceTracker& t) : |
| 3536 |
m_blockName(t.m_blockName), m_timestampUnit(t.m_timestampUnit), m_loggerId(t.m_loggerId), m_scopedLog(t.m_scopedLog), |
| 3537 |
m_level(t.m_level), m_hasChecked(t.m_hasChecked), m_lastCheckpointId(t.m_lastCheckpointId), m_enabled(t.m_enabled), |
| 3538 |
m_startTime(t.m_startTime), m_endTime(t.m_endTime), m_lastCheckpointTime(t.m_lastCheckpointTime) { |
| 3539 |
} |
| 3540 |
virtual ~PerformanceTracker(void); |
| 3541 |
|
| 3542 |
void checkpoint(const std::string& id = std::string(), const char* file = __FILE__, |
| 3543 |
base::type::LineNumber line = __LINE__, |
| 3544 |
const char* func = ""); |
| 3545 |
inline Level level(void) const { |
| 3546 |
return m_level; |
| 3547 |
} |
| 3548 |
private: |
| 3549 |
std::string m_blockName; |
| 3550 |
base::TimestampUnit m_timestampUnit; |
| 3551 |
std::string m_loggerId; |
| 3552 |
bool m_scopedLog; |
| 3553 |
Level m_level; |
| 3554 |
bool m_hasChecked; |
| 3555 |
std::string m_lastCheckpointId; |
| 3556 |
bool m_enabled; |
| 3557 |
struct timeval m_startTime, m_endTime, m_lastCheckpointTime; |
| 3558 |
|
| 3559 |
PerformanceTracker(void); |
| 3560 |
|
| 3561 |
friend class el::PerformanceTrackingData; |
| 3562 |
friend class base::DefaultPerformanceTrackingCallback; |
| 3563 |
|
| 3564 |
const inline base::type::string_t getFormattedTimeTaken() const { |
| 3565 |
return getFormattedTimeTaken(m_startTime); |
| 3566 |
} |
| 3567 |
|
| 3568 |
const base::type::string_t getFormattedTimeTaken(struct timeval startTime) const; |
| 3569 |
|
| 3570 |
virtual inline void log(el::base::type::ostream_t& os) const { |
| 3571 |
os << getFormattedTimeTaken(); |
| 3572 |
} |
| 3573 |
}; |
| 3574 |
class DefaultPerformanceTrackingCallback : public PerformanceTrackingCallback { |
| 3575 |
protected: |
| 3576 |
void handle(const PerformanceTrackingData* data) { |
| 3577 |
m_data = data; |
| 3578 |
base::type::stringstream_t ss; |
| 3579 |
if (m_data->dataType() == PerformanceTrackingData::DataType::Complete) { |
| 3580 |
ss << ELPP_LITERAL("Executed [") << m_data->blockName()->c_str() << ELPP_LITERAL("] in [") << |
| 3581 |
*m_data->formattedTimeTaken() << ELPP_LITERAL("]"); |
| 3582 |
} else { |
| 3583 |
ss << ELPP_LITERAL("Performance checkpoint"); |
| 3584 |
if (!m_data->checkpointId().empty()) { |
| 3585 |
ss << ELPP_LITERAL(" [") << m_data->checkpointId().c_str() << ELPP_LITERAL("]"); |
| 3586 |
} |
| 3587 |
ss << ELPP_LITERAL(" for block [") << m_data->blockName()->c_str() << ELPP_LITERAL("] : [") << |
| 3588 |
*m_data->performanceTracker(); |
| 3589 |
if (!ELPP->hasFlag(LoggingFlag::DisablePerformanceTrackingCheckpointComparison) |
| 3590 |
&& m_data->performanceTracker()->m_hasChecked) { |
| 3591 |
ss << ELPP_LITERAL(" ([") << *m_data->formattedTimeTaken() << ELPP_LITERAL("] from "); |
| 3592 |
if (m_data->performanceTracker()->m_lastCheckpointId.empty()) { |
| 3593 |
ss << ELPP_LITERAL("last checkpoint"); |
| 3594 |
} else { |
| 3595 |
ss << ELPP_LITERAL("checkpoint '") << m_data->performanceTracker()->m_lastCheckpointId.c_str() << ELPP_LITERAL("'"); |
| 3596 |
} |
| 3597 |
ss << ELPP_LITERAL(")]"); |
| 3598 |
} else { |
| 3599 |
ss << ELPP_LITERAL("]"); |
| 3600 |
} |
| 3601 |
} |
| 3602 |
const std::string str = ss.str(); |
| 3603 |
el::base::Writer(m_data->performanceTracker()->level(), m_data->file(), m_data->line(), m_data->func()).construct(1, |
| 3604 |
m_data->loggerId().c_str()) << str; |
| 3605 |
} |
| 3606 |
private: |
| 3607 |
const PerformanceTrackingData* m_data; |
| 3608 |
}; |
| 3609 |
} |
| 3610 |
inline const std::string* PerformanceTrackingData::blockName() const { |
| 3611 |
return const_cast<const std::string*>(&m_performanceTracker->m_blockName); |
| 3612 |
} |
| 3613 |
inline const struct timeval* PerformanceTrackingData::startTime() const { |
| 3614 |
return const_cast<const struct timeval*>(&m_performanceTracker->m_startTime); |
| 3615 |
} |
| 3616 |
inline const struct timeval* PerformanceTrackingData::endTime() const { |
| 3617 |
return const_cast<const struct timeval*>(&m_performanceTracker->m_endTime); |
| 3618 |
} |
| 3619 |
inline const struct timeval* PerformanceTrackingData::lastCheckpointTime() const { |
| 3620 |
return const_cast<const struct timeval*>(&m_performanceTracker->m_lastCheckpointTime); |
| 3621 |
} |
| 3622 |
inline const std::string& PerformanceTrackingData::loggerId(void) const { |
| 3623 |
return m_performanceTracker->m_loggerId; |
| 3624 |
} |
| 3625 |
#endif |
| 3626 |
namespace base { |
| 3627 |
|
| 3628 |
namespace debug { |
| 3629 |
#if defined(ELPP_FEATURE_ALL) || defined(ELPP_FEATURE_CRASH_LOG) |
| 3630 |
class StackTrace : base::NoCopy { |
| 3631 |
public: |
| 3632 |
static const unsigned int kMaxStack = 64; |
| 3633 |
static const unsigned int kStackStart = 2; |
| 3634 |
class StackTraceEntry { |
| 3635 |
public: |
| 3636 |
StackTraceEntry(std::size_t index, const std::string& loc, const std::string& demang, const std::string& hex, |
| 3637 |
const std::string& addr); |
| 3638 |
StackTraceEntry(std::size_t index, const std::string& loc) : |
| 3639 |
m_index(index), |
| 3640 |
m_location(loc) { |
| 3641 |
} |
| 3642 |
std::size_t m_index; |
| 3643 |
std::string m_location; |
| 3644 |
std::string m_demangled; |
| 3645 |
std::string m_hex; |
| 3646 |
std::string m_addr; |
| 3647 |
friend std::ostream& operator<<(std::ostream& ss, const StackTraceEntry& si); |
| 3648 |
|
| 3649 |
private: |
| 3650 |
StackTraceEntry(void); |
| 3651 |
}; |
| 3652 |
|
| 3653 |
StackTrace(void) { |
| 3654 |
generateNew(); |
| 3655 |
} |
| 3656 |
|
| 3657 |
virtual ~StackTrace(void) { |
| 3658 |
} |
| 3659 |
|
| 3660 |
inline std::vector<StackTraceEntry>& getLatestStack(void) { |
| 3661 |
return m_stack; |
| 3662 |
} |
| 3663 |
|
| 3664 |
friend std::ostream& operator<<(std::ostream& os, const StackTrace& st); |
| 3665 |
|
| 3666 |
private: |
| 3667 |
std::vector<StackTraceEntry> m_stack; |
| 3668 |
|
| 3669 |
void generateNew(void); |
| 3670 |
}; |
| 3671 |
|
| 3672 |
class CrashHandler : base::NoCopy { |
| 3673 |
public: |
| 3674 |
typedef void (*Handler)(int); |
| 3675 |
|
| 3676 |
explicit CrashHandler(bool useDefault); |
| 3677 |
explicit CrashHandler(const Handler& cHandler) { |
| 3678 |
setHandler(cHandler); |
| 3679 |
} |
| 3680 |
void setHandler(const Handler& cHandler); |
| 3681 |
|
| 3682 |
private: |
| 3683 |
Handler m_handler; |
| 3684 |
}; |
| 3685 |
#else |
| 3686 |
class CrashHandler { |
| 3687 |
public: |
| 3688 |
explicit CrashHandler(bool) {} |
| 3689 |
}; |
| 3690 |
#endif |
| 3691 |
} |
| 3692 |
} |
| 3693 |
extern base::debug::CrashHandler elCrashHandler; |
| 3694 |
#define MAKE_LOGGABLE(ClassType, ClassInstance, OutputStreamInstance) \ |
| 3695 |
el::base::type::ostream_t& operator<<(el::base::type::ostream_t& OutputStreamInstance, const ClassType& ClassInstance) |
| 3696 |
|
| 3697 |
class SysLogInitializer { |
| 3698 |
public: |
| 3699 |
SysLogInitializer(const char* processIdent, int options = 0, int facility = 0) { |
| 3700 |
#if defined(ELPP_SYSLOG) |
| 3701 |
openlog(processIdent, options, facility); |
| 3702 |
#else |
| 3703 |
ELPP_UNUSED(processIdent); |
| 3704 |
ELPP_UNUSED(options); |
| 3705 |
ELPP_UNUSED(facility); |
| 3706 |
#endif |
| 3707 |
} |
| 3708 |
virtual ~SysLogInitializer(void) { |
| 3709 |
#if defined(ELPP_SYSLOG) |
| 3710 |
closelog(); |
| 3711 |
#endif |
| 3712 |
} |
| 3713 |
}; |
| 3714 |
#define ELPP_INITIALIZE_SYSLOG(id, opt, fac) el::SysLogInitializer elSyslogInit(id, opt, fac) |
| 3715 |
|
| 3716 |
class Helpers : base::StaticClass { |
| 3717 |
public: |
| 3718 |
|
| 3719 |
static inline void setStorage(base::type::StoragePointer storage) { |
| 3720 |
ELPP = storage; |
| 3721 |
} |
| 3722 |
|
| 3723 |
static inline base::type::StoragePointer storage() { |
| 3724 |
return ELPP; |
| 3725 |
} |
| 3726 |
|
| 3727 |
static inline void setArgs(int argc, char** argv) { |
| 3728 |
ELPP->setApplicationArguments(argc, argv); |
| 3729 |
} |
| 3730 |
|
| 3731 |
static inline void setArgs(int argc, const char** argv) { |
| 3732 |
ELPP->setApplicationArguments(argc, const_cast<char**>(argv)); |
| 3733 |
} |
| 3734 |
|
| 3735 |
static inline void setThreadName(const std::string& name) { |
| 3736 |
ELPP->setThreadName(name); |
| 3737 |
} |
| 3738 |
static inline std::string getThreadName() { |
| 3739 |
return ELPP->getThreadName(base::threading::getCurrentThreadId()); |
| 3740 |
} |
| 3741 |
#if defined(ELPP_FEATURE_ALL) || defined(ELPP_FEATURE_CRASH_LOG) |
| 3742 |
|
| 3743 |
|
| 3744 |
|
| 3745 |
static inline void setCrashHandler(const el::base::debug::CrashHandler::Handler& crashHandler) { |
| 3746 |
el::elCrashHandler.setHandler(crashHandler); |
| 3747 |
} |
| 3748 |
|
| 3749 |
|
| 3750 |
static void crashAbort(int sig, const char* sourceFile = "", unsigned int long line = 0); |
| 3751 |
|
| 3752 |
|
| 3753 |
|
| 3754 |
|
| 3755 |
|
| 3756 |
static void logCrashReason(int sig, bool stackTraceIfAvailable = false, |
| 3757 |
Level level = Level::Fatal, const char* logger = base::consts::kDefaultLoggerId); |
| 3758 |
#endif |
| 3759 |
|
| 3760 |
|
| 3761 |
static inline void installPreRollOutCallback(const PreRollOutCallback& callback) { |
| 3762 |
ELPP->setPreRollOutCallback(callback); |
| 3763 |
} |
| 3764 |
|
| 3765 |
static inline void uninstallPreRollOutCallback(void) { |
| 3766 |
ELPP->unsetPreRollOutCallback(); |
| 3767 |
} |
| 3768 |
|
| 3769 |
template <typename T> |
| 3770 |
static inline bool installLogDispatchCallback(const std::string& id) { |
| 3771 |
return ELPP->installLogDispatchCallback<T>(id); |
| 3772 |
} |
| 3773 |
|
| 3774 |
template <typename T> |
| 3775 |
static inline void uninstallLogDispatchCallback(const std::string& id) { |
| 3776 |
ELPP->uninstallLogDispatchCallback<T>(id); |
| 3777 |
} |
| 3778 |
template <typename T> |
| 3779 |
static inline T* logDispatchCallback(const std::string& id) { |
| 3780 |
return ELPP->logDispatchCallback<T>(id); |
| 3781 |
} |
| 3782 |
#if defined(ELPP_FEATURE_ALL) || defined(ELPP_FEATURE_PERFORMANCE_TRACKING) |
| 3783 |
|
| 3784 |
template <typename T> |
| 3785 |
static inline bool installPerformanceTrackingCallback(const std::string& id) { |
| 3786 |
return ELPP->installPerformanceTrackingCallback<T>(id); |
| 3787 |
} |
| 3788 |
|
| 3789 |
template <typename T> |
| 3790 |
static inline void uninstallPerformanceTrackingCallback(const std::string& id) { |
| 3791 |
ELPP->uninstallPerformanceTrackingCallback<T>(id); |
| 3792 |
} |
| 3793 |
template <typename T> |
| 3794 |
static inline T* performanceTrackingCallback(const std::string& id) { |
| 3795 |
return ELPP->performanceTrackingCallback<T>(id); |
| 3796 |
} |
| 3797 |
#endif |
| 3798 |
|
| 3799 |
template <typename T> |
| 3800 |
static std::string convertTemplateToStdString(const T& templ) { |
| 3801 |
el::Logger* logger = |
| 3802 |
ELPP->registeredLoggers()->get(el::base::consts::kDefaultLoggerId); |
| 3803 |
if (logger == nullptr) { |
| 3804 |
return std::string(); |
| 3805 |
} |
| 3806 |
base::MessageBuilder b; |
| 3807 |
b.initialize(logger); |
| 3808 |
logger->acquireLock(); |
| 3809 |
b << templ; |
| 3810 |
#if defined(ELPP_UNICODE) |
| 3811 |
std::string s = std::string(logger->stream().str().begin(), logger->stream().str().end()); |
| 3812 |
#else |
| 3813 |
std::string s = logger->stream().str(); |
| 3814 |
#endif |
| 3815 |
logger->stream().str(ELPP_LITERAL("")); |
| 3816 |
logger->releaseLock(); |
| 3817 |
return s; |
| 3818 |
} |
| 3819 |
|
| 3820 |
static inline const el::base::utils::CommandLineArgs* commandLineArgs(void) { |
| 3821 |
return ELPP->commandLineArgs(); |
| 3822 |
} |
| 3823 |
|
| 3824 |
|
| 3825 |
static inline void reserveCustomFormatSpecifiers(std::size_t size) { |
| 3826 |
ELPP->m_customFormatSpecifiers.reserve(size); |
| 3827 |
} |
| 3828 |
|
| 3829 |
static inline void installCustomFormatSpecifier(const CustomFormatSpecifier& customFormatSpecifier) { |
| 3830 |
ELPP->installCustomFormatSpecifier(customFormatSpecifier); |
| 3831 |
} |
| 3832 |
|
| 3833 |
static inline bool uninstallCustomFormatSpecifier(const char* formatSpecifier) { |
| 3834 |
return ELPP->uninstallCustomFormatSpecifier(formatSpecifier); |
| 3835 |
} |
| 3836 |
|
| 3837 |
static inline bool hasCustomFormatSpecifier(const char* formatSpecifier) { |
| 3838 |
return ELPP->hasCustomFormatSpecifier(formatSpecifier); |
| 3839 |
} |
| 3840 |
static inline void validateFileRolling(Logger* logger, Level level) { |
| 3841 |
if (ELPP == nullptr || logger == nullptr) return; |
| 3842 |
logger->m_typedConfigurations->validateFileRolling(level, ELPP->preRollOutCallback()); |
| 3843 |
} |
| 3844 |
}; |
| 3845 |
|
| 3846 |
class Loggers : base::StaticClass { |
| 3847 |
public: |
| 3848 |
|
| 3849 |
static bool allowed(Level leve, const char* cat); |
| 3850 |
|
| 3851 |
static Logger* getLogger(const std::string& identity, bool registerIfNotAvailable = true); |
| 3852 |
|
| 3853 |
static void setDefaultLogBuilder(el::LogBuilderPtr& logBuilderPtr); |
| 3854 |
|
| 3855 |
template <typename T> |
| 3856 |
static inline bool installLoggerRegistrationCallback(const std::string& id) { |
| 3857 |
return ELPP->registeredLoggers()->installLoggerRegistrationCallback<T>(id); |
| 3858 |
} |
| 3859 |
|
| 3860 |
template <typename T> |
| 3861 |
static inline void uninstallLoggerRegistrationCallback(const std::string& id) { |
| 3862 |
ELPP->registeredLoggers()->uninstallLoggerRegistrationCallback<T>(id); |
| 3863 |
} |
| 3864 |
template <typename T> |
| 3865 |
static inline T* loggerRegistrationCallback(const std::string& id) { |
| 3866 |
return ELPP->registeredLoggers()->loggerRegistrationCallback<T>(id); |
| 3867 |
} |
| 3868 |
|
| 3869 |
|
| 3870 |
static bool unregisterLogger(const std::string& identity); |
| 3871 |
|
| 3872 |
static bool hasLogger(const std::string& identity); |
| 3873 |
|
| 3874 |
static Logger* reconfigureLogger(Logger* logger, const Configurations& configurations); |
| 3875 |
|
| 3876 |
static Logger* reconfigureLogger(const std::string& identity, const Configurations& configurations); |
| 3877 |
|
| 3878 |
static Logger* reconfigureLogger(const std::string& identity, ConfigurationType configurationType, |
| 3879 |
const std::string& value); |
| 3880 |
|
| 3881 |
static void reconfigureAllLoggers(const Configurations& configurations); |
| 3882 |
|
| 3883 |
static inline void reconfigureAllLoggers(ConfigurationType configurationType, const std::string& value) { |
| 3884 |
reconfigureAllLoggers(Level::Global, configurationType, value); |
| 3885 |
} |
| 3886 |
|
| 3887 |
static void reconfigureAllLoggers(Level level, ConfigurationType configurationType, |
| 3888 |
const std::string& value); |
| 3889 |
|
| 3890 |
static void setDefaultConfigurations(const Configurations& configurations, |
| 3891 |
bool reconfigureExistingLoggers = false); |
| 3892 |
|
| 3893 |
static const Configurations* defaultConfigurations(void); |
| 3894 |
|
| 3895 |
static const base::LogStreamsReferenceMap* logStreamsReference(void); |
| 3896 |
|
| 3897 |
static base::TypedConfigurations defaultTypedConfigurations(void); |
| 3898 |
|
| 3899 |
|
| 3900 |
static std::vector<std::string>* populateAllLoggerIds(std::vector<std::string>* targetList); |
| 3901 |
|
| 3902 |
static void configureFromGlobal(const char* globalConfigurationFilePath); |
| 3903 |
|
| 3904 |
|
| 3905 |
|
| 3906 |
|
| 3907 |
static bool configureFromArg(const char* argKey); |
| 3908 |
|
| 3909 |
static void flushAll(void); |
| 3910 |
|
| 3911 |
static inline void addFlag(LoggingFlag flag) { |
| 3912 |
ELPP->addFlag(flag); |
| 3913 |
} |
| 3914 |
|
| 3915 |
static inline void removeFlag(LoggingFlag flag) { |
| 3916 |
ELPP->removeFlag(flag); |
| 3917 |
} |
| 3918 |
|
| 3919 |
static inline bool hasFlag(LoggingFlag flag) { |
| 3920 |
return ELPP->hasFlag(flag); |
| 3921 |
} |
| 3922 |
|
| 3923 |
class ScopedAddFlag { |
| 3924 |
public: |
| 3925 |
ScopedAddFlag(LoggingFlag flag) : m_flag(flag) { |
| 3926 |
Loggers::addFlag(m_flag); |
| 3927 |
} |
| 3928 |
~ScopedAddFlag(void) { |
| 3929 |
Loggers::removeFlag(m_flag); |
| 3930 |
} |
| 3931 |
private: |
| 3932 |
LoggingFlag m_flag; |
| 3933 |
}; |
| 3934 |
|
| 3935 |
class ScopedRemoveFlag { |
| 3936 |
public: |
| 3937 |
ScopedRemoveFlag(LoggingFlag flag) : m_flag(flag) { |
| 3938 |
Loggers::removeFlag(m_flag); |
| 3939 |
} |
| 3940 |
~ScopedRemoveFlag(void) { |
| 3941 |
Loggers::addFlag(m_flag); |
| 3942 |
} |
| 3943 |
private: |
| 3944 |
LoggingFlag m_flag; |
| 3945 |
}; |
| 3946 |
|
| 3947 |
static void setLoggingLevel(Level level) { |
| 3948 |
ELPP->setLoggingLevel(level); |
| 3949 |
} |
| 3950 |
|
| 3951 |
static void setVerboseLevel(base::type::VerboseLevel level); |
| 3952 |
|
| 3953 |
static base::type::VerboseLevel verboseLevel(void); |
| 3954 |
|
| 3955 |
static void setVModules(const char* modules); |
| 3956 |
|
| 3957 |
static void setCategories(const char* categories, bool clear = true); |
| 3958 |
|
| 3959 |
static std::string getCategories(); |
| 3960 |
|
| 3961 |
static void clearVModules(void); |
| 3962 |
|
| 3963 |
static void clearCategories(void); |
| 3964 |
|
| 3965 |
static void setFilenameCommonPrefix(const std::string &prefix); |
| 3966 |
|
| 3967 |
static const std::string &getFilenameCommonPrefix(); |
| 3968 |
}; |
| 3969 |
class VersionInfo : base::StaticClass { |
| 3970 |
public: |
| 3971 |
|
| 3972 |
static const std::string version(void); |
| 3973 |
|
| 3974 |
|
| 3975 |
static const std::string releaseDate(void); |
| 3976 |
}; |
| 3977 |
} |
| 3978 |
#undef VLOG_IS_ON |
| 3979 |
|
| 3980 |
#define VLOG_IS_ON(verboseLevel) (ELPP->vRegistry()->allowed(verboseLevel, __FILE__)) |
| 3981 |
#undef TIMED_BLOCK |
| 3982 |
#undef TIMED_SCOPE |
| 3983 |
#undef TIMED_SCOPE_IF |
| 3984 |
#undef TIMED_FUNC |
| 3985 |
#undef TIMED_FUNC_IF |
| 3986 |
#undef ELPP_MIN_UNIT |
| 3987 |
#if defined(ELPP_PERFORMANCE_MICROSECONDS) |
| 3988 |
# define ELPP_MIN_UNIT el::base::TimestampUnit::Microsecond |
| 3989 |
#else |
| 3990 |
# define ELPP_MIN_UNIT el::base::TimestampUnit::Millisecond |
| 3991 |
#endif |
| 3992 |
|
| 3993 |
|
| 3994 |
|
| 3995 |
|
| 3996 |
|
| 3997 |
|
| 3998 |
|
| 3999 |
#define TIMED_SCOPE_IF(obj, blockname, condition) el::base::type::PerformanceTrackerPtr obj( condition ? \ |
| 4000 |
new el::base::PerformanceTracker(blockname, ELPP_MIN_UNIT) : nullptr ) |
| 4001 |
#define TIMED_SCOPE(obj, blockname) TIMED_SCOPE_IF(obj, blockname, true) |
| 4002 |
#define TIMED_BLOCK(obj, blockName) for (struct { int i; el::base::type::PerformanceTrackerPtr timer; } obj = { 0, \ |
| 4003 |
el::base::type::PerformanceTrackerPtr(new el::base::PerformanceTracker(blockName, ELPP_MIN_UNIT)) }; obj.i < 1; ++obj.i) |
| 4004 |
|
| 4005 |
|
| 4006 |
|
| 4007 |
|
| 4008 |
|
| 4009 |
|
| 4010 |
#define TIMED_FUNC_IF(obj,condition) TIMED_SCOPE_IF(obj, ELPP_FUNC, condition) |
| 4011 |
#define TIMED_FUNC(obj) TIMED_SCOPE(obj, ELPP_FUNC) |
| 4012 |
#undef PERFORMANCE_CHECKPOINT |
| 4013 |
#undef PERFORMANCE_CHECKPOINT_WITH_ID |
| 4014 |
#define PERFORMANCE_CHECKPOINT(obj) obj->checkpoint(std::string(), __FILE__, __LINE__, ELPP_FUNC) |
| 4015 |
#define PERFORMANCE_CHECKPOINT_WITH_ID(obj, id) obj->checkpoint(id, __FILE__, __LINE__, ELPP_FUNC) |
| 4016 |
#undef ELPP_COUNTER |
| 4017 |
#undef ELPP_COUNTER_POS |
| 4018 |
|
| 4019 |
#define ELPP_COUNTER (ELPP->hitCounters()->getCounter(__FILE__, __LINE__)) |
| 4020 |
|
| 4021 |
#define ELPP_COUNTER_POS (ELPP_COUNTER == nullptr ? -1 : ELPP_COUNTER->hitCounts()) |
| 4022 |
|
| 4023 |
#undef INFO |
| 4024 |
#undef WARNING |
| 4025 |
#undef DEBUG |
| 4026 |
#undef ERROR |
| 4027 |
#undef FATAL |
| 4028 |
#undef TRACE |
| 4029 |
#undef VERBOSE |
| 4030 |
|
| 4031 |
#undef CINFO |
| 4032 |
#undef CWARNING |
| 4033 |
#undef CDEBUG |
| 4034 |
#undef CFATAL |
| 4035 |
#undef CERROR |
| 4036 |
#undef CTRACE |
| 4037 |
#undef CVERBOSE |
| 4038 |
#undef CINFO_IF |
| 4039 |
#undef CWARNING_IF |
| 4040 |
#undef CDEBUG_IF |
| 4041 |
#undef CERROR_IF |
| 4042 |
#undef CFATAL_IF |
| 4043 |
#undef CTRACE_IF |
| 4044 |
#undef CVERBOSE_IF |
| 4045 |
#undef CINFO_EVERY_N |
| 4046 |
#undef CWARNING_EVERY_N |
| 4047 |
#undef CDEBUG_EVERY_N |
| 4048 |
#undef CERROR_EVERY_N |
| 4049 |
#undef CFATAL_EVERY_N |
| 4050 |
#undef CTRACE_EVERY_N |
| 4051 |
#undef CVERBOSE_EVERY_N |
| 4052 |
#undef CINFO_AFTER_N |
| 4053 |
#undef CWARNING_AFTER_N |
| 4054 |
#undef CDEBUG_AFTER_N |
| 4055 |
#undef CERROR_AFTER_N |
| 4056 |
#undef CFATAL_AFTER_N |
| 4057 |
#undef CTRACE_AFTER_N |
| 4058 |
#undef CVERBOSE_AFTER_N |
| 4059 |
#undef CINFO_N_TIMES |
| 4060 |
#undef CWARNING_N_TIMES |
| 4061 |
#undef CDEBUG_N_TIMES |
| 4062 |
#undef CERROR_N_TIMES |
| 4063 |
#undef CFATAL_N_TIMES |
| 4064 |
#undef CTRACE_N_TIMES |
| 4065 |
#undef CVERBOSE_N_TIMES |
| 4066 |
|
| 4067 |
#if ELPP_INFO_LOG |
| 4068 |
# define CINFO(writer, dispatchAction, ...) ELPP_WRITE_LOG(writer, el::Level::Info, dispatchAction, __VA_ARGS__) |
| 4069 |
#else |
| 4070 |
# define CINFO(writer, dispatchAction, ...) el::base::NullWriter() |
| 4071 |
#endif |
| 4072 |
#if ELPP_WARNING_LOG |
| 4073 |
# define CWARNING(writer, dispatchAction, ...) ELPP_WRITE_LOG(writer, el::Level::Warning, dispatchAction, __VA_ARGS__) |
| 4074 |
#else |
| 4075 |
# define CWARNING(writer, dispatchAction, ...) el::base::NullWriter() |
| 4076 |
#endif |
| 4077 |
#if ELPP_DEBUG_LOG |
| 4078 |
# define CDEBUG(writer, dispatchAction, ...) ELPP_WRITE_LOG(writer, el::Level::Debug, dispatchAction, __VA_ARGS__) |
| 4079 |
#else |
| 4080 |
# define CDEBUG(writer, dispatchAction, ...) el::base::NullWriter() |
| 4081 |
#endif |
| 4082 |
#if ELPP_ERROR_LOG |
| 4083 |
# define CERROR(writer, dispatchAction, ...) ELPP_WRITE_LOG(writer, el::Level::Error, dispatchAction, __VA_ARGS__) |
| 4084 |
#else |
| 4085 |
# define CERROR(writer, dispatchAction, ...) el::base::NullWriter() |
| 4086 |
#endif |
| 4087 |
#if ELPP_FATAL_LOG |
| 4088 |
# define CFATAL(writer, dispatchAction, ...) ELPP_WRITE_LOG(writer, el::Level::Fatal, dispatchAction, __VA_ARGS__) |
| 4089 |
#else |
| 4090 |
# define CFATAL(writer, dispatchAction, ...) el::base::NullWriter() |
| 4091 |
#endif |
| 4092 |
#if ELPP_TRACE_LOG |
| 4093 |
# define CTRACE(writer, dispatchAction, ...) ELPP_WRITE_LOG(writer, el::Level::Trace, dispatchAction, __VA_ARGS__) |
| 4094 |
#else |
| 4095 |
# define CTRACE(writer, dispatchAction, ...) el::base::NullWriter() |
| 4096 |
#endif |
| 4097 |
#if ELPP_VERBOSE_LOG |
| 4098 |
# define CVERBOSE(writer, vlevel, dispatchAction, ...) if (VLOG_IS_ON(vlevel)) writer(\ |
| 4099 |
el::Level::Verbose, __FILE__, __LINE__, ELPP_FUNC, dispatchAction, vlevel).construct(el_getVALength(__VA_ARGS__), __VA_ARGS__) |
| 4100 |
#else |
| 4101 |
# define CVERBOSE(writer, vlevel, dispatchAction, ...) el::base::NullWriter() |
| 4102 |
#endif |
| 4103 |
|
| 4104 |
#if ELPP_INFO_LOG |
| 4105 |
# define CINFO_IF(writer, condition_, dispatchAction, ...) \ |
| 4106 |
ELPP_WRITE_LOG_IF(writer, (condition_), el::Level::Info, dispatchAction, __VA_ARGS__) |
| 4107 |
#else |
| 4108 |
# define CINFO_IF(writer, condition_, dispatchAction, ...) el::base::NullWriter() |
| 4109 |
#endif |
| 4110 |
#if ELPP_WARNING_LOG |
| 4111 |
# define CWARNING_IF(writer, condition_, dispatchAction, ...)\ |
| 4112 |
ELPP_WRITE_LOG_IF(writer, (condition_), el::Level::Warning, dispatchAction, __VA_ARGS__) |
| 4113 |
#else |
| 4114 |
# define CWARNING_IF(writer, condition_, dispatchAction, ...) el::base::NullWriter() |
| 4115 |
#endif |
| 4116 |
#if ELPP_DEBUG_LOG |
| 4117 |
# define CDEBUG_IF(writer, condition_, dispatchAction, ...)\ |
| 4118 |
ELPP_WRITE_LOG_IF(writer, (condition_), el::Level::Debug, dispatchAction, __VA_ARGS__) |
| 4119 |
#else |
| 4120 |
# define CDEBUG_IF(writer, condition_, dispatchAction, ...) el::base::NullWriter() |
| 4121 |
#endif |
| 4122 |
#if ELPP_ERROR_LOG |
| 4123 |
# define CERROR_IF(writer, condition_, dispatchAction, ...)\ |
| 4124 |
ELPP_WRITE_LOG_IF(writer, (condition_), el::Level::Error, dispatchAction, __VA_ARGS__) |
| 4125 |
#else |
| 4126 |
# define CERROR_IF(writer, condition_, dispatchAction, ...) el::base::NullWriter() |
| 4127 |
#endif |
| 4128 |
#if ELPP_FATAL_LOG |
| 4129 |
# define CFATAL_IF(writer, condition_, dispatchAction, ...)\ |
| 4130 |
ELPP_WRITE_LOG_IF(writer, (condition_), el::Level::Fatal, dispatchAction, __VA_ARGS__) |
| 4131 |
#else |
| 4132 |
# define CFATAL_IF(writer, condition_, dispatchAction, ...) el::base::NullWriter() |
| 4133 |
#endif |
| 4134 |
#if ELPP_TRACE_LOG |
| 4135 |
# define CTRACE_IF(writer, condition_, dispatchAction, ...)\ |
| 4136 |
ELPP_WRITE_LOG_IF(writer, (condition_), el::Level::Trace, dispatchAction, __VA_ARGS__) |
| 4137 |
#else |
| 4138 |
# define CTRACE_IF(writer, condition_, dispatchAction, ...) el::base::NullWriter() |
| 4139 |
#endif |
| 4140 |
#if ELPP_VERBOSE_LOG |
| 4141 |
# define CVERBOSE_IF(writer, condition_, vlevel, dispatchAction, ...) if (VLOG_IS_ON(vlevel) && (condition_)) writer( \ |
| 4142 |
el::Level::Verbose, __FILE__, __LINE__, ELPP_FUNC, dispatchAction, vlevel).construct(el_getVALength(__VA_ARGS__), __VA_ARGS__) |
| 4143 |
#else |
| 4144 |
# define CVERBOSE_IF(writer, condition_, vlevel, dispatchAction, ...) el::base::NullWriter() |
| 4145 |
#endif |
| 4146 |
|
| 4147 |
#if ELPP_INFO_LOG |
| 4148 |
# define CINFO_EVERY_N(writer, occasion, dispatchAction, ...)\ |
| 4149 |
ELPP_WRITE_LOG_EVERY_N(writer, occasion, el::Level::Info, dispatchAction, __VA_ARGS__) |
| 4150 |
#else |
| 4151 |
# define CINFO_EVERY_N(writer, occasion, dispatchAction, ...) el::base::NullWriter() |
| 4152 |
#endif |
| 4153 |
#if ELPP_WARNING_LOG |
| 4154 |
# define CWARNING_EVERY_N(writer, occasion, dispatchAction, ...)\ |
| 4155 |
ELPP_WRITE_LOG_EVERY_N(writer, occasion, el::Level::Warning, dispatchAction, __VA_ARGS__) |
| 4156 |
#else |
| 4157 |
# define CWARNING_EVERY_N(writer, occasion, dispatchAction, ...) el::base::NullWriter() |
| 4158 |
#endif |
| 4159 |
#if ELPP_DEBUG_LOG |
| 4160 |
# define CDEBUG_EVERY_N(writer, occasion, dispatchAction, ...)\ |
| 4161 |
ELPP_WRITE_LOG_EVERY_N(writer, occasion, el::Level::Debug, dispatchAction, __VA_ARGS__) |
| 4162 |
#else |
| 4163 |
# define CDEBUG_EVERY_N(writer, occasion, dispatchAction, ...) el::base::NullWriter() |
| 4164 |
#endif |
| 4165 |
#if ELPP_ERROR_LOG |
| 4166 |
# define CERROR_EVERY_N(writer, occasion, dispatchAction, ...)\ |
| 4167 |
ELPP_WRITE_LOG_EVERY_N(writer, occasion, el::Level::Error, dispatchAction, __VA_ARGS__) |
| 4168 |
#else |
| 4169 |
# define CERROR_EVERY_N(writer, occasion, dispatchAction, ...) el::base::NullWriter() |
| 4170 |
#endif |
| 4171 |
#if ELPP_FATAL_LOG |
| 4172 |
# define CFATAL_EVERY_N(writer, occasion, dispatchAction, ...)\ |
| 4173 |
ELPP_WRITE_LOG_EVERY_N(writer, occasion, el::Level::Fatal, dispatchAction, __VA_ARGS__) |
| 4174 |
#else |
| 4175 |
# define CFATAL_EVERY_N(writer, occasion, dispatchAction, ...) el::base::NullWriter() |
| 4176 |
#endif |
| 4177 |
#if ELPP_TRACE_LOG |
| 4178 |
# define CTRACE_EVERY_N(writer, occasion, dispatchAction, ...)\ |
| 4179 |
ELPP_WRITE_LOG_EVERY_N(writer, occasion, el::Level::Trace, dispatchAction, __VA_ARGS__) |
| 4180 |
#else |
| 4181 |
# define CTRACE_EVERY_N(writer, occasion, dispatchAction, ...) el::base::NullWriter() |
| 4182 |
#endif |
| 4183 |
#if ELPP_VERBOSE_LOG |
| 4184 |
# define CVERBOSE_EVERY_N(writer, occasion, vlevel, dispatchAction, ...)\ |
| 4185 |
CVERBOSE_IF(writer, ELPP->validateEveryNCounter(__FILE__, __LINE__, occasion), vlevel, dispatchAction, __VA_ARGS__) |
| 4186 |
#else |
| 4187 |
# define CVERBOSE_EVERY_N(writer, occasion, vlevel, dispatchAction, ...) el::base::NullWriter() |
| 4188 |
#endif |
| 4189 |
|
| 4190 |
#if ELPP_INFO_LOG |
| 4191 |
# define CINFO_AFTER_N(writer, n, dispatchAction, ...)\ |
| 4192 |
ELPP_WRITE_LOG_AFTER_N(writer, n, el::Level::Info, dispatchAction, __VA_ARGS__) |
| 4193 |
#else |
| 4194 |
# define CINFO_AFTER_N(writer, n, dispatchAction, ...) el::base::NullWriter() |
| 4195 |
#endif |
| 4196 |
#if ELPP_WARNING_LOG |
| 4197 |
# define CWARNING_AFTER_N(writer, n, dispatchAction, ...)\ |
| 4198 |
ELPP_WRITE_LOG_AFTER_N(writer, n, el::Level::Warning, dispatchAction, __VA_ARGS__) |
| 4199 |
#else |
| 4200 |
# define CWARNING_AFTER_N(writer, n, dispatchAction, ...) el::base::NullWriter() |
| 4201 |
#endif |
| 4202 |
#if ELPP_DEBUG_LOG |
| 4203 |
# define CDEBUG_AFTER_N(writer, n, dispatchAction, ...)\ |
| 4204 |
ELPP_WRITE_LOG_AFTER_N(writer, n, el::Level::Debug, dispatchAction, __VA_ARGS__) |
| 4205 |
#else |
| 4206 |
# define CDEBUG_AFTER_N(writer, n, dispatchAction, ...) el::base::NullWriter() |
| 4207 |
#endif |
| 4208 |
#if ELPP_ERROR_LOG |
| 4209 |
# define CERROR_AFTER_N(writer, n, dispatchAction, ...)\ |
| 4210 |
ELPP_WRITE_LOG_AFTER_N(writer, n, el::Level::Error, dispatchAction, __VA_ARGS__) |
| 4211 |
#else |
| 4212 |
# define CERROR_AFTER_N(writer, n, dispatchAction, ...) el::base::NullWriter() |
| 4213 |
#endif |
| 4214 |
#if ELPP_FATAL_LOG |
| 4215 |
# define CFATAL_AFTER_N(writer, n, dispatchAction, ...)\ |
| 4216 |
ELPP_WRITE_LOG_AFTER_N(writer, n, el::Level::Fatal, dispatchAction, __VA_ARGS__) |
| 4217 |
#else |
| 4218 |
# define CFATAL_AFTER_N(writer, n, dispatchAction, ...) el::base::NullWriter() |
| 4219 |
#endif |
| 4220 |
#if ELPP_TRACE_LOG |
| 4221 |
# define CTRACE_AFTER_N(writer, n, dispatchAction, ...)\ |
| 4222 |
ELPP_WRITE_LOG_AFTER_N(writer, n, el::Level::Trace, dispatchAction, __VA_ARGS__) |
| 4223 |
#else |
| 4224 |
# define CTRACE_AFTER_N(writer, n, dispatchAction, ...) el::base::NullWriter() |
| 4225 |
#endif |
| 4226 |
#if ELPP_VERBOSE_LOG |
| 4227 |
# define CVERBOSE_AFTER_N(writer, n, vlevel, dispatchAction, ...)\ |
| 4228 |
CVERBOSE_IF(writer, ELPP->validateAfterNCounter(__FILE__, __LINE__, n), vlevel, dispatchAction, __VA_ARGS__) |
| 4229 |
#else |
| 4230 |
# define CVERBOSE_AFTER_N(writer, n, vlevel, dispatchAction, ...) el::base::NullWriter() |
| 4231 |
#endif |
| 4232 |
|
| 4233 |
#if ELPP_INFO_LOG |
| 4234 |
# define CINFO_N_TIMES(writer, n, dispatchAction, ...)\ |
| 4235 |
ELPP_WRITE_LOG_N_TIMES(writer, n, el::Level::Info, dispatchAction, __VA_ARGS__) |
| 4236 |
#else |
| 4237 |
# define CINFO_N_TIMES(writer, n, dispatchAction, ...) el::base::NullWriter() |
| 4238 |
#endif |
| 4239 |
#if ELPP_WARNING_LOG |
| 4240 |
# define CWARNING_N_TIMES(writer, n, dispatchAction, ...)\ |
| 4241 |
ELPP_WRITE_LOG_N_TIMES(writer, n, el::Level::Warning, dispatchAction, __VA_ARGS__) |
| 4242 |
#else |
| 4243 |
# define CWARNING_N_TIMES(writer, n, dispatchAction, ...) el::base::NullWriter() |
| 4244 |
#endif |
| 4245 |
#if ELPP_DEBUG_LOG |
| 4246 |
# define CDEBUG_N_TIMES(writer, n, dispatchAction, ...)\ |
| 4247 |
ELPP_WRITE_LOG_N_TIMES(writer, n, el::Level::Debug, dispatchAction, __VA_ARGS__) |
| 4248 |
#else |
| 4249 |
# define CDEBUG_N_TIMES(writer, n, dispatchAction, ...) el::base::NullWriter() |
| 4250 |
#endif |
| 4251 |
#if ELPP_ERROR_LOG |
| 4252 |
# define CERROR_N_TIMES(writer, n, dispatchAction, ...)\ |
| 4253 |
ELPP_WRITE_LOG_N_TIMES(writer, n, el::Level::Error, dispatchAction, __VA_ARGS__) |
| 4254 |
#else |
| 4255 |
# define CERROR_N_TIMES(writer, n, dispatchAction, ...) el::base::NullWriter() |
| 4256 |
#endif |
| 4257 |
#if ELPP_FATAL_LOG |
| 4258 |
# define CFATAL_N_TIMES(writer, n, dispatchAction, ...)\ |
| 4259 |
ELPP_WRITE_LOG_N_TIMES(writer, n, el::Level::Fatal, dispatchAction, __VA_ARGS__) |
| 4260 |
#else |
| 4261 |
# define CFATAL_N_TIMES(writer, n, dispatchAction, ...) el::base::NullWriter() |
| 4262 |
#endif |
| 4263 |
#if ELPP_TRACE_LOG |
| 4264 |
# define CTRACE_N_TIMES(writer, n, dispatchAction, ...)\ |
| 4265 |
ELPP_WRITE_LOG_N_TIMES(writer, n, el::Level::Trace, dispatchAction, __VA_ARGS__) |
| 4266 |
#else |
| 4267 |
# define CTRACE_N_TIMES(writer, n, dispatchAction, ...) el::base::NullWriter() |
| 4268 |
#endif |
| 4269 |
#if ELPP_VERBOSE_LOG |
| 4270 |
# define CVERBOSE_N_TIMES(writer, n, vlevel, dispatchAction, ...)\ |
| 4271 |
CVERBOSE_IF(writer, ELPP->validateNTimesCounter(__FILE__, __LINE__, n), vlevel, dispatchAction, __VA_ARGS__) |
| 4272 |
#else |
| 4273 |
# define CVERBOSE_N_TIMES(writer, n, vlevel, dispatchAction, ...) el::base::NullWriter() |
| 4274 |
#endif |
| 4275 |
|
| 4276 |
|
| 4277 |
|
| 4278 |
|
| 4279 |
#undef CLOG |
| 4280 |
#undef CLOG_VERBOSE |
| 4281 |
#undef CVLOG |
| 4282 |
#undef CLOG_IF |
| 4283 |
#undef CLOG_VERBOSE_IF |
| 4284 |
#undef CVLOG_IF |
| 4285 |
#undef CLOG_EVERY_N |
| 4286 |
#undef CVLOG_EVERY_N |
| 4287 |
#undef CLOG_AFTER_N |
| 4288 |
#undef CVLOG_AFTER_N |
| 4289 |
#undef CLOG_N_TIMES |
| 4290 |
#undef CVLOG_N_TIMES |
| 4291 |
|
| 4292 |
#define CLOG(LEVEL, ...)\ |
| 4293 |
C##LEVEL(el::base::Writer, el::base::DispatchAction::NormalLog, __VA_ARGS__) |
| 4294 |
#define CVLOG(vlevel, ...) CVERBOSE(el::base::Writer, vlevel, el::base::DispatchAction::NormalLog, __VA_ARGS__) |
| 4295 |
|
| 4296 |
#define CLOG_IF(condition, LEVEL, ...)\ |
| 4297 |
C##LEVEL##_IF(el::base::Writer, condition, el::base::DispatchAction::NormalLog, __VA_ARGS__) |
| 4298 |
#define CVLOG_IF(condition, vlevel, ...)\ |
| 4299 |
CVERBOSE_IF(el::base::Writer, condition, vlevel, el::base::DispatchAction::NormalLog, __VA_ARGS__) |
| 4300 |
|
| 4301 |
#define CLOG_EVERY_N(n, LEVEL, ...)\ |
| 4302 |
C##LEVEL##_EVERY_N(el::base::Writer, n, el::base::DispatchAction::NormalLog, __VA_ARGS__) |
| 4303 |
#define CVLOG_EVERY_N(n, vlevel, ...)\ |
| 4304 |
CVERBOSE_EVERY_N(el::base::Writer, n, vlevel, el::base::DispatchAction::NormalLog, __VA_ARGS__) |
| 4305 |
#define CLOG_AFTER_N(n, LEVEL, ...)\ |
| 4306 |
C##LEVEL##_AFTER_N(el::base::Writer, n, el::base::DispatchAction::NormalLog, __VA_ARGS__) |
| 4307 |
#define CVLOG_AFTER_N(n, vlevel, ...)\ |
| 4308 |
CVERBOSE_AFTER_N(el::base::Writer, n, vlevel, el::base::DispatchAction::NormalLog, __VA_ARGS__) |
| 4309 |
#define CLOG_N_TIMES(n, LEVEL, ...)\ |
| 4310 |
C##LEVEL##_N_TIMES(el::base::Writer, n, el::base::DispatchAction::NormalLog, __VA_ARGS__) |
| 4311 |
#define CVLOG_N_TIMES(n, vlevel, ...)\ |
| 4312 |
CVERBOSE_N_TIMES(el::base::Writer, n, vlevel, el::base::DispatchAction::NormalLog, __VA_ARGS__) |
| 4313 |
|
| 4314 |
|
| 4315 |
|
| 4316 |
|
| 4317 |
#undef LOG |
| 4318 |
#undef VLOG |
| 4319 |
#undef LOG_IF |
| 4320 |
#undef VLOG_IF |
| 4321 |
#undef LOG_EVERY_N |
| 4322 |
#undef VLOG_EVERY_N |
| 4323 |
#undef LOG_AFTER_N |
| 4324 |
#undef VLOG_AFTER_N |
| 4325 |
#undef LOG_N_TIMES |
| 4326 |
#undef VLOG_N_TIMES |
| 4327 |
#undef ELPP_CURR_FILE_LOGGER_ID |
| 4328 |
#if defined(ELPP_DEFAULT_LOGGER) |
| 4329 |
# define ELPP_CURR_FILE_LOGGER_ID ELPP_DEFAULT_LOGGER |
| 4330 |
#else |
| 4331 |
# define ELPP_CURR_FILE_LOGGER_ID el::base::consts::kDefaultLoggerId |
| 4332 |
#endif |
| 4333 |
#undef ELPP_TRACE |
| 4334 |
#define ELPP_TRACE CLOG(TRACE, ELPP_CURR_FILE_LOGGER_ID) |
| 4335 |
|
| 4336 |
#define LOG(LEVEL) CLOG(LEVEL, ELPP_CURR_FILE_LOGGER_ID) |
| 4337 |
#define VLOG(vlevel) CVLOG(vlevel, ELPP_CURR_FILE_LOGGER_ID) |
| 4338 |
|
| 4339 |
#define LOG_IF(condition, LEVEL) CLOG_IF(condition, LEVEL, ELPP_CURR_FILE_LOGGER_ID) |
| 4340 |
#define VLOG_IF(condition, vlevel) CVLOG_IF(condition, vlevel, ELPP_CURR_FILE_LOGGER_ID) |
| 4341 |
|
| 4342 |
#define LOG_EVERY_N(n, LEVEL) CLOG_EVERY_N(n, LEVEL, ELPP_CURR_FILE_LOGGER_ID) |
| 4343 |
#define VLOG_EVERY_N(n, vlevel) CVLOG_EVERY_N(n, vlevel, ELPP_CURR_FILE_LOGGER_ID) |
| 4344 |
#define LOG_AFTER_N(n, LEVEL) CLOG_AFTER_N(n, LEVEL, ELPP_CURR_FILE_LOGGER_ID) |
| 4345 |
#define VLOG_AFTER_N(n, vlevel) CVLOG_AFTER_N(n, vlevel, ELPP_CURR_FILE_LOGGER_ID) |
| 4346 |
#define LOG_N_TIMES(n, LEVEL) CLOG_N_TIMES(n, LEVEL, ELPP_CURR_FILE_LOGGER_ID) |
| 4347 |
#define VLOG_N_TIMES(n, vlevel) CVLOG_N_TIMES(n, vlevel, ELPP_CURR_FILE_LOGGER_ID) |
| 4348 |
|
| 4349 |
#undef CPLOG |
| 4350 |
#undef CPLOG_IF |
| 4351 |
#undef PLOG |
| 4352 |
#undef PLOG_IF |
| 4353 |
#undef DCPLOG |
| 4354 |
#undef DCPLOG_IF |
| 4355 |
#undef DPLOG |
| 4356 |
#undef DPLOG_IF |
| 4357 |
#define CPLOG(LEVEL, ...)\ |
| 4358 |
C##LEVEL(el::base::PErrorWriter, el::base::DispatchAction::NormalLog, __VA_ARGS__) |
| 4359 |
#define CPLOG_IF(condition, LEVEL, ...)\ |
| 4360 |
C##LEVEL##_IF(el::base::PErrorWriter, condition, el::base::DispatchAction::NormalLog, __VA_ARGS__) |
| 4361 |
#define DCPLOG(LEVEL, ...)\ |
| 4362 |
if (ELPP_DEBUG_LOG) C##LEVEL(el::base::PErrorWriter, el::base::DispatchAction::NormalLog, __VA_ARGS__) |
| 4363 |
#define DCPLOG_IF(condition, LEVEL, ...)\ |
| 4364 |
C##LEVEL##_IF(el::base::PErrorWriter, (ELPP_DEBUG_LOG) && (condition), el::base::DispatchAction::NormalLog, __VA_ARGS__) |
| 4365 |
#define PLOG(LEVEL) CPLOG(LEVEL, ELPP_CURR_FILE_LOGGER_ID) |
| 4366 |
#define PLOG_IF(condition, LEVEL) CPLOG_IF(condition, LEVEL, ELPP_CURR_FILE_LOGGER_ID) |
| 4367 |
#define DPLOG(LEVEL) DCPLOG(LEVEL, ELPP_CURR_FILE_LOGGER_ID) |
| 4368 |
#define DPLOG_IF(condition, LEVEL) DCPLOG_IF(condition, LEVEL, ELPP_CURR_FILE_LOGGER_ID) |
| 4369 |
|
| 4370 |
#undef CSYSLOG |
| 4371 |
#undef CSYSLOG_IF |
| 4372 |
#undef CSYSLOG_EVERY_N |
| 4373 |
#undef CSYSLOG_AFTER_N |
| 4374 |
#undef CSYSLOG_N_TIMES |
| 4375 |
#undef SYSLOG |
| 4376 |
#undef SYSLOG_IF |
| 4377 |
#undef SYSLOG_EVERY_N |
| 4378 |
#undef SYSLOG_AFTER_N |
| 4379 |
#undef SYSLOG_N_TIMES |
| 4380 |
#undef DCSYSLOG |
| 4381 |
#undef DCSYSLOG_IF |
| 4382 |
#undef DCSYSLOG_EVERY_N |
| 4383 |
#undef DCSYSLOG_AFTER_N |
| 4384 |
#undef DCSYSLOG_N_TIMES |
| 4385 |
#undef DSYSLOG |
| 4386 |
#undef DSYSLOG_IF |
| 4387 |
#undef DSYSLOG_EVERY_N |
| 4388 |
#undef DSYSLOG_AFTER_N |
| 4389 |
#undef DSYSLOG_N_TIMES |
| 4390 |
#if defined(ELPP_SYSLOG) |
| 4391 |
# define CSYSLOG(LEVEL, ...)\ |
| 4392 |
C##LEVEL(el::base::Writer, el::base::DispatchAction::SysLog, __VA_ARGS__) |
| 4393 |
# define CSYSLOG_IF(condition, LEVEL, ...)\ |
| 4394 |
C##LEVEL##_IF(el::base::Writer, condition, el::base::DispatchAction::SysLog, __VA_ARGS__) |
| 4395 |
# define CSYSLOG_EVERY_N(n, LEVEL, ...) C##LEVEL##_EVERY_N(el::base::Writer, n, el::base::DispatchAction::SysLog, __VA_ARGS__) |
| 4396 |
# define CSYSLOG_AFTER_N(n, LEVEL, ...) C##LEVEL##_AFTER_N(el::base::Writer, n, el::base::DispatchAction::SysLog, __VA_ARGS__) |
| 4397 |
# define CSYSLOG_N_TIMES(n, LEVEL, ...) C##LEVEL##_N_TIMES(el::base::Writer, n, el::base::DispatchAction::SysLog, __VA_ARGS__) |
| 4398 |
# define SYSLOG(LEVEL) CSYSLOG(LEVEL, el::base::consts::kSysLogLoggerId) |
| 4399 |
# define SYSLOG_IF(condition, LEVEL) CSYSLOG_IF(condition, LEVEL, el::base::consts::kSysLogLoggerId) |
| 4400 |
# define SYSLOG_EVERY_N(n, LEVEL) CSYSLOG_EVERY_N(n, LEVEL, el::base::consts::kSysLogLoggerId) |
| 4401 |
# define SYSLOG_AFTER_N(n, LEVEL) CSYSLOG_AFTER_N(n, LEVEL, el::base::consts::kSysLogLoggerId) |
| 4402 |
# define SYSLOG_N_TIMES(n, LEVEL) CSYSLOG_N_TIMES(n, LEVEL, el::base::consts::kSysLogLoggerId) |
| 4403 |
# define DCSYSLOG(LEVEL, ...) if (ELPP_DEBUG_LOG) C##LEVEL(el::base::Writer, el::base::DispatchAction::SysLog, __VA_ARGS__) |
| 4404 |
# define DCSYSLOG_IF(condition, LEVEL, ...)\ |
| 4405 |
C##LEVEL##_IF(el::base::Writer, (ELPP_DEBUG_LOG) && (condition), el::base::DispatchAction::SysLog, __VA_ARGS__) |
| 4406 |
# define DCSYSLOG_EVERY_N(n, LEVEL, ...)\ |
| 4407 |
if (ELPP_DEBUG_LOG) C##LEVEL##_EVERY_N(el::base::Writer, n, el::base::DispatchAction::SysLog, __VA_ARGS__) |
| 4408 |
# define DCSYSLOG_AFTER_N(n, LEVEL, ...)\ |
| 4409 |
if (ELPP_DEBUG_LOG) C##LEVEL##_AFTER_N(el::base::Writer, n, el::base::DispatchAction::SysLog, __VA_ARGS__) |
| 4410 |
# define DCSYSLOG_N_TIMES(n, LEVEL, ...)\ |
| 4411 |
if (ELPP_DEBUG_LOG) C##LEVEL##_EVERY_N(el::base::Writer, n, el::base::DispatchAction::SysLog, __VA_ARGS__) |
| 4412 |
# define DSYSLOG(LEVEL) DCSYSLOG(LEVEL, el::base::consts::kSysLogLoggerId) |
| 4413 |
# define DSYSLOG_IF(condition, LEVEL) DCSYSLOG_IF(condition, LEVEL, el::base::consts::kSysLogLoggerId) |
| 4414 |
# define DSYSLOG_EVERY_N(n, LEVEL) DCSYSLOG_EVERY_N(n, LEVEL, el::base::consts::kSysLogLoggerId) |
| 4415 |
# define DSYSLOG_AFTER_N(n, LEVEL) DCSYSLOG_AFTER_N(n, LEVEL, el::base::consts::kSysLogLoggerId) |
| 4416 |
# define DSYSLOG_N_TIMES(n, LEVEL) DCSYSLOG_N_TIMES(n, LEVEL, el::base::consts::kSysLogLoggerId) |
| 4417 |
#else |
| 4418 |
# define CSYSLOG(LEVEL, ...) el::base::NullWriter() |
| 4419 |
# define CSYSLOG_IF(condition, LEVEL, ...) el::base::NullWriter() |
| 4420 |
# define CSYSLOG_EVERY_N(n, LEVEL, ...) el::base::NullWriter() |
| 4421 |
# define CSYSLOG_AFTER_N(n, LEVEL, ...) el::base::NullWriter() |
| 4422 |
# define CSYSLOG_N_TIMES(n, LEVEL, ...) el::base::NullWriter() |
| 4423 |
# define SYSLOG(LEVEL) el::base::NullWriter() |
| 4424 |
# define SYSLOG_IF(condition, LEVEL) el::base::NullWriter() |
| 4425 |
# define SYSLOG_EVERY_N(n, LEVEL) el::base::NullWriter() |
| 4426 |
# define SYSLOG_AFTER_N(n, LEVEL) el::base::NullWriter() |
| 4427 |
# define SYSLOG_N_TIMES(n, LEVEL) el::base::NullWriter() |
| 4428 |
# define DCSYSLOG(LEVEL, ...) el::base::NullWriter() |
| 4429 |
# define DCSYSLOG_IF(condition, LEVEL, ...) el::base::NullWriter() |
| 4430 |
# define DCSYSLOG_EVERY_N(n, LEVEL, ...) el::base::NullWriter() |
| 4431 |
# define DCSYSLOG_AFTER_N(n, LEVEL, ...) el::base::NullWriter() |
| 4432 |
# define DCSYSLOG_N_TIMES(n, LEVEL, ...) el::base::NullWriter() |
| 4433 |
# define DSYSLOG(LEVEL) el::base::NullWriter() |
| 4434 |
# define DSYSLOG_IF(condition, LEVEL) el::base::NullWriter() |
| 4435 |
# define DSYSLOG_EVERY_N(n, LEVEL) el::base::NullWriter() |
| 4436 |
# define DSYSLOG_AFTER_N(n, LEVEL) el::base::NullWriter() |
| 4437 |
# define DSYSLOG_N_TIMES(n, LEVEL) el::base::NullWriter() |
| 4438 |
#endif |
| 4439 |
|
| 4440 |
|
| 4441 |
|
| 4442 |
|
| 4443 |
#undef DCLOG |
| 4444 |
#undef DCVLOG |
| 4445 |
#undef DCLOG_IF |
| 4446 |
#undef DCVLOG_IF |
| 4447 |
#undef DCLOG_EVERY_N |
| 4448 |
#undef DCVLOG_EVERY_N |
| 4449 |
#undef DCLOG_AFTER_N |
| 4450 |
#undef DCVLOG_AFTER_N |
| 4451 |
#undef DCLOG_N_TIMES |
| 4452 |
#undef DCVLOG_N_TIMES |
| 4453 |
|
| 4454 |
#define DCLOG(LEVEL, ...) if (ELPP_DEBUG_LOG) CLOG(LEVEL, __VA_ARGS__) |
| 4455 |
#define DCLOG_VERBOSE(vlevel, ...) if (ELPP_DEBUG_LOG) CLOG_VERBOSE(vlevel, __VA_ARGS__) |
| 4456 |
#define DCVLOG(vlevel, ...) if (ELPP_DEBUG_LOG) CVLOG(vlevel, __VA_ARGS__) |
| 4457 |
|
| 4458 |
#define DCLOG_IF(condition, LEVEL, ...) if (ELPP_DEBUG_LOG) CLOG_IF(condition, LEVEL, __VA_ARGS__) |
| 4459 |
#define DCVLOG_IF(condition, vlevel, ...) if (ELPP_DEBUG_LOG) CVLOG_IF(condition, vlevel, __VA_ARGS__) |
| 4460 |
|
| 4461 |
#define DCLOG_EVERY_N(n, LEVEL, ...) if (ELPP_DEBUG_LOG) CLOG_EVERY_N(n, LEVEL, __VA_ARGS__) |
| 4462 |
#define DCVLOG_EVERY_N(n, vlevel, ...) if (ELPP_DEBUG_LOG) CVLOG_EVERY_N(n, vlevel, __VA_ARGS__) |
| 4463 |
#define DCLOG_AFTER_N(n, LEVEL, ...) if (ELPP_DEBUG_LOG) CLOG_AFTER_N(n, LEVEL, __VA_ARGS__) |
| 4464 |
#define DCVLOG_AFTER_N(n, vlevel, ...) if (ELPP_DEBUG_LOG) CVLOG_AFTER_N(n, vlevel, __VA_ARGS__) |
| 4465 |
#define DCLOG_N_TIMES(n, LEVEL, ...) if (ELPP_DEBUG_LOG) CLOG_N_TIMES(n, LEVEL, __VA_ARGS__) |
| 4466 |
#define DCVLOG_N_TIMES(n, vlevel, ...) if (ELPP_DEBUG_LOG) CVLOG_N_TIMES(n, vlevel, __VA_ARGS__) |
| 4467 |
|
| 4468 |
|
| 4469 |
|
| 4470 |
#if !defined(ELPP_NO_DEBUG_MACROS) |
| 4471 |
|
| 4472 |
#undef DLOG |
| 4473 |
#undef DVLOG |
| 4474 |
#undef DLOG_IF |
| 4475 |
#undef DVLOG_IF |
| 4476 |
#undef DLOG_EVERY_N |
| 4477 |
#undef DVLOG_EVERY_N |
| 4478 |
#undef DLOG_AFTER_N |
| 4479 |
#undef DVLOG_AFTER_N |
| 4480 |
#undef DLOG_N_TIMES |
| 4481 |
#undef DVLOG_N_TIMES |
| 4482 |
|
| 4483 |
#define DLOG(LEVEL) DCLOG(LEVEL, ELPP_CURR_FILE_LOGGER_ID) |
| 4484 |
#define DVLOG(vlevel) DCVLOG(vlevel, ELPP_CURR_FILE_LOGGER_ID) |
| 4485 |
|
| 4486 |
#define DLOG_IF(condition, LEVEL) DCLOG_IF(condition, LEVEL, ELPP_CURR_FILE_LOGGER_ID) |
| 4487 |
#define DVLOG_IF(condition, vlevel) DCVLOG_IF(condition, vlevel, ELPP_CURR_FILE_LOGGER_ID) |
| 4488 |
|
| 4489 |
#define DLOG_EVERY_N(n, LEVEL) DCLOG_EVERY_N(n, LEVEL, ELPP_CURR_FILE_LOGGER_ID) |
| 4490 |
#define DVLOG_EVERY_N(n, vlevel) DCVLOG_EVERY_N(n, vlevel, ELPP_CURR_FILE_LOGGER_ID) |
| 4491 |
#define DLOG_AFTER_N(n, LEVEL) DCLOG_AFTER_N(n, LEVEL, ELPP_CURR_FILE_LOGGER_ID) |
| 4492 |
#define DVLOG_AFTER_N(n, vlevel) DCVLOG_AFTER_N(n, vlevel, ELPP_CURR_FILE_LOGGER_ID) |
| 4493 |
#define DLOG_N_TIMES(n, LEVEL) DCLOG_N_TIMES(n, LEVEL, ELPP_CURR_FILE_LOGGER_ID) |
| 4494 |
#define DVLOG_N_TIMES(n, vlevel) DCVLOG_N_TIMES(n, vlevel, ELPP_CURR_FILE_LOGGER_ID) |
| 4495 |
#endif |
| 4496 |
#if !defined(ELPP_NO_CHECK_MACROS) |
| 4497 |
|
| 4498 |
#undef CCHECK |
| 4499 |
#undef CPCHECK |
| 4500 |
#undef CCHECK_EQ |
| 4501 |
#undef CCHECK_NE |
| 4502 |
#undef CCHECK_LT |
| 4503 |
#undef CCHECK_GT |
| 4504 |
#undef CCHECK_LE |
| 4505 |
#undef CCHECK_GE |
| 4506 |
#undef CCHECK_BOUNDS |
| 4507 |
#undef CCHECK_NOTNULL |
| 4508 |
#undef CCHECK_STRCASEEQ |
| 4509 |
#undef CCHECK_STRCASENE |
| 4510 |
#undef CHECK |
| 4511 |
#undef PCHECK |
| 4512 |
#undef CHECK_EQ |
| 4513 |
#undef CHECK_NE |
| 4514 |
#undef CHECK_LT |
| 4515 |
#undef CHECK_GT |
| 4516 |
#undef CHECK_LE |
| 4517 |
#undef CHECK_GE |
| 4518 |
#undef CHECK_BOUNDS |
| 4519 |
#undef CHECK_NOTNULL |
| 4520 |
#undef CHECK_STRCASEEQ |
| 4521 |
#undef CHECK_STRCASENE |
| 4522 |
#define CCHECK(condition, ...) CLOG_IF(!(condition), FATAL, __VA_ARGS__) << "Check failed: [" << #condition << "] " |
| 4523 |
#define CPCHECK(condition, ...) CPLOG_IF(!(condition), FATAL, __VA_ARGS__) << "Check failed: [" << #condition << "] " |
| 4524 |
#define CHECK(condition) CCHECK(condition, ELPP_CURR_FILE_LOGGER_ID) |
| 4525 |
#define PCHECK(condition) CPCHECK(condition, ELPP_CURR_FILE_LOGGER_ID) |
| 4526 |
#define CCHECK_EQ(a, b, ...) CCHECK(a == b, __VA_ARGS__) |
| 4527 |
#define CCHECK_NE(a, b, ...) CCHECK(a != b, __VA_ARGS__) |
| 4528 |
#define CCHECK_LT(a, b, ...) CCHECK(a < b, __VA_ARGS__) |
| 4529 |
#define CCHECK_GT(a, b, ...) CCHECK(a > b, __VA_ARGS__) |
| 4530 |
#define CCHECK_LE(a, b, ...) CCHECK(a <= b, __VA_ARGS__) |
| 4531 |
#define CCHECK_GE(a, b, ...) CCHECK(a >= b, __VA_ARGS__) |
| 4532 |
#define CCHECK_BOUNDS(val, min, max, ...) CCHECK(val >= min && val <= max, __VA_ARGS__) |
| 4533 |
#define CHECK_EQ(a, b) CCHECK_EQ(a, b, ELPP_CURR_FILE_LOGGER_ID) |
| 4534 |
#define CHECK_NE(a, b) CCHECK_NE(a, b, ELPP_CURR_FILE_LOGGER_ID) |
| 4535 |
#define CHECK_LT(a, b) CCHECK_LT(a, b, ELPP_CURR_FILE_LOGGER_ID) |
| 4536 |
#define CHECK_GT(a, b) CCHECK_GT(a, b, ELPP_CURR_FILE_LOGGER_ID) |
| 4537 |
#define CHECK_LE(a, b) CCHECK_LE(a, b, ELPP_CURR_FILE_LOGGER_ID) |
| 4538 |
#define CHECK_GE(a, b) CCHECK_GE(a, b, ELPP_CURR_FILE_LOGGER_ID) |
| 4539 |
#define CHECK_BOUNDS(val, min, max) CCHECK_BOUNDS(val, min, max, ELPP_CURR_FILE_LOGGER_ID) |
| 4540 |
#define CCHECK_NOTNULL(ptr, ...) CCHECK((ptr) != nullptr, __VA_ARGS__) |
| 4541 |
#define CCHECK_STREQ(str1, str2, ...) CLOG_IF(!el::base::utils::Str::cStringEq(str1, str2), FATAL, __VA_ARGS__) \ |
| 4542 |
<< "Check failed: [" << #str1 << " == " << #str2 << "] " |
| 4543 |
#define CCHECK_STRNE(str1, str2, ...) CLOG_IF(el::base::utils::Str::cStringEq(str1, str2), FATAL, __VA_ARGS__) \ |
| 4544 |
<< "Check failed: [" << #str1 << " != " << #str2 << "] " |
| 4545 |
#define CCHECK_STRCASEEQ(str1, str2, ...) CLOG_IF(!el::base::utils::Str::cStringCaseEq(str1, str2), FATAL, __VA_ARGS__) \ |
| 4546 |
<< "Check failed: [" << #str1 << " == " << #str2 << "] " |
| 4547 |
#define CCHECK_STRCASENE(str1, str2, ...) CLOG_IF(el::base::utils::Str::cStringCaseEq(str1, str2), FATAL, __VA_ARGS__) \ |
| 4548 |
<< "Check failed: [" << #str1 << " != " << #str2 << "] " |
| 4549 |
#define CHECK_NOTNULL(ptr) CCHECK_NOTNULL((ptr), ELPP_CURR_FILE_LOGGER_ID) |
| 4550 |
#define CHECK_STREQ(str1, str2) CCHECK_STREQ(str1, str2, ELPP_CURR_FILE_LOGGER_ID) |
| 4551 |
#define CHECK_STRNE(str1, str2) CCHECK_STRNE(str1, str2, ELPP_CURR_FILE_LOGGER_ID) |
| 4552 |
#define CHECK_STRCASEEQ(str1, str2) CCHECK_STRCASEEQ(str1, str2, ELPP_CURR_FILE_LOGGER_ID) |
| 4553 |
#define CHECK_STRCASENE(str1, str2) CCHECK_STRCASENE(str1, str2, ELPP_CURR_FILE_LOGGER_ID) |
| 4554 |
#undef DCCHECK |
| 4555 |
#undef DCCHECK_EQ |
| 4556 |
#undef DCCHECK_NE |
| 4557 |
#undef DCCHECK_LT |
| 4558 |
#undef DCCHECK_GT |
| 4559 |
#undef DCCHECK_LE |
| 4560 |
#undef DCCHECK_GE |
| 4561 |
#undef DCCHECK_BOUNDS |
| 4562 |
#undef DCCHECK_NOTNULL |
| 4563 |
#undef DCCHECK_STRCASEEQ |
| 4564 |
#undef DCCHECK_STRCASENE |
| 4565 |
#undef DCPCHECK |
| 4566 |
#undef DCHECK |
| 4567 |
#undef DCHECK_EQ |
| 4568 |
#undef DCHECK_NE |
| 4569 |
#undef DCHECK_LT |
| 4570 |
#undef DCHECK_GT |
| 4571 |
#undef DCHECK_LE |
| 4572 |
#undef DCHECK_GE |
| 4573 |
#undef DCHECK_BOUNDS_ |
| 4574 |
#undef DCHECK_NOTNULL |
| 4575 |
#undef DCHECK_STRCASEEQ |
| 4576 |
#undef DCHECK_STRCASENE |
| 4577 |
#undef DPCHECK |
| 4578 |
#define DCCHECK(condition, ...) if (ELPP_DEBUG_LOG) CCHECK(condition, __VA_ARGS__) |
| 4579 |
#define DCCHECK_EQ(a, b, ...) if (ELPP_DEBUG_LOG) CCHECK_EQ(a, b, __VA_ARGS__) |
| 4580 |
#define DCCHECK_NE(a, b, ...) if (ELPP_DEBUG_LOG) CCHECK_NE(a, b, __VA_ARGS__) |
| 4581 |
#define DCCHECK_LT(a, b, ...) if (ELPP_DEBUG_LOG) CCHECK_LT(a, b, __VA_ARGS__) |
| 4582 |
#define DCCHECK_GT(a, b, ...) if (ELPP_DEBUG_LOG) CCHECK_GT(a, b, __VA_ARGS__) |
| 4583 |
#define DCCHECK_LE(a, b, ...) if (ELPP_DEBUG_LOG) CCHECK_LE(a, b, __VA_ARGS__) |
| 4584 |
#define DCCHECK_GE(a, b, ...) if (ELPP_DEBUG_LOG) CCHECK_GE(a, b, __VA_ARGS__) |
| 4585 |
#define DCCHECK_BOUNDS(val, min, max, ...) if (ELPP_DEBUG_LOG) CCHECK_BOUNDS(val, min, max, __VA_ARGS__) |
| 4586 |
#define DCCHECK_NOTNULL(ptr, ...) if (ELPP_DEBUG_LOG) CCHECK_NOTNULL((ptr), __VA_ARGS__) |
| 4587 |
#define DCCHECK_STREQ(str1, str2, ...) if (ELPP_DEBUG_LOG) CCHECK_STREQ(str1, str2, __VA_ARGS__) |
| 4588 |
#define DCCHECK_STRNE(str1, str2, ...) if (ELPP_DEBUG_LOG) CCHECK_STRNE(str1, str2, __VA_ARGS__) |
| 4589 |
#define DCCHECK_STRCASEEQ(str1, str2, ...) if (ELPP_DEBUG_LOG) CCHECK_STRCASEEQ(str1, str2, __VA_ARGS__) |
| 4590 |
#define DCCHECK_STRCASENE(str1, str2, ...) if (ELPP_DEBUG_LOG) CCHECK_STRCASENE(str1, str2, __VA_ARGS__) |
| 4591 |
#define DCPCHECK(condition, ...) if (ELPP_DEBUG_LOG) CPCHECK(condition, __VA_ARGS__) |
| 4592 |
#define DCHECK(condition) DCCHECK(condition, ELPP_CURR_FILE_LOGGER_ID) |
| 4593 |
#define DCHECK_EQ(a, b) DCCHECK_EQ(a, b, ELPP_CURR_FILE_LOGGER_ID) |
| 4594 |
#define DCHECK_NE(a, b) DCCHECK_NE(a, b, ELPP_CURR_FILE_LOGGER_ID) |
| 4595 |
#define DCHECK_LT(a, b) DCCHECK_LT(a, b, ELPP_CURR_FILE_LOGGER_ID) |
| 4596 |
#define DCHECK_GT(a, b) DCCHECK_GT(a, b, ELPP_CURR_FILE_LOGGER_ID) |
| 4597 |
#define DCHECK_LE(a, b) DCCHECK_LE(a, b, ELPP_CURR_FILE_LOGGER_ID) |
| 4598 |
#define DCHECK_GE(a, b) DCCHECK_GE(a, b, ELPP_CURR_FILE_LOGGER_ID) |
| 4599 |
#define DCHECK_BOUNDS(val, min, max) DCCHECK_BOUNDS(val, min, max, ELPP_CURR_FILE_LOGGER_ID) |
| 4600 |
#define DCHECK_NOTNULL(ptr) DCCHECK_NOTNULL((ptr), ELPP_CURR_FILE_LOGGER_ID) |
| 4601 |
#define DCHECK_STREQ(str1, str2) DCCHECK_STREQ(str1, str2, ELPP_CURR_FILE_LOGGER_ID) |
| 4602 |
#define DCHECK_STRNE(str1, str2) DCCHECK_STRNE(str1, str2, ELPP_CURR_FILE_LOGGER_ID) |
| 4603 |
#define DCHECK_STRCASEEQ(str1, str2) DCCHECK_STRCASEEQ(str1, str2, ELPP_CURR_FILE_LOGGER_ID) |
| 4604 |
#define DCHECK_STRCASENE(str1, str2) DCCHECK_STRCASENE(str1, str2, ELPP_CURR_FILE_LOGGER_ID) |
| 4605 |
#define DPCHECK(condition) DCPCHECK(condition, ELPP_CURR_FILE_LOGGER_ID) |
| 4606 |
#endif |
| 4607 |
#if defined(ELPP_DISABLE_DEFAULT_CRASH_HANDLING) |
| 4608 |
# define ELPP_USE_DEF_CRASH_HANDLER false |
| 4609 |
#else |
| 4610 |
# define ELPP_USE_DEF_CRASH_HANDLER true |
| 4611 |
#endif |
| 4612 |
#define ELPP_CRASH_HANDLER_INIT |
| 4613 |
#define ELPP_INIT_EASYLOGGINGPP(val) \ |
| 4614 |
namespace el { \ |
| 4615 |
namespace base { \ |
| 4616 |
el::base::type::StoragePointer elStorage(val); \ |
| 4617 |
} \ |
| 4618 |
el::base::debug::CrashHandler elCrashHandler(ELPP_USE_DEF_CRASH_HANDLER); \ |
| 4619 |
} |
| 4620 |
|
| 4621 |
#if ELPP_ASYNC_LOGGING |
| 4622 |
# define INITIALIZE_EASYLOGGINGPP ELPP_INIT_EASYLOGGINGPP(new el::base::Storage(el::LogBuilderPtr(new el::base::DefaultLogBuilder()),\ |
| 4623 |
new el::base::AsyncDispatchWorker())) |
| 4624 |
#else |
| 4625 |
# define INITIALIZE_EASYLOGGINGPP ELPP_INIT_EASYLOGGINGPP(new el::base::Storage(el::LogBuilderPtr(new el::base::DefaultLogBuilder()))) |
| 4626 |
#endif |
| 4627 |
#define INITIALIZE_NULL_EASYLOGGINGPP \ |
| 4628 |
namespace el {\ |
| 4629 |
namespace base {\ |
| 4630 |
el::base::type::StoragePointer elStorage;\ |
| 4631 |
}\ |
| 4632 |
el::base::debug::CrashHandler elCrashHandler(ELPP_USE_DEF_CRASH_HANDLER);\ |
| 4633 |
} |
| 4634 |
#define SHARE_EASYLOGGINGPP(initializedStorage)\ |
| 4635 |
namespace el {\ |
| 4636 |
namespace base {\ |
| 4637 |
el::base::type::StoragePointer elStorage(initializedStorage);\ |
| 4638 |
}\ |
| 4639 |
el::base::debug::CrashHandler elCrashHandler(ELPP_USE_DEF_CRASH_HANDLER);\ |
| 4640 |
} |
| 4641 |
|
| 4642 |
#if defined(ELPP_UNICODE) |
| 4643 |
# define START_EASYLOGGINGPP(argc, argv) el::Helpers::setArgs(argc, argv); std::locale::global(std::locale("")) |
| 4644 |
#else |
| 4645 |
# define START_EASYLOGGINGPP(argc, argv) el::Helpers::setArgs(argc, argv) |
| 4646 |
#endif |
| 4647 |
#endif |