]> andersk Git - moira.git/blob - update/log.c
sms -> moira
[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 #include <varargs.h>
28 #include "update.h"
29 #include <krb.h>
30
31 #ifndef __STDC__
32 #define const
33 #endif
34
35 #ifdef use_syslog
36 #include <syslog.h>
37 #else
38 #define use_tty
39 #endif
40
41 #ifdef use_syslog
42 int syslog_prio[] = {
43     LOG_DEBUG,
44     LOG_INFO,
45     LOG_WARNING,
46     LOG_ERR
47 };
48 #endif
49 int log_priority;
50 extern char *whoami;
51
52 void mr_update_com_err_hook(whoami, code, fmt, args)
53     const char *whoami;
54     long code;
55     const char *fmt;
56     va_list args;
57 {
58     char buf[BUFSIZ], *cp;
59 #ifndef __STDC__
60     FILE _strbuf;
61 #endif
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 __STDC__
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.051024 seconds and 5 git commands to generate.