]> andersk Git - moira.git/blob - update/log.c
8edb2cac7cdd2dc694063f7b7f42323f2eb714f8
[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 #ifdef sun
28 #undef sparc /* varargs.h depends on sparc, which we use differently */
29 #endif /* sun */
30 #include <varargs.h>
31 #include "update.h"
32 #include <krb.h>
33
34 #ifndef __STDC__
35 #define const
36 #endif
37
38 #ifdef use_syslog
39 #include <syslog.h>
40 #else
41 #define use_tty
42 #endif
43
44 #ifdef use_syslog
45 int syslog_prio[] = {
46     LOG_DEBUG,
47     LOG_INFO,
48     LOG_WARNING,
49     LOG_ERR
50 };
51 #endif
52 int log_priority;
53 extern char *whoami;
54
55 void mr_update_com_err_hook(whoami, code, fmt, args)
56     const char *whoami;
57     long code;
58     const char *fmt;
59     va_list args;
60 {
61     char buf[BUFSIZ], *cp;
62     FILE _strbuf;
63
64 #ifndef use_syslog
65     strcpy(buf, whoami);
66     for (cp = buf; *cp; cp++)
67         ;
68     *cp++ = ':';
69     *cp++ = ' ';
70 #else
71     cp = buf;
72     *cp = '\0';
73 #endif
74     if (code) {
75         strcpy(cp, error_message(code));
76         while (*cp)
77             cp++;
78     }
79 #ifdef HAS_VSPRINTF
80     vsprintf(cp, fmt, args);
81 #else
82     _strbuf._flag = _IOWRT+_IOSTRG;
83     _strbuf._ptr = cp;
84     _strbuf._cnt = BUFSIZ-(cp-buf);
85     _doprnt(fmt, args, &_strbuf);
86     putc('\0', &_strbuf);
87 #endif
88 #ifdef use_syslog
89     syslog(syslog_prio[log_priority], "%s", buf);
90 #endif
91 #ifdef use_tty
92     puts(buf);
93 #endif
94 }
95
96 mr_update_initialize()
97 {
98     static int initialized = 0;
99     if (initialized)
100         return;
101 #ifdef use_syslog
102     openlog(whoami, LOG_PID, LOG_DAEMON);
103 #endif
104     (void) set_com_err_hook(mr_update_com_err_hook);
105     log_priority = log_INFO;
106     initialized = 1;
107 }
108
109
110 static char fmt[] = "[%s] %s";
111
112 #define def(name,level,prio) \
113     name(msg) \
114     char *msg; \
115 {\
116      register int old_prio; \
117      old_prio = log_priority; \
118      mr_update_initialize(); \
119      com_err(whoami, 0, fmt, level, msg); \
120      log_priority = old_prio; \
121 }
122
123 def(mr_log_error, "error", log_ERROR)
124 def(mr_log_warning, "warning", log_WARNING)
125 def(mr_log_info, "info", log_INFO)
126 def(mr_debug, "debug", log_DEBUG)
This page took 0.034697 seconds and 3 git commands to generate.