]> andersk Git - moira.git/blob - update/log.c
eliminate use of the `register' keyword: let the compiler decide
[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
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 <stdarg.h>
28 #include "update.h"
29 #include <krb.h>
30
31 #ifdef use_syslog
32 #include <syslog.h>
33 #else
34 #define use_tty
35 #endif
36
37 #ifdef use_syslog
38 int syslog_prio[] = {
39   LOG_DEBUG,
40   LOG_INFO,
41   LOG_WARNING,
42   LOG_ERR
43 };
44 #endif
45 extern int log_priority;
46 extern char *whoami;
47
48 void mr_update_com_err_hook(const char *whoami, long code,
49                             const char *fmt, va_list args)
50 {
51   char buf[BUFSIZ], *cp;
52   FILE _strbuf;
53
54 #ifndef use_syslog
55   strcpy(buf, whoami);
56   for (cp = buf; *cp; cp++)
57     ;
58   *cp++ = ':';
59   *cp++ = ' ';
60 #else
61   cp = buf;
62   *cp = '\0';
63 #endif
64   if (code)
65     {
66       strcpy(cp, error_message(code));
67       while (*cp)
68         cp++;
69     }
70   vsprintf(cp, fmt, args);
71 #ifdef use_syslog
72   syslog(syslog_prio[log_priority], "%s", buf);
73 #endif
74 #ifdef use_tty
75   puts(buf);
76 #endif
77 }
78
79 mr_update_initialize(void)
80 {
81   static int initialized = 0;
82   if (initialized)
83     return;
84 #ifdef use_syslog
85   openlog(whoami, LOG_PID, LOG_DAEMON);
86 #endif
87   set_com_err_hook(mr_update_com_err_hook);
88   log_priority = log_INFO;
89   initialized = 1;
90 }
91
92
93 static char fmt[] = "[%s] %s";
94
95 #define def(name, level, prio) \
96 name(char *msg)\
97 {\
98    int old_prio; \
99    old_prio = log_priority; \
100    mr_update_initialize(); \
101    com_err(whoami, 0, fmt, level, msg); \
102    log_priority = old_prio; \
103 }
104
105 def(mr_log_error, "error", log_ERROR)
106 def(mr_log_warning, "warning", log_WARNING)
107 def(mr_log_info, "info", log_INFO)
108 def(mr_debug, "debug", log_DEBUG)
This page took 0.056122 seconds and 5 git commands to generate.