1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
/*
* Program: $RCSfile: log.c,v $ $Revision: 4.4 $
*
* Purpose: Log facility of internet "youbin" service.
*
* Author: K.Agusa agusa@nuie.nagoya-u.ac.jp
* S.Yamamoto yamamoto@nuie.nagoya-u.ac.jp
*
* Date: 1993/12/27
* Modified: $Date: 1995/03/26 11:33:01 $
*
* Copyright: K.Agusa and S.Yamamoto 1993 - 1995
*
* The X Consortium, and any party obtaining a copy of these files from
* the X Consortium, directly or indirectly, is granted, free of charge,
* a full and unrestricted irrevocable, world-wide, paid up, royalty-free,
* nonexclusive right and license to deal in this software and documentation
* files (the "Software"), including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons who receive copies from any such
* party to do so. This license includes without limitation a license to do
* the foregoing actions under any patents of the party supplying this
* software to the X Consortium.
*/
#ifndef lint
static char rcsid[] =
"$Id: log.c,v 4.4 1995/03/26 11:33:01 yamamoto Exp $";
#endif
#include <sys/types.h>
#include <netinet/in.h>
#include <stdio.h>
#include "youbin.h"
#include "server.h"
/*
* Variable argument list.
*
* USE_STDARG: Use ANSI routines.
* USE_VARARGS Use UNIX's native routines.
*/
#ifdef USE_STDARG
#include <stdarg.h>
#define VARARGS_PROTO(func, firstArg, type) func(type firstArg, ...)
#define VA_START(argsPtr, firstArg) va_start(argsPtr, firstArg)
#define VA_1ST_ARG(argsPtr, firstArg, type) firstArg
#else /* USE_VARARGS */
#include <varargs.h>
#define VARARGS_PROTO(func, firstArg, type) func(va_alist) va_dcl
#define VA_START(argsPtr, firstArg) va_start(argsPtr)
#define VA_1ST_ARG(argsPtr, firstArg, type) va_arg(argsPtr, type)
#endif /* USE_VARARGS */
/*
* Logging system messages.
*/
#ifdef SYSLOG
#include <syslog.h>
#endif
#ifndef SYSLOG_FACILITY
#define SYSLOG_FACILITY LOG_DAEMON
#endif
#ifndef LOG_DEBUG
#define LOG_DEBUG (-1) /* Dummy. */
#endif
#ifndef LOG_WARNING
#define LOG_WARNING (-1) /* Dummy. */
#endif
#ifndef LOG_INFO
#define LOG_INFO (-1) /* Dummy. */
#endif
#ifndef LOG_ERR
#define LOG_ERR (-1) /* Dummy. */
#endif
static int flag_syslog = ON; /* Always true. */
static int flag_console = ON; /* Always true. */
extern int errno;
//extern char *sys_errlist[];
/*
* Initialize.
*/
void
init_log()
{
#ifdef SYSLOG
openlog(prog_name, (LOG_CONS | LOG_PID), SYSLOG_FACILITY);
#endif
}
/*
* Top level functions.
*/
void
VARARGS_PROTO(debug_log, va_args, char *)
{
char buff_log[LOG_LEN + 1];
va_list args;
if (debug_mode) {
VA_START(args, va_args);
vsprintf(buff_log, VA_1ST_ARG(args, va_args, char *), args);
va_end(args);
output_log(LOG_DEBUG, buff_log);
}
}
void
VARARGS_PROTO(warn_log, va_args, char *)
{
char buff_log[LOG_LEN + 1];
va_list args;
VA_START(args, va_args);
vsprintf(buff_log, VA_1ST_ARG(args, va_args, char *), args);
va_end(args);
output_log(LOG_WARNING, buff_log);
}
void
VARARGS_PROTO(info_log, va_args, char *)
{
char buff_log[LOG_LEN + 1];
va_list args;
VA_START(args, va_args);
vsprintf(buff_log, VA_1ST_ARG(args, va_args, char *), args);
va_end(args);
output_log(LOG_INFO, buff_log);
}
void
VARARGS_PROTO(error_log, va_args, char *)
{
char buff_log[LOG_LEN + 1];
va_list args;
VA_START(args, va_args);
vsprintf(buff_log, VA_1ST_ARG(args, va_args, char *), args);
va_end(args);
output_log(LOG_ERR, buff_log);
}
void
VARARGS_PROTO(trace, va_args, char *)
{
/* Output trace message to syslog with LOG_INFO level. */
char buff_log[LOG_LEN + 1];
va_list args;
if (trace_mode) {
VA_START(args, va_args);
vsprintf(buff_log, VA_1ST_ARG(args, va_args, char *), args);
va_end(args);
output_log(LOG_INFO, buff_log);
}
}
void
sys_error_log(mess)
char *mess;
{
/* Output system error messages to syslog. */
char buff_log[LOG_LEN + 1];
sprintf(buff_log, "%s: %s\n", mess, sys_errlist[errno]);
output_log(LOG_ERR, buff_log);
}
/*
* Subroutines.
*/
void
output_log(syslog_level, mess)
int syslog_level;
char *mess;
{
#ifdef SYSLOG
if (flag_syslog) {
syslog(syslog_level, mess);
}
#endif /* SYSLOG */
if (flag_console) {
fprintf(stderr, "%s: %s", prog_name, mess);
}
}
|