]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_utilities/lib/logging.cpp
Security-59306.11.20.tar.gz
[apple/security.git] / OSX / libsecurity_utilities / lib / logging.cpp
1 /*
2 * Copyright (c) 2000-2004,2011,2014 Apple 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
37 namespace Security
38 {
39
40 namespace Syslog
41 {
42
43 //
44 // Open and initialize logging
45 //
46 void open(const char *ident, int facility, int options /*= 0*/)
47 {
48 ::openlog(ident, options, facility);
49 }
50
51
52 //
53 // General output method
54 //
55
56 static void output(int priority, const char *format, va_list args) __attribute__((format(printf, 2, 0)));
57
58
59 static void output(int priority, const char *format, va_list args)
60 {
61 ::vsyslog(priority, format, args);
62 }
63
64
65 //
66 // Priority-specific wrappers
67 //
68 void syslog(int priority, const char *format, ...)
69 { va_list args; va_start(args, format); output(priority, format, args); va_end(args); }
70
71 void emergency(const char *format, ...)
72 { va_list args; va_start(args, format); output(LOG_EMERG, format, args); va_end(args); }
73 void alert(const char *format, ...)
74 { va_list args; va_start(args, format); output(LOG_ALERT, format, args); va_end(args); }
75 void critical(const char *format, ...)
76 { va_list args; va_start(args, format); output(LOG_CRIT, format, args); va_end(args); }
77 void error(const char *format, ...)
78 { va_list args; va_start(args, format); output(LOG_ERR, format, args); va_end(args); }
79 void warning(const char *format, ...)
80 { va_list args; va_start(args, format); output(LOG_WARNING, format, args); va_end(args); }
81 void notice(const char *format, ...)
82 { va_list args; va_start(args, format); output(LOG_NOTICE, format, args); va_end(args); }
83 void info(const char *format, ...)
84 { va_list args; va_start(args, format); output(LOG_INFO, format, args); va_end(args); }
85 void debug(const char *format, ...)
86 { va_list args; va_start(args, format); output(LOG_DEBUG, format, args); va_end(args); }
87
88
89 //
90 // Enable mask operation
91 //
92 int mask()
93 {
94 int mask;
95 ::setlogmask(mask = ::setlogmask(0));
96 return mask;
97 }
98
99 void upto(int priority)
100 {
101 ::setlogmask(LOG_UPTO(priority));
102 }
103
104 void enable(int priority)
105 {
106 ::setlogmask(::setlogmask(0) | LOG_MASK(priority));
107 }
108
109 void disable(int priority)
110 {
111 ::setlogmask(::setlogmask(0) & ~LOG_MASK(priority));
112 }
113
114 } // end namespace Syslog
115
116 } // end namespace Security