1124758Semax/*
2124758Semax * log.c
3124758Semax *
4124758Semax * Copyright (c) 2004 Maksim Yevmenkin <m_evmenkin@yahoo.com>
5124758Semax * All rights reserved.
6124758Semax *
7124758Semax * Redistribution and use in source and binary forms, with or without
8124758Semax * modification, are permitted provided that the following conditions
9124758Semax * are met:
10124758Semax * 1. Redistributions of source code must retain the above copyright
11124758Semax *    notice, this list of conditions and the following disclaimer.
12124758Semax * 2. Redistributions in binary form must reproduce the above copyright
13124758Semax *    notice, this list of conditions and the following disclaimer in the
14124758Semax *    documentation and/or other materials provided with the distribution.
15124758Semax *
16124758Semax * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17124758Semax * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18124758Semax * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19124758Semax * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20124758Semax * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21124758Semax * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22124758Semax * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23124758Semax * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24124758Semax * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25124758Semax * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26124758Semax * SUCH DAMAGE.
27124758Semax *
28124758Semax * $Id: log.c,v 1.1 2004/01/07 23:15:00 max Exp $
29124758Semax * $FreeBSD$
30124758Semax */
31124758Semax
32124758Semax#include <sys/types.h>
33124758Semax#include <stdarg.h>
34124758Semax#include <syslog.h>
35124758Semax
36124758Semaxvoid
37124758Semaxlog_open(char const *prog, int32_t log2stderr)
38124758Semax{
39124758Semax	openlog(prog, LOG_PID|LOG_NDELAY|(log2stderr? LOG_PERROR:0), LOG_USER);
40124758Semax}
41124758Semax
42124758Semaxvoid
43124758Semaxlog_close(void)
44124758Semax{
45124758Semax	closelog();
46124758Semax}
47124758Semax
48124758Semaxvoid
49124758Semaxlog_emerg(char const *message, ...)
50124758Semax{
51124758Semax	va_list	ap;
52124758Semax
53124758Semax	va_start(ap, message);
54124758Semax	vsyslog(LOG_EMERG, message, ap);
55124758Semax	va_end(ap);
56124758Semax}
57124758Semax
58124758Semaxvoid
59124758Semaxlog_alert(char const *message, ...)
60124758Semax{
61124758Semax	va_list	ap;
62124758Semax
63124758Semax	va_start(ap, message);
64124758Semax	vsyslog(LOG_ALERT, message, ap);
65124758Semax	va_end(ap);
66124758Semax}
67124758Semax
68124758Semaxvoid
69124758Semaxlog_crit(char const *message, ...)
70124758Semax{
71124758Semax	va_list	ap;
72124758Semax
73124758Semax	va_start(ap, message);
74124758Semax	vsyslog(LOG_CRIT, message, ap);
75124758Semax	va_end(ap);
76124758Semax}
77124758Semax
78124758Semaxvoid
79124758Semaxlog_err(char const *message, ...)
80124758Semax{
81124758Semax	va_list	ap;
82124758Semax
83124758Semax	va_start(ap, message);
84124758Semax	vsyslog(LOG_ERR, message, ap);
85124758Semax	va_end(ap);
86124758Semax}
87124758Semax
88124758Semaxvoid
89124758Semaxlog_warning(char const *message, ...)
90124758Semax{
91124758Semax	va_list	ap;
92124758Semax
93124758Semax	va_start(ap, message);
94124758Semax	vsyslog(LOG_WARNING, message, ap);
95124758Semax	va_end(ap);
96124758Semax}
97124758Semax
98124758Semaxvoid
99124758Semaxlog_notice(char const *message, ...)
100124758Semax{
101124758Semax	va_list	ap;
102124758Semax
103124758Semax	va_start(ap, message);
104124758Semax	vsyslog(LOG_NOTICE, message, ap);
105124758Semax	va_end(ap);
106124758Semax}
107124758Semax
108124758Semaxvoid
109124758Semaxlog_info(char const *message, ...)
110124758Semax{
111124758Semax	va_list	ap;
112124758Semax
113124758Semax	va_start(ap, message);
114124758Semax	vsyslog(LOG_INFO, message, ap);
115124758Semax	va_end(ap);
116124758Semax}
117124758Semax
118124758Semaxvoid
119124758Semaxlog_debug(char const *message, ...)
120124758Semax{
121124758Semax	va_list	ap;
122124758Semax
123124758Semax	va_start(ap, message);
124124758Semax	vsyslog(LOG_DEBUG, message, ap);
125124758Semax	va_end(ap);
126124758Semax}
127124758Semax
128