Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
tracelog.h File Reference
#include <stdio.h>
#include <string.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  TlogGlobal

Defines

#define TLOG_MAXMODULES   50
#define TLOG_MESSAGE   tlog_message
#define TLOG_ERROR   TLOG_MESSAGE
#define TLOG_WARNING   if (tlogGlobal.debugOn) TLOG_MESSAGE
#define TLOG_PRINT(imodule, procname, level, args)

Functions

void tlog_init (FILE *fileStream)
 Initializes all TRACELOG operations and sets filestream for trace/log output.
int tlog_set_level (int imodule, int messageLevel, const char *functionList)
 Set diagnostic message display level for module no.
int tlog_test (int imodule, char *procname, int level)
 Determines whether trace/log message is to be displayed for specified module at specified message level.
void tlog_message (const char *format,...)
 Displays an error message on the TRACELOG filestream.
void tlog_warning (const char *format,...)
 Displays a warning message on the TRACELOG filestream.

Variables

TlogGlobal tlogGlobal

Class Documentation

struct TlogGlobal

Definition at line 123 of file tracelog.h.

Collaboration diagram for TlogGlobal:
Class Members
int debugOn
FILE * errorStream
char * functionList
int messageLevel

Define Documentation

Definition at line 143 of file tracelog.h.

Definition at line 63 of file tracelog.h.

Definition at line 140 of file tracelog.h.

