X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=res%2Blog%2Fgw-log.c;h=2c5b5e1e6a00640281fb078d63ad3ce9f377e56f;hb=9f5629c93687790acce8ef189cfac986f3c2d2e6;hp=5ea38f850cf26b2ef134317fe27b7cfe3294b104;hpb=e1ec9d39463f431383547891f38e30f2ff17842c;p=egate.git diff --git a/res+log/gw-log.c b/res+log/gw-log.c index 5ea38f8..2c5b5e1 100644 --- a/res+log/gw-log.c +++ b/res+log/gw-log.c @@ -47,7 +47,16 @@ * 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 @@ -86,6 +95,7 @@ #include #include #include +#include #include @@ -185,7 +195,7 @@ int gw_log_file (unsigned level_a, const char *fname_a) 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; @@ -203,7 +213,7 @@ int gw_log (unsigned level_a, const char *event_type, const char *format, ...) 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, @@ -234,3 +244,60 @@ int gw_log (unsigned level_a, const char *event_type, const char *format, ...) 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; +}