2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1995-03-31 10:16:55 quinn
10 * Revision 1.1 1995/03/30 10:26:53 quinn
13 * Revision 1.9 1994/12/12 12:09:02 quinn
16 * Revision 1.8 1994/11/22 13:15:38 quinn
19 * Revision 1.7 1994/10/05 10:16:11 quinn
20 * Added xrealloc. Fixed bug in log.
22 * Revision 1.6 1994/10/04 14:02:19 quinn
25 * Revision 1.5 1994/09/28 13:07:41 adam
26 * Implemented log_mask_str.
28 * Revision 1.4 1994/09/27 20:04:13 quinn
31 * Revision 1.3 1994/08/18 08:18:48 quinn
32 * Added prefix to log_init.
34 * Revision 1.2 1994/08/17 14:27:53 quinn
37 * Revision 1.1 1994/08/17 13:23:15 quinn
50 static int l_level = LOG_DEFAULT_LEVEL;
51 static FILE *l_file = stderr;
52 static char l_prefix[30] = "log";
59 { LOG_FATAL, "fatal"},
60 { LOG_DEBUG, "debug"},
69 void log_init(int level, const char *prefix, const char *name)
72 if (prefix && *prefix)
73 strcpy(l_prefix, prefix);
74 if (!name || !*name || l_file != stderr)
76 if (!(l_file = fopen(name, "a")))
78 setbuffer(l_file, 0, 0);
81 void logf(int level, const char *fmt, ...)
84 char buf[4096], flags[1024];
87 if (!(level & l_level))
89 if (level & LOG_ERRNO)
92 for (i = 0; level && mask_names[i].name; i++)
93 if (mask_names[i].mask & level)
95 if (*mask_names[i].name)
96 sprintf(flags + strlen(flags), "[%s]", mask_names[i].name);
97 level -= mask_names[i].mask;
100 vsprintf(buf, fmt, ap);
102 sprintf(buf + strlen(buf), " [%s]", strerror(errno));
103 fprintf(l_file, "%s: %s %s\n", l_prefix, flags, buf);
107 int log_mask_str (const char *str)
110 int i, level = LOG_DEFAULT_LEVEL;
114 for (p = str; *p && *p != ','; p++)
116 if (*str == '-' || isdigit(*str))
119 for (i = 0; mask_names[i].name; i++)
120 if (strlen (mask_names[i].name) == p-str &&
121 memcmp (mask_names[i].name, str, p-str) == 0)
123 if (mask_names[i].mask)
124 level |= mask_names[i].mask;