1/*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25//
26// logging - message log support
27//
28#ifdef __MWERKS__
29# define _CPP_LOGGING
30#endif
31
32#include <security_utilities/logging.h>
33#include <security_utilities/globalizer.h>
34#include <cstdarg>
35#include <syslog.h>
36
37namespace Security
38{
39
40namespace Syslog
41{
42
43//
44// Open and initialize logging
45//
46void open(const char *ident, int facility, int options /*= 0*/)
47{
48	::openlog(ident, options, facility);
49}
50
51
52//
53// General output method
54//
55static void output(int priority, const char *format, va_list args)
56{
57	::vsyslog(priority, format, args);
58}
59
60
61//
62// Priority-specific wrappers
63//
64void syslog(int priority, const char *format, ...)
65{ va_list args; va_start(args, format); output(priority, format, args); va_end(args); }
66
67void emergency(const char *format, ...)
68{ va_list args; va_start(args, format); output(LOG_EMERG, format, args); va_end(args); }
69void alert(const char *format, ...)
70{ va_list args; va_start(args, format); output(LOG_ALERT, format, args); va_end(args); }
71void critical(const char *format, ...)
72{ va_list args; va_start(args, format); output(LOG_CRIT, format, args); va_end(args); }
73void error(const char *format, ...)
74{ va_list args; va_start(args, format); output(LOG_ERR, format, args); va_end(args); }
75void warning(const char *format, ...)
76{ va_list args; va_start(args, format); output(LOG_WARNING, format, args); va_end(args); }
77void notice(const char *format, ...)
78{ va_list args; va_start(args, format); output(LOG_NOTICE, format, args); va_end(args); }
79void info(const char *format, ...)
80{ va_list args; va_start(args, format); output(LOG_INFO, format, args); va_end(args); }
81void debug(const char *format, ...)
82{ va_list args; va_start(args, format); output(LOG_DEBUG, format, args); va_end(args); }
83
84
85//
86// Enable mask operation
87//
88int mask()
89{
90	int mask;
91	::setlogmask(mask = ::setlogmask(0));
92	return mask;
93}
94
95void upto(int priority)
96{
97	::setlogmask(LOG_UPTO(priority));
98}
99
100void enable(int priority)
101{
102	::setlogmask(::setlogmask(0) | LOG_MASK(priority));
103}
104
105void disable(int priority)
106{
107	::setlogmask(::setlogmask(0) & ~LOG_MASK(priority));
108}
109
110} // end namespace Syslog
111
112} // end namespace Security
113