Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
tracelog.c File Reference
#include <stdlib.h>
#include <stdarg.h>
#include "unistring.h"
#include "tracelog.h"

Go to the source code of this file.

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)
 Sets TRACELOG display levels for module IMODULE (documented in tracelog.h)
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.
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
static int initGlobal = 0

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 
)

Sets TRACELOG display levels for module IMODULE (documented in tracelog.h)

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

int initGlobal = 0 [static]

Definition at line 56 of file tracelog.c.

Definition at line 54 of file tracelog.c.