/*****************************************************************
**
** @(#) log.c -- The ZKT error logging module
**
** Copyright (c) June 2008, Holger Zuleger HZnet. All rights reserved.
**
** This software is open source.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
**
** Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
**
** Neither the name of Holger Zuleger HZnet nor the names of its contributors may
** be used to endorse or promote products derived from this software without
** specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
** POSSIBILITY OF SUCH DAMAGE.
**
**
*****************************************************************/
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <ctype.h>
# include <time.h>
# include <assert.h>
# include <errno.h>
# include <syslog.h>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
# include "config_zkt.h"
# include "misc.h"
# include "debug.h"
#define extern
# include "log.h"
#undef extern
/*****************************************************************
** module internal vars & declarations
*****************************************************************/
static int lg_minfilelevel;
static int lg_syslogging;
static int lg_minsyslevel;
static long lg_errcnt;
static const char *lg_progname;
typedef struct {
const char *str;
int syslog_level;
} lg_symtbl_t;
};
/*****************************************************************
** function definitions (for function declarations see log.h)
*****************************************************************/
/*****************************************************************
** lg_fileopen (path, name) -- open the log file
** Name is a (absolute or relative) file or directory name.
** If path is given and name is a relative path name then path
** is prepended to name.
** returns the open file pointer or NULL on error
*****************************************************************/
{
int len;
struct tm *t;
return NULL;
else
# ifdef LOG_TEST
# endif
if ( is_directory (fname) )
{
# ifdef LOG_TEST
# endif
}
# ifdef LOG_TEST
# endif
return NULL;
return fp;
}
/*****************************************************************
** lg_str2lvl (level_name)
*****************************************************************/
{
lg_symtbl_t *p;
if ( !name )
return LG_NONE;
return p->level;
return LG_NONE;
}
/*****************************************************************
** lg_lvl2syslog (level)
*****************************************************************/
{
lg_symtbl_t *p;
return p->syslog_level;
return LOG_DEBUG; /* if not found, return DEBUG as default */
}
/*****************************************************************
** lg_str2syslog (facility_name)
*****************************************************************/
{
lg_symtbl_t *p;
if ( !facility )
return LG_NONE;
return p->syslog_level;
return LG_NONE;
}
/*****************************************************************
** lg_lvl2str (level)
*****************************************************************/
{
lg_symtbl_t *p;
return "none";
return p->str;
return "fatal";
}
/*****************************************************************
** lg_geterrcnt () -- returns the current value of the internal
** error counter
*****************************************************************/
long lg_geterrcnt ()
{
return lg_errcnt;
}
/*****************************************************************
** lg_seterrcnt () -- sets the internal error counter
** returns the current value
*****************************************************************/
{
}
/*****************************************************************
** lg_reseterrcnt () -- resets the internal error counter to 0
** returns the current value
*****************************************************************/
long lg_reseterrcnt ()
{
return lg_seterrcnt (0L);
}
/*****************************************************************
** lg_open (prog, facility, syslevel, path, file, filelevel)
** -- open the log channel
** return values:
** 0 on success
** -1 on file open error
*****************************************************************/
int lg_open (const char *progname, const char *facility, const char *syslevel, const char *path, const char *file, const char *filelevel)
{
int sysfacility;
dbg_val6 ("lg_open (%s, %s, %s, %s, %s, %s)\n", progname, facility, syslevel, path, file, filelevel);
if ( sysfacility >= 0 )
{
lg_syslogging = 1;
}
{
return -1;
}
return 0;
}
/*****************************************************************
** lg_close () -- close the open filepointer for error logging
** return 0 if no error log file is currently open,
** otherwise the return code of fclose is returned.
*****************************************************************/
int lg_close ()
{
int ret = 0;
if ( lg_syslogging )
{
closelog ();
lg_syslogging = 0;
}
if ( lg_fp )
{
}
return ret;
}
/*****************************************************************
** lg_zone_start (domain)
** -- reopen the log channel
** return values:
** 0 on success
** -1 on file open error
*****************************************************************/
{
if ( lg_fp )
}
/*****************************************************************
** lg_zone_end (domain)
** -- close the (reopened) log channel
** return values:
** 0 on success
** -1 on file open error
*****************************************************************/
int lg_zone_end ()
{
{
lg_close ();
return 1;
}
return 0;
}
/*****************************************************************
**
** lg_args (level, argc, argv[])
** log all command line arguments (up to a length of 511 chars)
** with priority level
**
*****************************************************************/
{
int len;
int i;
len = 0;
#if 1
#else
#endif
}
/*****************************************************************
**
** lg_mesg (level, fmt, ...)
**
** Write a given message to the error log file and counts
** all messages written with an level greater than LOG_ERR.
**
** All messages will be on one line in the logfile, so it's
** not necessary to add an '\n' to the message.
**
** To call this function before an elog_open() is called is
** useless!
**
*****************************************************************/
{
struct tm *t;
format[0] ='\0';
{
#if defined (LOG_WITH_LEVEL) && LOG_WITH_LEVEL
#endif
}
{
#if defined (LOG_WITH_TIMESTAMP) && LOG_WITH_TIMESTAMP
#endif
#if defined (LOG_WITH_PROGNAME) && LOG_WITH_PROGNAME
if ( lg_progname )
#endif
#if defined (LOG_WITH_LEVEL) && LOG_WITH_LEVEL
#endif
}
lg_errcnt++;
}
#ifdef LOG_TEST
const char *progname;
{
const char *levelstr;
const char *newlevelstr;
int level;
int err;
if ( --argc )
else
levelstr = "fatal";
#if 1
"user",
#else
"none",
#endif
levelstr, ".",
#if 1
"test.log",
#else
NULL,
#endif
newlevelstr)) )
else
{
}
return 0;
}
#endif