]>
Commit | Line | Data |
---|---|---|
52b7d2ce A |
1 | /* $Id: plog.h,v 1.5 2004/06/11 16:00:17 ludvigm Exp $ */ |
2 | ||
3 | /* | |
4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
5 | * All rights reserved. | |
6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * 3. Neither the name of the project nor the names of its contributors | |
16 | * may be used to endorse or promote products derived from this software | |
17 | * without specific prior written permission. | |
18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND | |
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | |
30 | */ | |
31 | ||
32 | #ifndef _PLOG_H | |
33 | #define _PLOG_H | |
34 | ||
35 | #include "config.h" | |
36 | ||
37 | #ifdef HAVE_STDARG_H | |
38 | #include <stdarg.h> | |
39 | #else | |
40 | #include <varargs.h> | |
41 | #endif | |
65c25746 A |
42 | #include <asl.h> |
43 | #include <sys/queue.h> | |
44 | #include <SystemConfiguration/SCPreferences.h> | |
52b7d2ce | 45 | |
52b7d2ce A |
46 | |
47 | extern char *pname; | |
48 | extern u_int32_t loglevel; | |
49 | extern int f_foreground; | |
50 | extern int print_location; | |
65c25746 A |
51 | extern char *logfile; |
52 | extern char logFileStr[]; | |
53 | extern char *gSessId; | |
54 | extern char *gSessType; | |
55 | extern char *gSessVer; | |
56 | extern aslclient logRef; | |
52b7d2ce | 57 | |
85f41bec | 58 | struct sockaddr_storage; |
65c25746 A |
59 | |
60 | typedef enum clog_err_op { | |
61 | CLOG_ERR_OFF = 0, | |
62 | CLOG_ERR_FILL, | |
63 | CLOG_ERR_DUMP, | |
64 | } clog_err_op_t; | |
65 | ||
66 | typedef struct clog_err { | |
67 | int clog_err_level; /* will be used for filtering */ | |
68 | int clog_err_code; /* internal code */ | |
69 | char *client_id; | |
70 | char *client_type; | |
71 | char *description; | |
72 | int description_len; | |
73 | const char *function; | |
74 | const char *line; | |
75 | ||
76 | // add a CFErrorRef for global error code (i.e. number-space) | |
77 | ||
78 | TAILQ_HEAD(_chain_head, clog_err) chain_head; | |
79 | TAILQ_ENTRY(clog_err) chain; | |
80 | } clog_err_t; | |
81 | ||
82 | extern const char *plog_facility; | |
83 | extern const char *plog_session_id; | |
84 | extern const char *plog_session_type; | |
85 | extern const char *plog_session_ver; | |
86 | extern void clog_func (clog_err_t *, clog_err_op_t, int, const char *, const char *, const char *, ...); | |
87 | extern void plogdump_asl (aslmsg, int, const char *, ...); | |
88 | extern void plogdump_func (int, void *, size_t, const char *, ...); | |
89 | extern void plogcf(int priority, CFStringRef fmt, ...); | |
90 | ||
91 | #define clog(cerr, cerr_op, pri, fmt, args...) do { \ | |
92 | if (pri <= loglevel) { \ | |
93 | clog_func(cerr, cerr_op, pri, __FUNCTION__, __LINE__, fmt, ##args); \ | |
94 | } \ | |
95 | } while(0) | |
96 | ||
97 | #define plog(pri, fmt, args...) do { \ | |
98 | if (pri <= loglevel) { \ | |
99 | aslmsg m; \ | |
100 | if ((m = asl_new(ASL_TYPE_MSG))) { \ | |
101 | asl_set(m, ASL_KEY_FACILITY, plog_facility); \ | |
102 | if (gSessId) \ | |
103 | asl_set(m, plog_session_id, gSessId); \ | |
104 | if (gSessType) \ | |
105 | asl_set(m, plog_session_type, gSessType); \ | |
106 | if (gSessVer) \ | |
107 | asl_set(m, plog_session_ver, gSessVer); \ | |
108 | asl_log(logRef, m, pri, fmt, ##args); \ | |
109 | asl_free(m); \ | |
110 | } \ | |
111 | } \ | |
112 | } while(0) | |
113 | ||
114 | #define plogdump(pri, buf, len, fmt, args...) do { \ | |
115 | if (pri <= loglevel) { \ | |
116 | plogdump_func(pri, buf, len, fmt, ##args); \ | |
117 | } \ | |
118 | } while(0) | |
119 | ||
120 | void ploginit(void); | |
121 | ||
122 | void plogreadprefs (void); | |
123 | ||
124 | void plogsetfile (char *); | |
125 | ||
126 | void plogresetfile (char *); | |
127 | ||
128 | int ploggetlevel(void); | |
129 | ||
130 | void plogsetlevel (int); | |
131 | ||
132 | void plogresetlevel (void); | |
133 | ||
134 | void plogsetlevelstr (char *); | |
135 | void plogsetlevelquotedstr (char *); | |
136 | ||
137 | // Called at the beginning of any dispatch event to initialize the logger with protocol client info | |
138 | void plogsetsessioninfo (const char *session_id, | |
139 | const char *session_type, | |
140 | const char *session_ver); | |
e8d9021d | 141 | |
52b7d2ce | 142 | #endif /* _PLOG_H */ |