home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / include / prlog.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.2 KB  |  172 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef prlog_h___
  20. #define prlog_h___
  21.  
  22. #include "prtypes.h"
  23.  
  24. PR_BEGIN_EXTERN_C
  25.  
  26. /*
  27. **
  28. ** Define in your environment a NSPR_LOG_MODULES variable. The value of
  29. ** this variable has the form:
  30. **
  31. **     <moduleName>:<value>[, <moduleName>:<value>]*
  32. **
  33. ** where moduleName is one of named modules that support debugging (see
  34. ** the header file for a particular module for more specific
  35. ** information).  Value is one of the enum PRLogModuleLevel's legal
  36. ** values.
  37. **
  38. ** Special modules exist for controlling the logging facility:
  39. **    sync        -- do unbuffered logging
  40. **    bufsize:size    -- use a buffer of "size" bytes
  41. **
  42. ** Define in your environment NSPR_LOG_FILE to specify the log file to
  43. ** use unless the default of "stderr" is acceptable.
  44. **
  45. ** To put log messages in your programs, use the PR_LOG macro:
  46. **
  47. **     PR_LOG(<module>, <level>, (<printfString>, <args>*));
  48. **
  49. ** Where <module> is the address of a PRLogModuleInfo structure, and
  50. ** <level> is one of the following levels:
  51. */
  52.  
  53. typedef enum PRLogModuleLevel {
  54.     PR_LOG_NONE = 0,                /* nothing */
  55.     PR_LOG_ALWAYS = 1,              /* always printed */
  56.     PR_LOG_ERROR = 2,               /* error messages */
  57.     PR_LOG_WARNING = 3,             /* warning messages */
  58.     PR_LOG_DEBUG = 4,               /* debug messages */
  59.  
  60.     PR_LOG_NOTICE = PR_LOG_DEBUG,   /* notice messages */
  61.     PR_LOG_WARN = PR_LOG_WARNING,   /* warning messages */
  62.     PR_LOG_MIN = PR_LOG_DEBUG,      /* minimal debugging messages */
  63.     PR_LOG_MAX = PR_LOG_DEBUG       /* maximal debugging messages */
  64. } PRLogModuleLevel;
  65.  
  66. /*
  67. ** One of these structures is created for each module that uses logging.
  68. **    "name" is the name of the module
  69. **    "level" is the debugging level selected for that module
  70. */
  71. typedef struct PRLogModuleInfo {
  72.     const char *name;
  73.     PRLogModuleLevel level;
  74.     struct PRLogModuleInfo *next;
  75. } PRLogModuleInfo;
  76.  
  77. /*
  78. ** Create a new log module.
  79. */
  80. PR_EXTERN(PRLogModuleInfo*) PR_NewLogModule(const char *name);
  81.  
  82. /*
  83. ** Set the file to use for logging. Returns PR_FALSE if the file cannot
  84. ** be created
  85. */
  86. PR_EXTERN(PRBool) PR_SetLogFile(const char *name);
  87.  
  88. /*
  89. ** Set the size of the logging buffer. If "buffer_size" is zero then the
  90. ** logging becomes "synchronous" (or unbuffered).
  91. */
  92. PR_EXTERN(void) PR_SetLogBuffering(PRIntn buffer_size);
  93.  
  94. /*
  95. ** Print a string to the log. "fmt" is a PR_snprintf format type. All
  96. ** messages printed to the log are preceeded by the name of the thread
  97. ** and a time stamp. Also, the routine provides a missing newline if one
  98. ** is not provided.
  99. */
  100. PR_EXTERN(void) PR_LogPrint(const char *fmt, ...);
  101.  
  102. /*
  103. ** Flush the log to its file.
  104. */
  105. PR_EXTERN(void) PR_LogFlush(void);
  106.  
  107. /*
  108. ** Windoze 16 can't support a large static string space for all of the
  109. ** various debugging strings so logging is not enabled for it.
  110. */
  111. #if (defined(DEBUG) || defined(FORCE_PR_LOG)) && !defined(WIN16)
  112. #define PR_LOGGING 1
  113.  
  114. #define PR_LOG_TEST(_module,_level) \
  115.     ((_module)->level >= (_level))
  116.  
  117. /*
  118. ** Log something.
  119. **    "module" is the address of a PRLogModuleInfo structure
  120. **    "level" is the desired logging level
  121. **    "args" is a variable length list of arguments to print, in the following
  122. **       format:  ("printf style format string", ...)
  123. */
  124. #define PR_LOG(_module,_level,_args)     \
  125.     PR_BEGIN_MACRO             \
  126.       if (PR_LOG_TEST(_module,_level)) { \
  127.       PR_LogPrint _args;         \
  128.       }                     \
  129.     PR_END_MACRO
  130.  
  131. #else /* (defined(DEBUG) || defined(FORCE_PR_LOG)) && !defined(WIN16) */
  132.  
  133. #undef PR_LOGGING
  134. #define PR_LOG_TEST(module,level) 0
  135. #define PR_LOG(module,level,args)
  136.  
  137. #endif /* (defined(DEBUG) || defined(FORCE_PR_LOG)) && !defined(WIN16) */
  138.  
  139. #ifndef NO_NSPR_10_SUPPORT
  140.  
  141. #ifdef PR_LOGGING
  142. #define PR_LOG_BEGIN    PR_LOG
  143. #define PR_LOG_END      PR_LOG
  144. #define PR_LOG_DEFINE   PR_NewLogModule
  145. #else
  146. #define PR_LOG_BEGIN(module,level,args)
  147. #define PR_LOG_END(module,level,args)
  148. #define PR_LOG_DEFINE(_name)    NULL
  149. #endif /* PR_LOGGING */
  150.  
  151. #endif /* NO_NSPR_10_SUPPORT */
  152.  
  153. #if defined(DEBUG)
  154.  
  155. PR_EXTERN(void) PR_Assert(const char *s, const char *file, PRIntn ln);
  156. #define PR_ASSERT(_expr) \
  157.     ((_expr)?((void)0):PR_Assert(# _expr,__FILE__,__LINE__))
  158.  
  159. #define PR_NOT_REACHED(_reasonStr) \
  160.     PR_Assert(_reasonStr,__FILE__,__LINE__)
  161.  
  162. #else
  163.  
  164. #define PR_ASSERT(expr) ((void) 0)
  165. #define PR_NOT_REACHED(reasonStr)
  166.  
  167. #endif /* defined(DEBUG) */
  168.  
  169. PR_END_EXTERN_C
  170.  
  171. #endif /* prlog_h___ */
  172.