This repository has been archived by the owner on Oct 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mlog.c
78 lines (69 loc) · 2.11 KB
/
mlog.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* $Id$
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* For alternative licensing terms, contact licensing@tri-dsystems.com.
*
* Copyright 2005,2006 TRI-D Systems, Inc.
*/
#include "ident.h"
RCSID("$Id$")
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#include "extern.h"
/*
* By default we log at syslog debug level, and depend on system
* configuration to throw away noise. This has a slight race;
* on HUP we might change this, but it won't be noticed right away.
* No big deal; certainly not worth even an uncontended lock.
*/
int log_level = LOG_DEBUG;
int log_facility = LOG_AUTH;
static int log_syslog = 0; /* log to stderr or syslog? */
/* maybe log */
void
mlog(int level, const char *fmt, ...)
{
va_list ap;
char ffmt[1024]; /* modified fmt for stderr */
/* discard if log level isn't high enough */
if (level > log_level)
return;
/* map "super debug" levels to syslog debug level */
if (level > LOG_DEBUG)
level = LOG_DEBUG;
va_start(ap, fmt);
if (log_syslog) {
(void) vsyslog(level, fmt, ap);
} else {
/* prefix progname and suffix '\n' to fmt */
(void) snprintf(ffmt, sizeof(ffmt), "%s: %s\n", progname, fmt);
ffmt[1023] = '\0';
(void) vfprintf(stderr, ffmt, ap);
}
va_end(ap);
return;
}
/* start logging to syslog instead of stderr */
void
mopenlog(const char *ident, int logopt)
{
openlog(ident, logopt, log_facility);
log_syslog = 1;
return;
}