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