00001 #ifndef _GEMFIRE_LOG_HPP_
00002 #define _GEMFIRE_LOG_HPP_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00019 #include "gfcpp_globals.hpp"
00020 #include <stdio.h>
00021 #include <stdarg.h>
00022
00023
00024
00025
00026 #ifndef GEMFIRE_HIGHEST_LOG_LEVEL
00027 #define GEMFIRE_HIGHEST_LOG_LEVEL All
00028 #endif
00029
00030
00031 #ifndef GEMFIRE_MAX_LOG_FILE_LIMIT
00032 #define GEMFIRE_MAX_LOG_FILE_LIMIT (1024 * 1024 * 1024)
00033 #endif
00034
00035 #ifndef GEMFIRE_MAX_LOG_DISK_LIMIT
00036 #define GEMFIRE_MAX_LOG_DISK_LIMIT (1024ll * 1024ll * 1024ll * 1024ll)
00037 #endif
00038
00039 #define _GF_MSG_LIMIT 8192
00040
00041
00042
00046 namespace gemfire {
00047
00048 class Exception;
00049
00050
00051
00052
00053
00054 #define GF_LOG(level,expr) if ( level > gemfire::Log::logLevel() ) { } else gemfire::Log::log(level, expr)
00055
00056
00057
00135 class CPPCACHE_EXPORT Log {
00136
00137 public:
00138
00139
00140
00141
00142
00143 enum LogLevel {
00144
00145
00146
00147
00148 None,
00149
00150 Error,
00151 Warning,
00152 Info,
00153
00154 Default,
00155
00156 Config,
00157
00158 Fine,
00159 Finer,
00160 Finest,
00161
00162 Debug,
00163
00164 All
00165
00166 };
00167
00168
00169
00170
00171
00175 static LogLevel logLevel()
00176 { return s_logLevel; }
00177
00181 static void setLogLevel( LogLevel level )
00182 { s_logLevel = level; }
00183
00189 static const char* logFileName();
00190
00191
00198 static void init
00199
00200 (LogLevel level, const char* logFileName, int32 logFileLimit = 0, int64 logDiskSpaceLimit = 0);
00201
00202
00206 static void close();
00207
00208
00215 static const char* levelToChars(Log::LogLevel level);
00216
00217
00223 static LogLevel charsToLevel(const char* chars);
00224
00225
00240 static char* formatLogLine(char* buf, LogLevel level);
00241
00242
00243
00244
00248 static bool enabled(LogLevel level)
00249 {
00250 return
00251 (((s_doingDebug && level == Debug) ||
00252 GEMFIRE_HIGHEST_LOG_LEVEL >= level) && s_logLevel >= level);
00253 }
00254
00255
00259 static void log(LogLevel level, const char* msg)
00260 {
00261 if (enabled(level))
00262 put(level, msg);
00263 }
00264
00265
00269 static void logThrow(LogLevel level, const char* msg, const Exception& ex)
00270 {
00271 if (enabled(level))
00272 putThrow(level, msg, ex);
00273 }
00274
00275
00279 static void logCatch(LogLevel level, const char* msg, const Exception& ex)
00280 {
00281 if (enabled(level))
00282 putCatch(level, msg, ex);
00283 }
00284
00285
00286
00287
00288
00292 static bool errorEnabled()
00293 {
00294 return GEMFIRE_HIGHEST_LOG_LEVEL >= Error && s_logLevel >= Error;
00295 }
00296
00297
00302 static void error(const char* msg)
00303 {
00304 if (errorEnabled())
00305 put(Error, msg);
00306 }
00307
00308
00313 static void errorThrow(const char* msg, const Exception& ex)
00314 {
00315 if (errorEnabled())
00316 putThrow(Error, msg, ex);
00317 }
00318
00323 static void errorCatch(const char* msg, const Exception& ex)
00324 {
00325 if (errorEnabled())
00326 putCatch(Error, msg, ex);
00327 }
00328
00329
00330
00331
00332
00336 static bool warningEnabled()
00337 {
00338 return GEMFIRE_HIGHEST_LOG_LEVEL >= Warning && s_logLevel >= Warning;
00339 }
00340
00341
00346 static void warning(const char* msg)
00347 {
00348 if (warningEnabled())
00349 put(Warning, msg);
00350 }
00351
00352
00357 static void warningThrow(const char* msg, const Exception& ex)
00358 {
00359 if (warningEnabled())
00360 putThrow(Warning, msg, ex);
00361 }
00362
00363
00368 static void warningCatch(const char* msg, const Exception& ex)
00369 {
00370 if (warningEnabled())
00371 putCatch(Warning, msg, ex);
00372 }
00373
00374
00375
00376
00377
00381 static bool infoEnabled()
00382 {
00383 return GEMFIRE_HIGHEST_LOG_LEVEL >= Info && s_logLevel >= Info;
00384 }
00385
00386
00391 static void info(const char* msg)
00392 {
00393 if (infoEnabled())
00394 put(Info, msg);
00395 }
00396
00397
00402 static void infoThrow(const char* msg, const Exception& ex)
00403 {
00404 if (infoEnabled())
00405 putThrow(Info, msg, ex);
00406 }
00407
00408
00413 static void infoCatch(const char* msg, const Exception& ex)
00414 {
00415 if (infoEnabled())
00416 putCatch(Info, msg, ex);
00417 }
00418
00419
00420
00421
00422
00426 static bool configEnabled()
00427 {
00428 return GEMFIRE_HIGHEST_LOG_LEVEL >= Config && s_logLevel >= Config;
00429 }
00430
00431
00436 static void config(const char* msg)
00437 {
00438 if (configEnabled())
00439 put(Config, msg);
00440 }
00441
00442
00447 static void configThrow(const char* msg, const Exception& ex)
00448 {
00449 if (configEnabled())
00450 putThrow(Config, msg, ex);
00451 }
00452
00453
00458 static void configCatch(const char* msg, const Exception& ex)
00459 {
00460 if (configEnabled())
00461 putCatch(Config, msg, ex);
00462 }
00463
00464
00465
00466
00467
00471 static bool fineEnabled()
00472 {
00473 return GEMFIRE_HIGHEST_LOG_LEVEL >= Fine && s_logLevel >= Fine;
00474 }
00475
00476
00481 static void fine(const char* msg)
00482 {
00483 if (fineEnabled())
00484 put(Fine, msg);
00485 }
00486
00487
00492 static void fineThrow(const char* msg, const Exception& ex)
00493 {
00494 if (fineEnabled())
00495 putThrow(Fine, msg, ex);
00496 }
00497
00498
00503 static void fineCatch(const char* msg, const Exception& ex)
00504 {
00505 if (fineEnabled())
00506 putCatch(Fine, msg, ex);
00507 }
00508
00509
00510
00511
00512
00516 static bool finerEnabled()
00517 {
00518 return GEMFIRE_HIGHEST_LOG_LEVEL >= Finer && s_logLevel >= Finer;
00519 }
00520
00521
00526 static void finer(const char* msg)
00527 {
00528 if (finerEnabled())
00529 put(Finer, msg);
00530 }
00531
00532
00537 static void finerThrow(const char* msg, const Exception& ex)
00538 {
00539 if (finerEnabled())
00540 putThrow(Finer, msg, ex);
00541 }
00542
00543
00548 static void finerCatch(const char* msg, const Exception& ex)
00549 {
00550 if (finerEnabled())
00551 putCatch(Finer, msg, ex);
00552 }
00553
00554
00555
00556
00557
00561 static bool finestEnabled()
00562 {
00563 return GEMFIRE_HIGHEST_LOG_LEVEL >= Finest && s_logLevel >= Finest;
00564 }
00565
00566
00571 static void finest(const char* msg)
00572 {
00573 if (finestEnabled())
00574 put(Finest, msg);
00575 }
00576
00577
00582 static void finestThrow(const char* msg, const Exception& ex)
00583 {
00584 if (finestEnabled())
00585 putThrow(Finest, msg, ex);
00586 }
00587
00588
00593 static void finestCatch(const char* msg, const Exception& ex)
00594 {
00595 if (finestEnabled())
00596 putCatch(Finest, msg, ex);
00597 }
00598
00599
00600
00601
00602
00606 static bool debugEnabled()
00607 {
00608 return (s_doingDebug || GEMFIRE_HIGHEST_LOG_LEVEL >= Debug) &&
00609 s_logLevel >= Debug;
00610 }
00611
00612
00617 static void debug(const char* msg)
00618 {
00619 if (debugEnabled())
00620 put(Debug, msg);
00621 }
00622
00623
00628 static void debugThrow(const char* msg, const Exception& ex)
00629 {
00630 if (debugEnabled())
00631 putThrow(Debug, msg, ex);
00632 }
00633
00634
00639 static void debugCatch(const char* msg, const Exception& ex)
00640 {
00641 if (debugEnabled())
00642 putCatch(Debug, msg, ex);
00643 }
00644
00645
00646
00647
00648
00649 static void enterFn(LogLevel level, const char* functionName);
00650
00651
00652 static void exitFn(LogLevel level, const char* functionName);
00653
00654
00655
00656
00657
00658 private:
00659
00660
00661 static LogLevel s_logLevel;
00662
00663
00664
00665
00666 #ifdef DEBUG
00667 enum { s_doingDebug = 1 };
00668 #else
00669 enum { s_doingDebug = 0 };
00670 #endif
00671
00672
00673
00674
00675
00676 static void writeBanner();
00677
00678
00679
00680 public:
00681
00682 static void put(LogLevel level, const char* msg);
00683
00684 static void putThrow
00685 (LogLevel level, const char* msg, const Exception& ex);
00686
00687 static void putCatch
00688 (LogLevel level, const char* msg, const Exception& ex);
00689
00690 };
00691
00692
00693
00694
00695
00696
00697 class LogFn {
00698
00699 const char* m_functionName;
00700 Log::LogLevel m_level;
00701
00702 public:
00703
00704 LogFn(const char* functionName, Log::LogLevel level = Log::Finest)
00705 : m_functionName(functionName), m_level(level)
00706 {
00707 if (Log::enabled(m_level))
00708 Log::enterFn(m_level, m_functionName);
00709 }
00710
00711 ~LogFn()
00712 {
00713 if (Log::enabled(m_level))
00714 Log::exitFn(m_level, m_functionName);
00715 }
00716
00717 private:
00718 LogFn(const LogFn& rhs);
00719 void operator = (const LogFn& rhs);
00720 };
00721
00722
00723
00724
00729 class CPPCACHE_EXPORT LogVarargs
00730 {
00731 public:
00732
00733 static void debug( const char* fmt, ...);
00734 static void error( const char* fmt, ...);
00735 static void warn( const char* fmt, ...);
00736 static void info( const char* fmt, ...);
00737 static void config( const char* fmt, ...);
00738 static void fine( const char* fmt, ...);
00739 static void finer( const char* fmt, ...);
00740 static void finest( const char* fmt, ...);
00741
00742 };
00743
00744 }
00745
00746
00747
00748 #define LOGDEBUG if ( gemfire::Log::Debug <= gemfire::Log::logLevel() ) gemfire::LogVarargs::debug
00749
00750
00751
00752 #define LOGERROR if ( gemfire::Log::Error <= gemfire::Log::logLevel() ) gemfire::LogVarargs::error
00753
00754
00755
00756 #define LOGWARN if ( gemfire::Log::Warning <= gemfire::Log::logLevel() ) gemfire::LogVarargs::warn
00757
00758
00759
00760 #define LOGINFO if ( gemfire::Log::Info <= gemfire::Log::logLevel() ) gemfire::LogVarargs::info
00761
00762
00763
00764 #define LOGCONFIG if ( gemfire::Log::Config <= gemfire::Log::logLevel() ) gemfire::LogVarargs::config
00765
00766
00767
00768 #define LOGFINE if ( gemfire::Log::Fine <= gemfire::Log::logLevel() ) gemfire::LogVarargs::fine
00769
00770
00771
00772 #define LOGFINER if ( gemfire::Log::Finer <= gemfire::Log::logLevel() ) gemfire::LogVarargs::finer
00773
00774
00775
00776 #define LOGFINEST if ( gemfire::Log::Finest <= gemfire::Log::logLevel() ) gemfire::LogVarargs::finest
00777
00778
00779
00780
00781
00782
00783
00784 #endif
00785
00786
00787