1 /* $OpenBSD: log.c,v 1.2 2012/11/13 17:10:40 yasuoka Exp $ */
4 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
20 #include <sys/socket.h>
21 #include <netinet/in.h>
32 #include "debugutil.h"
36 extern int debugsyslog
;
38 void logit(int, const char *, ...);
43 extern char *__progname
;
48 openlog(__progname
, LOG_PID
| LOG_NDELAY
, LOG_DAEMON
);
54 logit(int pri
, const char *fmt
, ...)
64 vlog(int pri
, const char *fmt
, va_list ap
)
66 vlog_printf(pri
, fmt
, ap
);
71 log_warn(const char *emsg
, ...)
76 /* best effort to even work in out of memory situations */
78 logit(LOG_CRIT
, "%s", strerror(errno
));
82 if (asprintf(&nfmt
, "%s: %s", emsg
, strerror(errno
)) == -1) {
84 vlog(LOG_CRIT
, emsg
, ap
);
85 logit(LOG_CRIT
, "%s", strerror(errno
));
87 vlog(LOG_CRIT
, nfmt
, ap
);
95 log_warnx(const char *emsg
, ...)
100 vlog(LOG_CRIT
, emsg
, ap
);
105 log_info(const char *emsg
, ...)
110 vlog(LOG_INFO
, emsg
, ap
);
115 log_debug(const char *emsg
, ...)
119 if (debug
|| debugsyslog
) {
121 vlog(LOG_DEBUG
, emsg
, ap
);
127 fatal(const char *emsg
)
130 logit(LOG_CRIT
, "fatal: %s", strerror(errno
));
133 logit(LOG_CRIT
, "fatal: %s: %s",
134 emsg
, strerror(errno
));
136 logit(LOG_CRIT
, "fatal: %s", emsg
);
142 fatalx(const char *emsg
)