]>
git.ipfire.org Git - thirdparty/lldpd.git/blob - src/log.c
1 /* $OpenBSD: log.c,v 1.11 2007/12/07 17:17:00 reyk Exp $ */
4 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
6 * Permission to use, copy, modify, and/or 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.
21 #include <sys/types.h>
31 static void vlog(int, const char *, va_list);
32 static void logit(int, const char *, ...);
35 log_init(int n_debug
, const char *progname
)
40 openlog(progname
, LOG_PID
| LOG_NDELAY
, LOG_DAEMON
);
46 logit(int pri
, const char *fmt
, ...)
56 vlog(int pri
, const char *fmt
, va_list ap
)
61 /* best effort in out of mem situations */
62 if (asprintf(&nfmt
, "%s\n", fmt
) == -1) {
63 vfprintf(stderr
, fmt
, ap
);
64 fprintf(stderr
, "\n");
66 vfprintf(stderr
, nfmt
, ap
);
71 vsyslog(pri
, fmt
, ap
);
76 log_warn(const char *emsg
, ...)
81 /* best effort to even work in out of memory situations */
83 logit(LOG_CRIT
, "%s", strerror(errno
));
87 if (asprintf(&nfmt
, "%s: %s", emsg
, strerror(errno
)) == -1) {
89 vlog(LOG_CRIT
, emsg
, ap
);
90 logit(LOG_CRIT
, "%s", strerror(errno
));
92 vlog(LOG_CRIT
, nfmt
, ap
);
100 log_warnx(const char *emsg
, ...)
105 vlog(LOG_CRIT
, emsg
, ap
);
110 log_info(const char *emsg
, ...)
115 vlog(LOG_INFO
, emsg
, ap
);
120 log_debug(const char *emsg
, ...)
126 vlog(LOG_DEBUG
, emsg
, ap
);
132 fatal(const char *emsg
)
135 logit(LOG_CRIT
, "fatal: %s", strerror(errno
));
138 logit(LOG_CRIT
, "fatal: %s: %s",
139 emsg
, strerror(errno
));
141 logit(LOG_CRIT
, "fatal: %s", emsg
);
147 fatalx(const char *emsg
)