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