Pivotal GemFire Native Client Cache Reference  9.0.6
Log.hpp
Go to the documentation of this file.
1 #ifndef _GEMFIRE_LOG_HPP_
2 #define _GEMFIRE_LOG_HPP_
3 
4 
5 /*=========================================================================
6  * Copyright (c) 2004-2014 Pivotal Software, Inc. All Rights Reserved.
7  * This product is protected by U.S. and international copyright
8  * and intellectual property laws. Pivotal products are covered by
9  * more patents listed at http://www.pivotal.io/patents.
10  *=========================================================================
11  */
12 
19 #include "gfcpp_globals.hpp"
20 #include <stdio.h>
21 #include <stdarg.h>
22 
23 /******************************************************************************/
24 
25 
26 #ifndef GEMFIRE_HIGHEST_LOG_LEVEL
27  #define GEMFIRE_HIGHEST_LOG_LEVEL All
28 #endif
29 
30 
31 #ifndef GEMFIRE_MAX_LOG_FILE_LIMIT
32  #define GEMFIRE_MAX_LOG_FILE_LIMIT (1024 * 1024 * 1024)
33 #endif
34 
35 #ifndef GEMFIRE_MAX_LOG_DISK_LIMIT
36 #define GEMFIRE_MAX_LOG_DISK_LIMIT (1024ll * 1024ll * 1024ll * 1024ll)
37 #endif
38 
39 #define _GF_MSG_LIMIT 8192
40 
41 /******************************************************************************/
42 
46 namespace gemfire {
47 
48 class Exception;
49 
50 /******************************************************************************/
51 /******************************************************************************/
52 
53 /* Logs the message if the given level is less than or equal to the current logging level. */
54 #define GF_LOG(level,expr) if ( level > gemfire::Log::logLevel() ) { } else gemfire::Log::log(level, expr)
55 
56 
57 
136 
137 public:
138 
139 
140  /******/
141 
142 
143  enum LogLevel {
144 
145  // NOTE: if you change this enum declaration at all, be sure to
146  // change levelToChars and charsToLevel functions!
147 
148  None,
149 
150  Error,
151  Warning,
152  Info,
153 
154  Default,
155 
156  Config,
157 
158  Fine,
159  Finer,
160  Finest,
161 
162  Debug,
163 
164  All
165 
166  };
167 
168 
169  /******/
170 
171 
175  static LogLevel logLevel()
176  { return s_logLevel; }
177 
181  static void setLogLevel( LogLevel level )
182  { s_logLevel = level; }
183 
189  static const char* logFileName();
190 
191 
198  static void init
199  // 0 => use maximum value (currently 1G)
200  (LogLevel level, const char* logFileName, int32 logFileLimit = 0, int64 logDiskSpaceLimit = 0);
201 
202 
206  static void close();
207 
208 
215  static const char* levelToChars(Log::LogLevel level);
216 
217 
223  static LogLevel charsToLevel(const char* chars);
224 
225 
240  static char* formatLogLine(char* buf, LogLevel level);
241 
242  /******/
243 
244 
248  static bool enabled(LogLevel level)
249  {
250  return
251  (((s_doingDebug && level == Debug) ||
252  GEMFIRE_HIGHEST_LOG_LEVEL >= level) && s_logLevel >= level);
253  }
254 
255 
259  static void log(LogLevel level, const char* msg)
260  {
261  if (enabled(level))
262  put(level, msg);
263  }
264 
265 
269  static void logThrow(LogLevel level, const char* msg, const Exception& ex)
270  {
271  if (enabled(level))
272  putThrow(level, msg, ex);
273  }
274 
275 
279  static void logCatch(LogLevel level, const char* msg, const Exception& ex)
280  {
281  if (enabled(level))
282  putCatch(level, msg, ex);
283  }
284 
285 
286  /******/
287 
288 
292  static bool errorEnabled()
293  {
294  return GEMFIRE_HIGHEST_LOG_LEVEL >= Error && s_logLevel >= Error;
295  }
296 
297 
302  static void error(const char* msg)
303  {
304  if (errorEnabled())
305  put(Error, msg);
306  }
307 
308 
313  static void errorThrow(const char* msg, const Exception& ex)
314  {
315  if (errorEnabled())
316  putThrow(Error, msg, ex);
317  }
318 
323  static void errorCatch(const char* msg, const Exception& ex)
324  {
325  if (errorEnabled())
326  putCatch(Error, msg, ex);
327  }
328 
329 
330  /******/
331 
332 
336  static bool warningEnabled()
337  {
338  return GEMFIRE_HIGHEST_LOG_LEVEL >= Warning && s_logLevel >= Warning;
339  }
340 
341 
346  static void warning(const char* msg)
347  {
348  if (warningEnabled())
349  put(Warning, msg);
350  }
351 
352 
357  static void warningThrow(const char* msg, const Exception& ex)
358  {
359  if (warningEnabled())
360  putThrow(Warning, msg, ex);
361  }
362 
363 
368  static void warningCatch(const char* msg, const Exception& ex)
369  {
370  if (warningEnabled())
371  putCatch(Warning, msg, ex);
372  }
373 
374 
375  /******/
376 
377 
381  static bool infoEnabled()
382  {
383  return GEMFIRE_HIGHEST_LOG_LEVEL >= Info && s_logLevel >= Info;
384  }
385 
386 
391  static void info(const char* msg)
392  {
393  if (infoEnabled())
394  put(Info, msg);
395  }
396 
397 
402  static void infoThrow(const char* msg, const Exception& ex)
403  {
404  if (infoEnabled())
405  putThrow(Info, msg, ex);
406  }
407 
408 
413  static void infoCatch(const char* msg, const Exception& ex)
414  {
415  if (infoEnabled())
416  putCatch(Info, msg, ex);
417  }
418 
419 
420  /******/
421 
422 
426  static bool configEnabled()
427  {
428  return GEMFIRE_HIGHEST_LOG_LEVEL >= Config && s_logLevel >= Config;
429  }
430 
431 
436  static void config(const char* msg)
437  {
438  if (configEnabled())
439  put(Config, msg);
440  }
441 
442 
447  static void configThrow(const char* msg, const Exception& ex)
448  {
449  if (configEnabled())
450  putThrow(Config, msg, ex);
451  }
452 
453 
458  static void configCatch(const char* msg, const Exception& ex)
459  {
460  if (configEnabled())
461  putCatch(Config, msg, ex);
462  }
463 
464 
465  /******/
466 
467 
471  static bool fineEnabled()
472  {
473  return GEMFIRE_HIGHEST_LOG_LEVEL >= Fine && s_logLevel >= Fine;
474  }
475 
476 
481  static void fine(const char* msg)
482  {
483  if (fineEnabled())
484  put(Fine, msg);
485  }
486 
487 
492  static void fineThrow(const char* msg, const Exception& ex)
493  {
494  if (fineEnabled())
495  putThrow(Fine, msg, ex);
496  }
497 
498 
503  static void fineCatch(const char* msg, const Exception& ex)
504  {
505  if (fineEnabled())
506  putCatch(Fine, msg, ex);
507  }
508 
509 
510  /******/
511 
512 
516  static bool finerEnabled()
517  {
518  return GEMFIRE_HIGHEST_LOG_LEVEL >= Finer && s_logLevel >= Finer;
519  }
520 
521 
526  static void finer(const char* msg)
527  {
528  if (finerEnabled())
529  put(Finer, msg);
530  }
531 
532 
537  static void finerThrow(const char* msg, const Exception& ex)
538  {
539  if (finerEnabled())
540  putThrow(Finer, msg, ex);
541  }
542 
543 
548  static void finerCatch(const char* msg, const Exception& ex)
549  {
550  if (finerEnabled())
551  putCatch(Finer, msg, ex);
552  }
553 
554 
555  /******/
556 
557 
561  static bool finestEnabled()
562  {
563  return GEMFIRE_HIGHEST_LOG_LEVEL >= Finest && s_logLevel >= Finest;
564  }
565 
566 
571  static void finest(const char* msg)
572  {
573  if (finestEnabled())
574  put(Finest, msg);
575  }
576 
577 
582  static void finestThrow(const char* msg, const Exception& ex)
583  {
584  if (finestEnabled())
585  putThrow(Finest, msg, ex);
586  }
587 
588 
593  static void finestCatch(const char* msg, const Exception& ex)
594  {
595  if (finestEnabled())
596  putCatch(Finest, msg, ex);
597  }
598 
599 
600  /******/
601 
602 
606  static bool debugEnabled()
607  {
608  return (s_doingDebug || GEMFIRE_HIGHEST_LOG_LEVEL >= Debug) &&
609  s_logLevel >= Debug;
610  }
611 
612 
617  static void debug(const char* msg)
618  {
619  if (debugEnabled())
620  put(Debug, msg);
621  }
622 
623 
628  static void debugThrow(const char* msg, const Exception& ex)
629  {
630  if (debugEnabled())
631  putThrow(Debug, msg, ex);
632  }
633 
634 
639  static void debugCatch(const char* msg, const Exception& ex)
640  {
641  if (debugEnabled())
642  putCatch(Debug, msg, ex);
643  }
644 
645 
646  /******/
647 
648 
649  static void enterFn(LogLevel level, const char* functionName);
650 
651 
652  static void exitFn(LogLevel level, const char* functionName);
653 
654 
655 
656  /******/
657 
658 private:
659 
660 
661  static LogLevel s_logLevel;
662 
663 
664  /******/
665 
666 #ifdef DEBUG
667  enum { s_doingDebug = 1 };
668 #else
669  enum { s_doingDebug = 0 };
670 #endif
671 
672 
673  /******/
674 
675 
676  static void writeBanner();
677 
678 
679  /******/
680 public:
681 
682  static void put(LogLevel level, const char* msg);
683 
684  static void putThrow
685  (LogLevel level, const char* msg, const Exception& ex);
686 
687  static void putCatch
688  (LogLevel level, const char* msg, const Exception& ex);
689 
690 };
691 
692 
693 /******************************************************************************/
694 /******************************************************************************/
695 
696 
697 class LogFn {
698 
699  const char* m_functionName;
700  Log::LogLevel m_level;
701 
702 public:
703 
704  LogFn(const char* functionName, Log::LogLevel level = Log::Finest)
705  : m_functionName(functionName), m_level(level)
706  {
707  if (Log::enabled(m_level))
708  Log::enterFn(m_level, m_functionName);
709  }
710 
711  ~LogFn()
712  {
713  if (Log::enabled(m_level))
714  Log::exitFn(m_level, m_functionName);
715  }
716 
717 private:
718  LogFn(const LogFn& rhs); // never defined
719  void operator = (const LogFn& rhs); // never defined
720 };
721 
722 /******************************************************************************/
723 /******************************************************************************/
724 
730 {
731  public:
732 
733  static void debug( const char* fmt, ...);
734  static void error( const char* fmt, ...);
735  static void warn( const char* fmt, ...);
736  static void info( const char* fmt, ...);
737  static void config( const char* fmt, ...);
738  static void fine( const char* fmt, ...);
739  static void finer( const char* fmt, ...);
740  static void finest( const char* fmt, ...);
741 
742 };
743 
744 }
745 
746 /************************ LOGDEBUG ***********************************/
747 
748 #define LOGDEBUG if ( gemfire::Log::Debug <= gemfire::Log::logLevel() ) gemfire::LogVarargs::debug
749 
750 /************************ LOGERROR ***********************************/
751 
752 #define LOGERROR if ( gemfire::Log::Error <= gemfire::Log::logLevel() ) gemfire::LogVarargs::error
753 
754 /************************ LOGWARN ***********************************/
755 
756 #define LOGWARN if ( gemfire::Log::Warning <= gemfire::Log::logLevel() ) gemfire::LogVarargs::warn
757 
758 /************************ LOGINFO ***********************************/
759 
760 #define LOGINFO if ( gemfire::Log::Info <= gemfire::Log::logLevel() ) gemfire::LogVarargs::info
761 
762 /************************ LOGCONFIG ***********************************/
763 
764 #define LOGCONFIG if ( gemfire::Log::Config <= gemfire::Log::logLevel() ) gemfire::LogVarargs::config
765 
766 /************************ LOGFINE ***********************************/
767 
768 #define LOGFINE if ( gemfire::Log::Fine <= gemfire::Log::logLevel() ) gemfire::LogVarargs::fine
769 
770 /************************ LOGFINER ***********************************/
771 
772 #define LOGFINER if ( gemfire::Log::Finer <= gemfire::Log::logLevel() ) gemfire::LogVarargs::finer
773 
774 /************************ LOGFINEST ***********************************/
775 
776 #define LOGFINEST if ( gemfire::Log::Finest <= gemfire::Log::logLevel() ) gemfire::LogVarargs::finest
777 
778 /******************************************************************************/
779 
780 
781 /******************************************************************************/
782 
783 
784 #endif
785 
786 
787 /******************************************************************************/
static bool finerEnabled()
Returns whether "finer" log messages are enabled.
Definition: Log.hpp:516
static void finerThrow(const char *msg, const Exception &ex)
Logs both a message and thrown exception.
Definition: Log.hpp:537
static void setLogLevel(LogLevel level)
Set the current log level.
Definition: Log.hpp:181
#define GEMFIRE_HIGHEST_LOG_LEVEL
The interface of the Log class.
Definition: Log.hpp:27
static void info(const char *msg)
Logs a message.
Definition: Log.hpp:391
static void configThrow(const char *msg, const Exception &ex)
Logs both a message and thrown exception.
Definition: Log.hpp:447
static bool configEnabled()
Returns whether "config" log messages are enabled.
Definition: Log.hpp:426
int64_t int64
signed 64 bit integer
Definition: gf_base.hpp:180
static void finestThrow(const char *msg, const Exception &ex)
Logs both a message and thrown exception.
Definition: Log.hpp:582
These functions are added to facilitate logging in printf format.
Definition: Log.hpp:729
static void debugThrow(const char *msg, const Exception &ex)
Logs both a message and thrown exception.
Definition: Log.hpp:628
static void log(LogLevel level, const char *msg)
Logs a message at given level.
Definition: Log.hpp:259
static void configCatch(const char *msg, const Exception &ex)
Writes both a message and caught exception.
Definition: Log.hpp:458
static void warningThrow(const char *msg, const Exception &ex)
Logs both a message and thrown exception.
Definition: Log.hpp:357
static void finer(const char *msg)
Logs a message.
Definition: Log.hpp:526
static bool enabled(LogLevel level)
Returns whether log messages at given level are enabled.
Definition: Log.hpp:248
static void fineCatch(const char *msg, const Exception &ex)
Writes both a message and caught exception.
Definition: Log.hpp:503
static void infoThrow(const char *msg, const Exception &ex)
Logs both a message and thrown exception.
Definition: Log.hpp:402
static LogLevel logLevel()
Returns the current log level.
Definition: Log.hpp:175
static bool errorEnabled()
Returns whether "error" log messages are enabled.
Definition: Log.hpp:292
static void errorThrow(const char *msg, const Exception &ex)
Logs both a message and thrown exception.
Definition: Log.hpp:313
This namespace contains all the GemFire C++ API classes, enumerations and globals.
Definition: Assert.hpp:19
static bool warningEnabled()
Returns whether "warning" log messages are enabled.
Definition: Log.hpp:336
static bool finestEnabled()
Returns whether "finest" log messages are enabled.
Definition: Log.hpp:561
static void debug(const char *msg)
Logs a message.
Definition: Log.hpp:617
static void finestCatch(const char *msg, const Exception &ex)
Writes both a message and caught exception.
Definition: Log.hpp:593
static void logThrow(LogLevel level, const char *msg, const Exception &ex)
Logs both a message and thrown exception.
Definition: Log.hpp:269
int32_t int32
signed 32 bit integer
Definition: gf_base.hpp:178
static void logCatch(LogLevel level, const char *msg, const Exception &ex)
Logs both a message and caught exception.
Definition: Log.hpp:279
static void error(const char *msg)
Logs a message.
Definition: Log.hpp:302
static void warningCatch(const char *msg, const Exception &ex)
Writes both a message and caught exception.
Definition: Log.hpp:368
static void infoCatch(const char *msg, const Exception &ex)
Writes both a message and caught exception.
Definition: Log.hpp:413
static bool fineEnabled()
Returns whether "fine" log messages are enabled.
Definition: Log.hpp:471
#define CPPCACHE_EXPORT
Defines a GemFire CPPCACHE export.
Definition: gf_base.hpp:51
static bool debugEnabled()
Returns whether "debug" log messages are enabled.
Definition: Log.hpp:606
A description of an exception that occurred during a cache operation.
Definition: Exception.hpp:31
static void debugCatch(const char *msg, const Exception &ex)
Writes both a message and caught exception.
Definition: Log.hpp:639
static bool infoEnabled()
Returns whether "info" log messages are enabled.
Definition: Log.hpp:381
static void fineThrow(const char *msg, const Exception &ex)
Logs both a message and thrown exception.
Definition: Log.hpp:492
static void finerCatch(const char *msg, const Exception &ex)
Writes both a message and caught exception.
Definition: Log.hpp:548
static void config(const char *msg)
Logs a message.
Definition: Log.hpp:436
static void errorCatch(const char *msg, const Exception &ex)
Writes both a message and caught exception.
Definition: Log.hpp:323
static void fine(const char *msg)
Logs a message.
Definition: Log.hpp:481
static void warning(const char *msg)
Logs a message.
Definition: Log.hpp:346
static void finest(const char *msg)
Logs a message.
Definition: Log.hpp:571
Defines methods available to clients that want to write a log message to their GemFire system&#39;s share...
Definition: Log.hpp:135

GemFire C++ Cache API Documentation