view src/log.c @ 193:021d145e34e9 noffle

[svn] * src/fetch.c: Only leave articles in the requested list if the error fetching them was fatal. Otherwise article requests will accumulate indefinitely (e.g retrieving through NNTPcache when it can't find the body of an article, now or event. Yes, this happened to me; I had nearly 2000 requests backed up and never being cleared). * src/group.c: The weekend's change introduced code that causes a bus error on Sparc ( *(time_t *)p = xxx ). Replace with a safe memcpy, and also use memcpy when reading the Entry and time items to remove warnings on Sparc compilation.
author bears
date Mon, 22 Oct 2001 14:41:43 +0100
parents fed1334d766b
children 755e03bc7dcf
line wrap: on
line source

/*
  log.c

  $Id: log.c 300 2001-08-05 08:24:22Z bears $
*/

#if HAVE_CONFIG_H
#include <config.h>
#endif

#include <syslog.h>
#include <stdarg.h>
#include "common.h"
#include "log.h"
#include "portable.h"

#define MAXLENGTH 240

#define	DEFAULT_DBG_MASK	LOG_DBG_NONE

struct
{
    Bool interactive;
    unsigned debugMask;
} log = { FALSE, DEFAULT_DBG_MASK };

void
Log_init( const char *name, Bool interactive, int facility )
{
    int option = LOG_PID | LOG_CONS;

    log.interactive = interactive;
    openlog( name, option, facility );
}

#define DO_LOG( LEVEL )               \
    va_list ap;                       \
    Str t;                            \
                                      \
    va_start( ap, fmt );              \
    vsnprintf( t, MAXCHAR, fmt, ap ); \
    if ( MAXLENGTH < MAXCHAR )        \
        t[ MAXLENGTH ] = '\0';        \
    syslog( LEVEL, "%s", t );         \
    if ( log.interactive )            \
        fprintf( stderr, "%s\n", t );   \
    va_end( ap );

void
Log_inf( const char *fmt, ... )
{
    DO_LOG( LOG_INFO );
}

void
Log_err( const char *fmt, ... )
{
    DO_LOG( LOG_ERR );
}

/* Ensure the condition "cond" is true; otherwise log an error and return 1 */
int 
Log_check(int cond, const char *fmt, ... )
{
  if (!cond) {
    DO_LOG( LOG_ERR );
    return 1;
  }
  return 0;
}

void
Log_ntc( const char *fmt, ... )
{
    DO_LOG( LOG_NOTICE );
}

void
Log_dbg( unsigned subsystem, const char *fmt, ... )
{
    if ( ( subsystem & log.debugMask ) != 0 ) {
	DO_LOG( LOG_DEBUG );
    }
}

void
Log_setDbgMask( unsigned mask )
{
    /* A non-zero mask always include Noffle logs */
    if ( mask != 0 )
	mask |= LOG_DBG_NOFFLE;

    log.debugMask = mask;
}