NSPR Reference Previous Contents Next |
printf()
style strings
to the console or to a log file. NSPR uses this facility itself for its own development
debugging purposes.
You can select events to be logged by module or level. A module is a user-defined class of log events. A level is a numeric value that indicates the seriousness of the event to be logged. You can combine module and level criteria to get highly selective logging.
NSPR also provides "assert"-style macros and functions to aid in application debugging.
Conditional Compilation and Execution
Log Types and Variables
Logging Functions and Macros
Use Example
#define
values DEBUG
or FORCE_PR_LOG
enable NSPR logging for application programs.
To enable NSPR logging and/or the debugging aids in your application, compile using the NSPR debug build headers and runtime. Set one of the compile-time defines when you build your application.
Execution-time control of NSPR's logging uses two environment variables. These variables control which modules and levels are logged as well as the file name of the log file. By default, no logging is enabled at execution time.
PRLogModuleInfo
PRLogModuleLevel
Two environment variables control the behavior of logging at execution time:
NSPR_LOG_MODULES
NSPR_LOG_FILE
PRLogModuleInfo
structure controls logging from within your application. To
log your program's activity, create a PRLogModuleInfo
structure using
PR_NewLogModule
.
#include <prlog.h>
typedef struct PRLogModuleInfo {
const char *name;
PRLogModuleLevel level;
struct PRLogModuleInfo *next;
} PRLogModuleInfo;
PRLogModuleLevel
defines levels of logging available to
application programs.
#include <prlog.h>
typedef enum PRLogModuleLevel {
PR_LOG_NONE = 0,
PR_LOG_ALWAYS = 1,
PR_LOG_ERROR = 2,
PR_LOG_WARNING = 3,
PR_LOG_DEBUG = 4,
PR_LOG_NOTICE = PR_LOG_DEBUG,
PR_LOG_WARN = PR_LOG_WARNING,
PR_LOG_MIN = PR_LOG_DEBUG,
PR_LOG_MAX = PR_LOG_DEBUG
} PRLogModuleLevel;
moduleName:level[, moduleName:level]*
moduleName is the name specified in a PR_NewLogModule
call.
level is a numeric value in the range PR_LOG_NONE
to PR_LOG_MAX
.
moduleName
that is associated with the name
argument in a call to
PR_NewLogModule
and a non-zero level
value to enable logging for the named
moduleName
.
Special log module names are provided for controlling NSPR's log service at
execution time. These controls should be set in the NSPR_LOG_MODULES
environment variable at execution time to affect NSPR's log service for your
application.
all
enables all log modules. To enable all log module calls to
PR_LOG
, set the variable as follows:
set NSPR_LOG_MODULES=all:5
The name sync
enables unbuffered logging.
The name bufsize:
size sets the log buffer to size.
filespec
filespec is a filename. The exact syntax is platform specific.
NSPR_LOG_FILE
is not in the environment, then log output is written to stdout
or
stderr
, depending on the platform. Set NSPR_LOG_FILE
to the name of the log file
you want to use. NSPR logging, when enabled, writes to the file named in this
environment variable.
For MS Windows systems, you can set NSPR_LOG_FILE
to the special
(case-sensitive) value WinDebug
. This value causes logging output to be written
using the Windows function OutputDebugString()
, which writes to the debugger
window.
PR_NewLogModule
PR_SetLogFile
PR_SetLogBuffering
PR_LogPrint
PR_LogFlush
PR_LOG_TEST
PR_LOG
PR_Assert
PR_ASSERT
PR_NOT_REACHED
#include <prlog.h>
PRLogModuleInfo* PR_NewLogModule(const char *name);
name
|
The name to be assigned to the PRLogModuleInfo structure.
|
PRLogModuleInfo
structure.
PRLogModuleInfo
structure with the
specified name. If the environment variable NSPR_LOG_MODULES
contains the
specified name, then the associated level value from the variable is associated with
the new PRLogModuleInfo
structure.
#include <prlog.h>
PRBool PR_SetLogFile(const char *name);
name
|
The name of the log file.
|
PR_TRUE
when successful. Otherwise, PR_FALSE
.
Ordinarily, a user application need not use this function, as NSPR initializes logging at NSPR startup. The application can use the model provided in Use Example to effect application logging.
#include <prlog.h>
void PR_SetLogBuffering(PRIntn buffer_size);
buffer_size
|
The size of the buffer to be used for logging.
|
Ordinarily, a user application need not use this function, as NSPR initializes logging at NSPR startup. The application can use the model provided in Use Example to effect application logging.
#include <prlog.h>
void PR_LogPrint(const char *fmt, ...);
fmt
|
The string that is used as the formatting specification.
|
#include <prlog.h>
void PR_LogFlush(void);
#include <prlog.h>
PRBool PR_LOG_TEST (
PRLogModuleInfo *_module,
PRLogModuleLevel _level);
PR_TRUE
when logging is enabled for the given module and level, otherwise
PR_FALSE
.
PR_LOG
.
#include <prlog.h>
void PR_LOG (
PRLogModuleInfo *_module,
PRLogModuleLevel _level
... _args);
For an example of using conditional logging, see Use Example .
This macro compiles to nothing if compile-time options are not specified to enable logging.
#include <prlog.h>
void PR_Assert (
const char *s,
const char *file,
PRIntn ln);
s
|
A string to be displayed in the log
|
file
|
The file name of the compilation unit containing this function call.
|
ln
|
The line number within the specified file of this function call.
|
Normally an application would not call this function directly; use PR_ASSERT
instead.
FALSE
.
#include <prlog.h>
void PR_ASSERT ( expression );
expression
|
Any valid C language expression that evaluates to TRUE or FALSE .
|
FALSE
) the
application terminates; otherwise the application continues. The macro converts
the expression to a string and passes it to PR_Assert
, using file
and ln
parameters from the compile-time environment.
This macro compiles to nothing if compile-time options are not specified to enable logging.
#include <prlog.h>
void PR_NOT_REACHED( char *_reasonStr)
reasonStr
|
A string that describes why you should not have reached this
statement.
|
This macro compiles to nothing if compile-time options are not specified to enable logging.
DEBUG
defined.
Before running the compiled program, set the environment variable
NSPR_LOG_MODULES
to userStuff:5
static void UserLogStuff( void )
{
PRLogModuleInfo *myLM;
PRIntn i;
myLM = PR_NewLogModule( "userStuff" );
PR_ASSERT( myLM );
PR_LOG( myLM, PR_LOG_NOTICE, ("Log a Notice %d\n", 999 ));
for (i = 0; i < 10 ; i++ )
{
PR_LOG( myLM, PR_LOG_DEBUG, ("Log Debug number: %d\n", i));
PR_Sleep( 500 );
}
PR_LOG( myLM, PR_LOG_NOTICE, ("That's all folks\n");
} /* end UserLogStuff() */
Last Updated May 18, 2001