]> andersk Git - moira.git/blame - update/log.c
fix RCS Id strings
[moira.git] / update / log.c
CommitLineData
7ac48069 1/* $Id$
2 *
de56407f 3 * handle logging for dcm and update server
4 *
7ac48069 5 * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
de56407f 8 */
de56407f 9
546bc43b 10#include <mit-copyright.h>
7ac48069 11#include <moira.h>
12#include "update_server.h"
13
de56407f 14#include <stdio.h>
7da203a3 15#include <stdarg.h>
7ac48069 16
7da203a3 17#include "update.h"
36689901 18
de56407f 19#ifdef use_syslog
20#include <syslog.h>
21#else
22#define use_tty
23#endif
24
7ac48069 25RCSID("$Header$");
26
27void mr_update_com_err_hook(const char *whoami, long code,
28 const char *fmt, va_list args);
29
de56407f 30#ifdef use_syslog
31int syslog_prio[] = {
5eaef520 32 LOG_DEBUG,
33 LOG_INFO,
34 LOG_WARNING,
35 LOG_ERR
de56407f 36};
37#endif
7da203a3 38extern int log_priority;
29ce7010 39extern char *whoami;
de56407f 40
5eaef520 41void mr_update_com_err_hook(const char *whoami, long code,
42 const char *fmt, va_list args)
de56407f 43{
5eaef520 44 char buf[BUFSIZ], *cp;
de56407f 45
46#ifndef use_syslog
5eaef520 47 strcpy(buf, whoami);
48 for (cp = buf; *cp; cp++)
49 ;
50 *cp++ = ':';
51 *cp++ = ' ';
de56407f 52#else
5eaef520 53 cp = buf;
54 *cp = '\0';
de56407f 55#endif
5eaef520 56 if (code)
57 {
58 strcpy(cp, error_message(code));
59 while (*cp)
60 cp++;
de56407f 61 }
5eaef520 62 vsprintf(cp, fmt, args);
de56407f 63#ifdef use_syslog
5eaef520 64 syslog(syslog_prio[log_priority], "%s", buf);
de56407f 65#endif
66#ifdef use_tty
5eaef520 67 puts(buf);
de56407f 68#endif
69}
70
7ac48069 71void mr_update_initialize(void)
de56407f 72{
5eaef520 73 static int initialized = 0;
74 if (initialized)
75 return;
de56407f 76#ifdef use_syslog
5eaef520 77 openlog(whoami, LOG_PID, LOG_DAEMON);
de56407f 78#endif
5eaef520 79 set_com_err_hook(mr_update_com_err_hook);
80 log_priority = log_INFO;
81 initialized = 1;
de56407f 82}
29ce7010 83
84
85static char fmt[] = "[%s] %s";
86
5eaef520 87#define def(name, level, prio) \
7ac48069 88void name(char *msg)\
29ce7010 89{\
44d12d58 90 int old_prio; \
5eaef520 91 old_prio = log_priority; \
92 mr_update_initialize(); \
93 com_err(whoami, 0, fmt, level, msg); \
94 log_priority = old_prio; \
29ce7010 95}
96
2ad0a777 97def(mr_log_error, "error", log_ERROR)
98def(mr_log_warning, "warning", log_WARNING)
99def(mr_log_info, "info", log_INFO)
100def(mr_debug, "debug", log_DEBUG)
This page took 0.093406 seconds and 5 git commands to generate.