* Europagate, 1994-1995.
*
* $Log: gw-log.c,v $
- * Revision 1.10 1995/05/16 09:40:48 adam
+ * Revision 1.13 1995/12/01 12:41:03 adam
+ * Bug fix.
+ *
+ * Revision 1.12 1995/12/01 12:24:17 adam
+ * New function: gw_log_mask_str.
+ *
+ * Revision 1.11 1995/11/09 09:54:28 adam
+ * More readable logging format.
+ *
+ * Revision 1.10 1995/05/16 09:40:48 adam
* LICENSE.
*
* Revision 1.9 1995/04/19 12:12:06 adam
#include <unistd.h>
#include <time.h>
#include <errno.h>
+#include <ctype.h>
#include <gw-log.h>
int gw_log (unsigned level_a, const char *event_type, const char *format, ...)
{
- static char emit_str[2048];
+ static char emit_str[4096];
struct file_mask *list;
struct timeval tv;
struct timezone tz;
gettimeofday (&tv, &tz);
memcpy (&tms, localtime (&tv.tv_sec), sizeof(tms));
- sprintf (emit_str, "%s %d %02d%02d%02d%02d%02d%02d%03d %d %s ",
+ sprintf (emit_str, "%s %d %02d%02d%02d %02d%02d%02d %03d %d %s ",
app_name, session,
tms.tm_year, 1+tms.tm_mon, tms.tm_mday,
tms.tm_hour, tms.tm_min, tms.tm_sec,
va_end (ap);
return err;
}
+
+static struct {
+ int mask;
+ char *name;
+} mask_names[] =
+{
+ { GW_LOG_ALL, "all" },
+ { GW_LOG_DEFAULT, "default"},
+ { GW_LOG_DEFAULT, "def" },
+ { GW_LOG_FATAL, "fatal" },
+ { GW_LOG_WARN, "warn" },
+ { GW_LOG_ACCT, "acct" },
+ { GW_LOG_STAT, "stat" },
+ { GW_LOG_NOTICE, "notice" },
+ { GW_LOG_DEBUG, "debug" },
+ { GW_LOG_DEBUGN(0), "debug0" },
+ { GW_LOG_DEBUGN(1), "debug1" },
+ { GW_LOG_DEBUGN(2), "debug2" },
+ { GW_LOG_DEBUGN(3), "debug3" },
+ { GW_LOG_DEBUGN(4), "debug4" },
+ { GW_LOG_DEBUGN(5), "debug5" },
+ { GW_LOG_DEBUGN(6), "debug6" },
+ { GW_LOG_DEBUGN(7), "debug7" },
+ { GW_LOG_DEBUGN(8), "debug8" },
+ { GW_LOG_DEBUGN(8), "debug9" },
+ { 0, "none" },
+ { 0, NULL }
+};
+
+unsigned gw_log_mask_str (const char *str)
+{
+ const char *p;
+ int i;
+ unsigned level = GW_LOG_DEFAULT;
+
+ while (*str)
+ {
+ for (p = str; *p && *p != ','; p++)
+ ;
+ if (*str == '-' || isdigit(*str))
+ level = atoi (str);
+ else
+ for (i = 0; mask_names[i].name; i++)
+ if (strlen (mask_names[i].name) == p-str &&
+ memcmp (mask_names[i].name, str, p-str) == 0)
+ {
+ if (mask_names[i].mask)
+ level |= mask_names[i].mask;
+ else
+ level = 0;
+ }
+ if (*p == ',')
+ p++;
+ str = p;
+ }
+ return level;
+}