ze-filter  (ze-filter-0.8.0-develop-180218)
zeSyslog.h
Go to the documentation of this file.
1 
2 /*
3  *
4  * ze-filter - Mail Server Filter for sendmail
5  *
6  * Copyright (c) 2001-2018 - Jose-Marcio Martins da Cruz
7  *
8  * Auteur : Jose Marcio Martins da Cruz
9  * jose.marcio.mc@gmail.org
10  *
11  * Historique :
12  * Creation : janvier 2002
13  *
14  * This program is free software, but with restricted license :
15  *
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20  *
21  * More details about ze-filter license can be found at ze-filter
22  * web site : http://foss.jose-marcio.org
23  */
24 
25 #ifndef __ZE_SYSLOG_H
26 
27 #define ZE_STDOUT 1
28 #define ZE_SYSLOG 0
29 #define ZE_OUT_ALL 2
30 
31 
32 /* ****************************************************************************
33  * *
34  * *
35  **************************************************************************** */
36 #define zeLog_Debug(...) zeSyslog(LOG_DEBUG, __VA_ARGS__)
37 
38 extern int ze_output;
39 extern int ze_logLevel;
40 extern int ze_logFacility;
41 extern bool ze_logSeverity;
42 
43 void zeLog_SetOutput(bool, bool);
44 
45 void zeLog_SetLevel(int);
46 void zeLog_SetFacility(char *);
47 
48 void zeSyslog(int, char *, ...);
49 void zeOpenlog(const char *ident, int option, int facility);
50 void zeCloselog();
51 
52 int zeLog_FacilityValue(char *);
53 char *zeLog_FacilityName(int);
54 
55 int zeLog_PriorityValue(char *);
56 char *zeLog_PriorityName(int);
57 
58 /* ****************************************************************************
59  * *
60  * *
61  **************************************************************************** */
62 
63 void zeLog_MessageInfo(int, char *, ...);
64 void zeLog_MessageWarning(int, char *, ...);
65 void zeLog_MessageError(int, char *, ...);
66 
67 void zeLog_MsgDebug(char *, int, char *, ...);
68 void zeLog_MsgInfo(char *, int, char *, ...);
69 void zeLog_MsgNotice(char *, int, char *, ...);
70 void zeLog_MsgWarning(char *, int, char *, ...);
71 void zeLog_MsgError(char *, int, char *, ...);
72 
73 void zeLog_SysWarning(char *, int, char *, ...);
74 void zeLog_SysError(char *, int, char *, ...);
75 
76 
77 /* ****************************************************************************
78  * *
79  * *
80  **************************************************************************** */
81 
82 #define ZE_Message(level, sysloglevel, ...) \
83 do { \
84  if (ze_logLevel >= level) {\
85  zeSyslog(sysloglevel, __VA_ARGS__); \
86  } \
87 } while (0)
88 
89 #define ZE_MessageDebug(level, ...) ZE_Message(level, LOG_DEBUG, __VA_ARGS__)
90 #define ZE_MessageInfo(level, ...) ZE_Message(level, LOG_INFO, __VA_ARGS__)
91 #define ZE_MessageNotice(level, ...) ZE_Message(level, LOG_NOTICE, __VA_ARGS__)
92 #define ZE_MessageWarning(level, ...) ZE_Message(level, LOG_WARNING, __VA_ARGS__)
93 #define ZE_MessageError(level, ...) ZE_Message(level, LOG_ERR, __VA_ARGS__)
94 
95 
96 /* ****************************************************************************
97  * *
98  * *
99  **************************************************************************** */
100 #define ZE_LogMsg(level, sysloglevel, ...) \
101 do { \
102  if (ze_logLevel > level) { \
103  char h_log_str[256]; \
104  (void ) snprintf(h_log_str, sizeof(h_log_str), __VA_ARGS__); \
105  zeSyslog(sysloglevel, "%s : %s", ZE_FUNCTION, h_log_str); \
106  } \
107 } while (0)
108 
109 #define ZE_LogMsgDebug(level, ...) ZE_LogMsg(level, LOG_DEBUG, __VA_ARGS__)
110 #define ZE_LogMsgInfo(level, ...) ZE_LogMsg(level, LOG_INFO, __VA_ARGS__)
111 #define ZE_LogMsgNotice(level, ...) ZE_LogMsg(level, LOG_NOTICE, __VA_ARGS__)
112 #define ZE_LogMsgWarning(level, ...) ZE_LogMsg(level, LOG_WARNING, __VA_ARGS__)
113 #define ZE_LogMsgError(level, ...) ZE_LogMsg(level, LOG_ERR, __VA_ARGS__)
114 
115 /* ****************************************************************************
116  * *
117  * *
118  **************************************************************************** */
119 #define ZE_LogSys(sysloglevel, ...) \
120 do { \
121  char h_log_str[256]; \
122  int serrno = errno; \
123  char *t = (serrno != 0 ? strerror(serrno) : ""); \
124  (void ) snprintf(h_log_str, sizeof(h_log_str), __VA_ARGS__); \
125  zeSyslog(sysloglevel, "%s : %s : %s", ZE_FUNCTION, h_log_str, t); \
126 } while (0)
127 
128 #define ZE_LogSysWarning(...) ZE_LogSys(LOG_WARNING, __VA_ARGS__)
129 #define ZE_LogSysError(...) ZE_LogSys(LOG_ERR, __VA_ARGS__)
130 #define ZE_LogSysCrit(...) ZE_LogSys(LOG_CRIT, __VA_ARGS__)
131 
132 #if 0
133  if (sysloglevel == LOG_ERR || sysloglevel == LOG_CRIT) { \
134  if (serrno == ENOMEM) \
135  exit(EX_OSERR); \
136  } \
137 
138 #endif
139 
140 /* ****************************************************************************
141  * *
142  * *
143  **************************************************************************** */
144 
145 #if 0
146 #define ZE_MESSAGE_DEBUG(level, ...) \
147 do { \
148  if (ze_logLevel >= level) {\
149  zeSyslog(LOG_DEBUG, __VA_ARGS__); \
150  } \
151 } while (0)
152 
153 #define ZE_MessageInfo(level, ...) \
154 do { \
155  if (ze_logLevel >= level) {\
156  zeSyslog(LOG_INFO, __VA_ARGS__); \
157  } \
158 } while (0)
159 
160 #define ZE_MessageNotice(level, ...) \
161 do { \
162  if (ze_logLevel >= level) {\
163  zeSyslog(LOG_NOTICE, __VA_ARGS__); \
164  } \
165 } while (0)
166 
167 #define ZE_MessageWarning(level, ...) \
168 do { \
169  if (ze_logLevel >= level) {\
170  zeSyslog(LOG_WARNING, __VA_ARGS__); \
171  } \
172 } while (0)
173 
174 #define ZE_MessageError(level, ...) \
175 do { \
176  if (ze_logLevel >= level) {\
177  zeSyslog(LOG_ERR, __VA_ARGS__); \
178  } \
179 } while (0)
180 #endif
181 
182 
183 #if 0
184 #define ZE_LogMsgDebug(level, ...) \
185 do { \
186  if (ze_logLevel > level) { \
187  char h_log_str[256]; \
188  (void ) snprintf(h_log_str, sizeof(h_log_str), __VA_ARGS__); \
189  zeSyslog(LOG_DEBUG, "%s : %s", ZE_FUNCTION, h_log_str); \
190  } \
191 } while (0)
192 
193 #define ZE_LogMsgInfo(level, ...) \
194 do { \
195  if (ze_logLevel >= level) {\
196  char h_log_str[256]; \
197  (void ) snprintf(h_log_str, sizeof(h_log_str), __VA_ARGS__); \
198  zeSyslog(LOG_INFO, "%s : %s", ZE_FUNCTION, h_log_str); \
199  } \
200 } while (0)
201 
202 #define ZE_LogMsgNOTICE(...) \
203 do { \
204  char h_log_str[256]; \
205  (void ) snprintf(h_log_str, sizeof(h_log_str), __VA_ARGS__); \
206  zeSyslog(LOG_NOTICE, "%s : %s", ZE_FUNCTION, h_log_str); \
207 } while (0)
208 
209 #define ZE_LogMsgWarning(...) \
210 do { \
211  char h_log_str[256]; \
212  (void ) snprintf(h_log_str, sizeof(h_log_str), __VA_ARGS__); \
213  zeSyslog(LOG_WARNING, "%s : %s", ZE_FUNCTION, h_log_str); \
214 } while (0)
215 
216 #define ZE_LogMsgError(...) \
217 do { \
218  char h_log_str[256]; \
219  (void ) snprintf(h_log_str, sizeof(h_log_str), __VA_ARGS__); \
220  zeSyslog(LOG_ERR, "%s : %s", ZE_FUNCTION, h_log_str); \
221 } while (0)
222 
223 #define ZE_LOG_MSG_CRIT(...) \
224 do { \
225  char h_log_str[256]; \
226  (void ) snprintf(h_log_str, sizeof(h_log_str), __VA_ARGS__); \
227  zeSyslog(LOG_CRIT, "%s : %s", ZE_FUNCTION, h_log_str); \
228 } while (0)
229 #endif
230 
231 
232 
233 #if 0
234 #define ZE_LogSysWarning(...) \
235 do { \
236  char h_log_str[256]; \
237  char *t = (errno != 0 ? strerror(errno) : ""); \
238  (void ) snprintf(h_log_str, sizeof(h_log_str), __VA_ARGS__); \
239  zeSyslog(LOG_WARNING, "%s : %s : %s", ZE_FUNCTION, h_log_str, t); \
240 } while (0)
241 
242 
243 #define ZE_LogSysError(...) \
244  do { \
245  char h_log_str[256]; \
246  int serrno = errno; \
247  char *t = (serrno != 0 ? strerror(serrno) : ""); \
248  (void ) snprintf(h_log_str, sizeof(h_log_str), __VA_ARGS__); \
249  zeSyslog(LOG_ERR, "%s : %s : %s", ZE_FUNCTION, h_log_str, t); \
250  switch (serrno) \
251  { \
252  case ENOMEM : \
253  exit(EX_OSERR); \
254  break; \
255  } \
256  } while (0)
257 
258 #define ZE_LogSysCrit(...) \
259  do { \
260  char h_log_str[256]; \
261  int serrno = errno; \
262  char *t = (serrno != 0 ? strerror(serrno) : ""); \
263  (void ) snprintf(h_log_str, sizeof(h_log_str), __VA_ARGS__); \
264  zeSyslog(LOG_CRIT, "%s : %s : %s", ZE_FUNCTION, h_log_str, t); \
265  switch (serrno) \
266  { \
267  case ENOMEM : \
268  exit(EX_OSERR); \
269  break; \
270  } \
271  } while (0)
272 
273 #define ZE_LOG_SYS_FATAL(...) \
274  do { \
275  char h_log_str[256]; \
276  char *t = (errno != 0 ? strerror(errno) : ""); \
277  (void ) snprintf(h_log_str, sizeof(h_log_str), __VA_ARGS__); \
278  zeSyslog(LOG_ERR, "%s : %s : %s", ZE_FUNCTION, h_log_str, t); \
279  exit(EX_SOFTWARE); \
280  } while (0)
281 #endif
282 
283 #define __ZE_SYSLOG_H
284 #endif
void zeSyslog(int, char *,...)
Definition: zeSyslog.c:54
void zeLog_SysError(char *, int, char *,...)
Definition: zeSyslog.c:327
void zeLog_SetLevel(int)
void zeOpenlog(const char *ident, int option, int facility)
void zeLog_SysWarning(char *, int, char *,...)
Definition: zeSyslog.c:305
void zeLog_MessageWarning(int, char *,...)
Definition: zeSyslog.c:167
int zeLog_FacilityValue(char *)
Definition: zeSyslog.c:442
int ze_logLevel
Definition: zeSyslog.c:34
void zeCloselog()
Definition: zeSyslog.c:138
int ze_logFacility
Definition: zeSyslog.c:35
void zeLog_SetOutput(bool, bool)
Definition: zeSyslog.c:490
char * zeLog_FacilityName(int)
Definition: zeSyslog.c:431
void zeLog_MessageInfo(int, char *,...)
Definition: zeSyslog.c:148
void zeLog_SetFacility(char *)
Definition: zeSyslog.c:475
void zeLog_MsgError(char *, int, char *,...)
Definition: zeSyslog.c:285
int ze_output
void zeLog_MsgNotice(char *, int, char *,...)
Definition: zeSyslog.c:245
void zeLog_MsgInfo(char *, int, char *,...)
Definition: zeSyslog.c:225
void zeLog_MsgDebug(char *, int, char *,...)
Definition: zeSyslog.c:205
int zeLog_PriorityValue(char *)
Definition: zeSyslog.c:463
void zeLog_MessageError(int, char *,...)
Definition: zeSyslog.c:186
bool ze_logSeverity
Definition: zeSyslog.c:36
void zeLog_MsgWarning(char *, int, char *,...)
Definition: zeSyslog.c:265
char * zeLog_PriorityName(int)
Definition: zeSyslog.c:452