#define TLOG_PRINT (   imodule,
  procname,
  level,
  args 
)
Value:
do {                                            \
  if (tlogGlobal.debugOn && tlog_test(imodule,":" #procname ":",level)) {  \
      TLOG_MESSAGE args;                                                  \
  }                                             \
} while(0)

Definition at line 147 of file tracelog.h.

#define TLOG_WARNING   if (tlogGlobal.debugOn) TLOG_MESSAGE

Definition at line 145 of file tracelog.h.


Function Documentation

void tlog_init ( FILE fileStream)

Initializes all TRACELOG operations and sets filestream for trace/log output.

Setting filestream to NULL suppresses all output. (documented in tracelog.h)

Definition at line 62 of file tracelog.c.

{
  int imodule;

#ifdef DEBUG_LTERM
  fprintf(stderr, "tlog_init:\n");
#endif

  /* Do not re-initialize */
  if (initGlobal)
    return;

  initGlobal = 1;

  /* Error output stream */
  tlogGlobal.errorStream = fileStream;

  /* Debugging is disabled initially */
  tlogGlobal.debugOn = 0;

  for (imodule=0; imodule<TLOG_MAXMODULES; imodule++) {
    tlogGlobal.messageLevel[imodule] = 0;
    tlogGlobal.functionList[imodule] = NULL;
  }

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void tlog_message ( const char *  format,
  ... 
)

Displays an error message on the TRACELOG filestream.

Definition at line 186 of file tracelog.c.

{
  va_list ap;             /* pointer to variable length argument list */

  if (tlogGlobal.errorStream == NULL)
    return;

  va_start(ap, format);   /* make ap point to first unnamed arg */
  vfprintf(tlogGlobal.errorStream, format, ap);
  va_end(ap);             /* clean up */
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int tlog_set_level ( int  imodule,
int  messageLevel,
const char *  functionList 
)

Set diagnostic message display level for module no.

IMODULE. (0 <= IMODULE < TLOG_MAXMODULES)

MESSAGELEVEL (>=0) specifies the diagnostic message display level: only diagnostic messages with level values >= MESSAGELEVEL are printed (For example, level 10, 11, ...: outermost level; level 20, 21, ...: next inner level; ... level 50, 51, ...: innermost level)

The message SUBLEVEL threshold is defined as MESSAGELEVEL%10 (ranging from 0 to 9). Only those diagnostic messages with sublevel values >= SUBLEVEL threshold are displayed Usually, the SUBLEVEL threshold values are interpreted as 0 => print single message per selected procedure. 1...9 => print only messages upto selected sublevel.

Setting MESSAGELEVEL to zero and FUNCTIONLIST to null for all modules disables debugging and printing of warning messages. (This is the initial configuration following the call to lterm_init.) Setting MESSAGELEVEL to 1 for atleast one module enables debugging and causes warning messages for all modules to be printed.

FUNCTIONLIST is a colon-separated string of function names, e.g., "func_a:func_b". Trace/log messages for functions in this list are always output if debugging is enabled provided the sublevel values exceed the threshold, regardless of full message level values. If FUNCTIONLIST contains a single method name without a class name, or a class name without a method name, then the missing portion is assumed to be wild-carded.

Returns 0 on success, -1 otherwise (i.e., for invalid module numbers)

Set diagnostic message display level for module no.

Returns:
0 on success, or -1 on error.

Definition at line 95 of file tracelog.c.

{
  int j;

#ifdef DEBUG_LTERM
  fprintf(stderr, "tlog_set_level:%d, %d\n", imodule, messageLevel);
#endif

  if ((imodule < 0) || (imodule >= TLOG_MAXMODULES))
    return -1;

  /* Message level */
  tlogGlobal.messageLevel[imodule] = messageLevel;

  /* Free function list string */
  free(tlogGlobal.functionList[imodule]);

  if (functionList == NULL) {
    tlogGlobal.functionList[imodule] = NULL;

  } else {
    /* Duplicate function list string */
    int slen = strlen(functionList);
    char *stem;

    if (slen > 1000) slen = 1000;

    stem = malloc((unsigned int) slen+3);
    strncpy(&stem[1], functionList, (unsigned int) slen);
    stem[0] = ':';
    stem[slen+1] = ':';
    stem[slen+2] = '\0';

    tlogGlobal.functionList[imodule] = stem;

    if (messageLevel > 0) {
      tlog_warning("tlog_set_level: module %d, functionList=\"%s\"\n",
                                    imodule, tlogGlobal.functionList[imodule]);
    }
  }

  /* Turn on debugging only if needed */
  tlogGlobal.debugOn = 0;

  if (tlogGlobal.errorStream != NULL) {
    for (j=0; j<TLOG_MAXMODULES; j++) {
      if ((tlogGlobal.messageLevel[j] > 0) ||
          (tlogGlobal.functionList != NULL))
        tlogGlobal.debugOn = 1;
    }
  }

  if (messageLevel > 0) {
    tlog_warning("tlog_set_level: module %d, messageLevel=%d\n",
                                    imodule, messageLevel);
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int tlog_test ( int  imodule,
char *  procstr,
int  level 
)

Determines whether trace/log message is to be displayed for specified module at specified message level.

Returns:
1 (true) if message should be displayed, 0 otherwise

Definition at line 160 of file tracelog.c.

{
  if (tlogGlobal.errorStream == NULL)
    return 0;

  if ((imodule < 0) || (imodule >= TLOG_MAXMODULES))
    return 0;

  if ( (level <= tlogGlobal.messageLevel[imodule]) ||
         ((tlogGlobal.functionList[imodule] != NULL) &&
          ( (strstr(tlogGlobal.functionList[imodule],procstr) != NULL) ||
             (strstr(procstr,tlogGlobal.functionList[imodule]) != NULL)) ) ) {
    /* Display message */
#if defined(USE_NSPR_BASE) && !defined(DEBUG_LTERM)
    PR_LogPrint("%s%2d: ", procstr, level);
#else
    fprintf(tlogGlobal.errorStream, "%s%2d: ", procstr, level);
#endif
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

void tlog_warning ( const char *  format,
  ... 
)

Displays a warning message on the TRACELOG filestream.

Definition at line 201 of file tracelog.c.

{
  va_list ap;             /* pointer to variable length argument list */

  if ((tlogGlobal.errorStream == NULL) || !tlogGlobal.debugOn)
    return;

  va_start(ap, format);   /* make ap point to first unnamed arg */
  vfprintf(tlogGlobal.errorStream, format, ap);
  va_end(ap);             /* clean up */
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 54 of file tracelog.c.