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