]> andersk Git - moira.git/blob - update/log.c
Initial revision
[moira.git] / update / log.c
1 /*
2  *      $Source$
3  *      $Header$
4  */
5 /*  (c) Copyright 1988 by the Massachusetts Institute of Technology. */
6 /*  For copying and distribution information, please see the file */
7 /*  <mit-copyright.h>. */
8
9 #ifndef lint
10 static char *rcsid_log_c = "$Header$";
11 #endif  lint
12
13 /*
14  * handle logging for dcm and update server
15  *
16  * this should eventually use zephyr
17  */
18
19 /*
20  * define syslog for using syslog,
21  * default to tty
22  */
23
24 #include <mit-copyright.h>
25 #include <stdio.h>
26 #include "com_err.h"
27 #ifndef sun
28 #include <varargs.h>
29 #endif
30 #include "update.h"
31 #include <krb.h>
32
33 #ifndef __STDC__
34 #define const
35 #endif
36
37 #ifdef use_syslog
38 #include <syslog.h>
39 #else
40 #define use_tty
41 #endif
42
43 #ifdef use_syslog
44 int syslog_prio[] = {
45     LOG_DEBUG,
46     LOG_INFO,
47     LOG_WARNING,
48     LOG_ERR
49 };
50 #endif
51 int log_priority;
52 extern char *whoami;
53
54 void mr_update_com_err_hook(whoami, code, fmt, args)
55     const char *whoami;
56     long code;
57     const char *fmt;
58     va_list args;
59 {
60     char buf[BUFSIZ], *cp;
61     FILE _strbuf;
62
63 #ifndef use_syslog
64     strcpy(buf, whoami);
65     for (cp = buf; *cp; cp++)
66         ;
67     *cp++ = ':';
68     *cp++ = ' ';
69 #else
70     cp = buf;
71     *cp = '\0';
72 #endif
73     if (code) {
74         strcpy(cp, error_message(code));
75         while (*cp)
76             cp++;
77     }
78 #ifdef HAS_VSPRINTF
79     vsprintf(cp, fmt, args);
80 #else
81     _strbuf._flag = _IOWRT+_IOSTRG;
82     _strbuf._ptr = cp;
83     _strbuf._cnt = BUFSIZ-(cp-buf);
84     _doprnt(fmt, args, &_strbuf);
85     putc('\0', &_strbuf);
86 #endif
87 #ifdef use_syslog
88     syslog(syslog_prio[log_priority], "%s", buf);
89 #endif
90 #ifdef use_tty
91     puts(buf);
92 #endif
93 }
94
95 mr_update_initialize()
96 {
97     static int initialized = 0;
98     if (initialized)
99         return;
100 #ifdef use_syslog
101     openlog(whoami, LOG_PID, LOG_DAEMON);
102 #endif
103     (void) set_com_err_hook(mr_update_com_err_hook);
104     log_priority = log_INFO;
105     initialized = 1;
106 }
107
108
109 static char fmt[] = "[%s] %s";
110
111 #define def(name,level,prio) \
112     name(msg) \
113     char *msg; \
114 {\
115      register int old_prio; \
116      old_prio = log_priority; \
117      mr_update_initialize(); \
118      com_err(whoami, 0, fmt, level, msg); \
119      log_priority = old_prio; \
120 }
121
122 def(mr_log_error, "error", log_ERROR)
123 def(mr_log_warning, "warning", log_WARNING)
124 def(mr_log_info, "info", log_INFO)
125 def(mr_debug, "debug", log_DEBUG)
This page took 0.063443 seconds and 5 git commands to generate.