corosync  3.0.3
logsys.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2004 MontaVista Software, Inc.
3  * Copyright (c) 2006-2012 Red Hat, Inc.
4  *
5  * Author: Steven Dake (sdake@redhat.com)
6  * Author: Lon Hohberger (lhh@redhat.com)
7  * Author: Fabio M. Di Nitto (fdinitto@redhat.com)
8  *
9  * All rights reserved.
10  *
11  * This software licensed under BSD license, the text of which follows:
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions are met:
15  *
16  * - Redistributions of source code must retain the above copyright notice,
17  * this list of conditions and the following disclaimer.
18  * - Redistributions in binary form must reproduce the above copyright notice,
19  * this list of conditions and the following disclaimer in the documentation
20  * and/or other materials provided with the distribution.
21  * - Neither the name of the MontaVista Software, Inc. nor the names of its
22  * contributors may be used to endorse or promote products derived from this
23  * software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35  * THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 #ifndef LOGSYS_H_DEFINED
38 #define LOGSYS_H_DEFINED
39 
40 #include <stdarg.h>
41 #include <stdlib.h>
42 #include <syslog.h>
43 #include <pthread.h>
44 #include <limits.h>
45 
46 #include <corosync/corotypes.h>
47 
48 #include <qb/qbconfig.h>
49 #include <qb/qblog.h>
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 /*
56  * All of the LOGSYS_MODE's can be ORed together for combined behavior
57  *
58  * FORK and THREADED are ignored for SUBSYSTEMS
59  */
60 #define LOGSYS_MODE_OUTPUT_FILE (1<<0)
61 #define LOGSYS_MODE_OUTPUT_STDERR (1<<1)
62 #define LOGSYS_MODE_OUTPUT_SYSLOG (1<<2)
63 #define LOGSYS_MODE_FORK (1<<3)
64 #define LOGSYS_MODE_THREADED (1<<4)
65 
66 /*
67  * Log priorities, compliant with syslog and SA Forum Log spec.
68  */
69 #define LOGSYS_LEVEL_EMERG LOG_EMERG
70 #define LOGSYS_LEVEL_ALERT LOG_ALERT
71 #define LOGSYS_LEVEL_CRIT LOG_CRIT
72 #define LOGSYS_LEVEL_ERROR LOG_ERR
73 #define LOGSYS_LEVEL_WARNING LOG_WARNING
74 #define LOGSYS_LEVEL_NOTICE LOG_NOTICE
75 #define LOGSYS_LEVEL_INFO LOG_INFO
76 #define LOGSYS_LEVEL_DEBUG LOG_DEBUG
77 #define LOGSYS_LEVEL_TRACE LOG_TRACE
78 
79 /*
80  * logsys_logger bits
81  *
82  * SUBSYS_COUNT defines the maximum number of subsystems
83  * SUBSYS_NAMELEN defines the maximum len of a subsystem name
84  */
85 #define LOGSYS_MAX_SUBSYS_COUNT 32
86 #define LOGSYS_MAX_SUBSYS_NAMELEN 64
87 #define LOGSYS_MAX_PERROR_MSG_LEN 128
88 
89 /*
90  * Debug levels
91  */
92 #define LOGSYS_DEBUG_OFF 0
93 #define LOGSYS_DEBUG_ON 1
94 #define LOGSYS_DEBUG_TRACE 2
95 
96 #ifndef LOGSYS_UTILS_ONLY
97 
103 extern int logsys_format_set (
104  const char *format);
105 
110 extern char *logsys_format_get (void);
111 
125  const char *subsys,
126  unsigned int facility);
127 
135  const char *subsys,
136  unsigned int priority);
137 
144 extern int logsys_config_mode_set (
145  const char *subsys,
146  unsigned int mode);
147 
153 extern unsigned int logsys_config_mode_get (
154  const char *subsys);
155 
159 void logsys_config_apply(void);
160 
171 extern int logsys_config_file_set (
172  const char *subsys,
173  const char **error_string,
174  const char *file);
175 
183  const char *subsys,
184  unsigned int priority);
185 
195 extern int logsys_config_debug_set (
196  const char *subsys,
197  unsigned int value);
198 
199 /*
200  * External API - helpers
201  *
202  * convert facility/priority to/from name/values
203  */
209 extern int logsys_priority_id_get (
210  const char *name);
211 
217 extern const char *logsys_priority_name_get (
218  unsigned int priority);
219 
228 extern int _logsys_system_setup(
229  const char *mainsystem,
230  unsigned int mode,
231  int syslog_facility,
232  int syslog_priority);
233 
237 extern void logsys_system_fini (void);
238 
244 extern int _logsys_config_subsys_get (
245  const char *subsys);
246 
253 extern int _logsys_subsys_create (const char *subsys, const char *filename);
254 
259 extern int logsys_thread_start (void);
260 
261 extern void logsys_blackbox_set(int enable);
262 
263 extern void logsys_blackbox_prefork(void);
264 
265 extern void logsys_blackbox_postfork(void);
266 
268 
272 static int logsys_subsys_id __attribute__((unused)) = LOGSYS_MAX_SUBSYS_COUNT;
273 
281 #define LOGSYS_DECLARE_SYSTEM(name,mode,syslog_facility,syslog_priority)\
282 QB_LOG_INIT_DATA(logsys_qb_init); \
283 __attribute__ ((constructor)) \
284 static void logsys_system_init (void) \
285 { \
286  if (_logsys_system_setup (name,mode,syslog_facility,syslog_priority) < 0) { \
287  fprintf (stderr, \
288  "Unable to setup logging system: %s.\n", name); \
289  exit (-1); \
290  } \
291 }
292 
297 #define LOGSYS_DECLARE_SUBSYS(subsys) \
298 __attribute__ ((constructor)) \
299 static void logsys_subsys_init (void) \
300 { \
301  logsys_subsys_id = \
302  _logsys_subsys_create ((subsys), __FILE__); \
303  if (logsys_subsys_id == -1) { \
304  fprintf (stderr, \
305  "Unable to create logging subsystem: %s.\n", subsys); \
306  exit (-1); \
307  } \
308 }
309 
317 #define LOGSYS_PERROR(err_num, level, fmt, args...) do { \
318  char _error_str[LOGSYS_MAX_PERROR_MSG_LEN]; \
319  const char *_error_ptr = qb_strerror_r(err_num, _error_str, sizeof(_error_str)); \
320  qb_log(level, fmt ": %s (%d)", ##args, _error_ptr, err_num); \
321  } while(0)
322 
323 #define log_printf(level, format, args...) qb_log(level, format, ##args)
324 #define ENTER qb_enter
325 #define LEAVE qb_leave
326 #define TRACE1(format, args...) qb_log(LOG_TRACE, "TRACE1:" #format, ##args)
327 #define TRACE2(format, args...) qb_log(LOG_TRACE, "TRACE2:" #format, ##args)
328 #define TRACE3(format, args...) qb_log(LOG_TRACE, "TRACE3:" #format, ##args)
329 #define TRACE4(format, args...) qb_log(LOG_TRACE, "TRACE4:" #format, ##args)
330 #define TRACE5(format, args...) qb_log(LOG_TRACE, "TRACE5:" #format, ##args)
331 #define TRACE6(format, args...) qb_log(LOG_TRACE, "TRACE6:" #format, ##args)
332 #define TRACE7(format, args...) qb_log(LOG_TRACE, "TRACE7:" #format, ##args)
333 #define TRACE8(format, args...) qb_log(LOG_TRACE, "TRACE8:" #format, ##args)
334 
335 #endif /* LOGSYS_UTILS_ONLY */
336 
337 #ifdef __cplusplus
338 }
339 #endif
340 
341 #endif /* LOGSYS_H_DEFINED */
value
uint32_t value
Definition: exec/votequorum.c:2
logsys_priority_id_get
int logsys_priority_id_get(const char *name)
logsys_priority_id_get
Definition: logsys.c:830
logsys_config_apply
void logsys_config_apply(void)
logsys_config_apply
Definition: logsys.c:790
logsys_config_syslog_priority_set
int logsys_config_syslog_priority_set(const char *subsys, unsigned int priority)
logsys_config_syslog_priority_set
Definition: logsys.c:662
_logsys_system_setup
int _logsys_system_setup(const char *mainsystem, unsigned int mode, int syslog_facility, int syslog_priority)
_logsys_system_setup
Definition: logsys.c:304
logsys_config_syslog_facility_set
int logsys_config_syslog_facility_set(const char *subsys, unsigned int facility)
per system/subsystem settings.
Definition: logsys.c:655
logsys_blackbox_set
void logsys_blackbox_set(int enable)
Definition: logsys.c:864
logsys_config_logfile_priority_set
int logsys_config_logfile_priority_set(const char *subsys, unsigned int priority)
logsys_config_logfile_priority_set
Definition: logsys.c:689
_logsys_config_subsys_get
int _logsys_config_subsys_get(const char *subsys)
_logsys_config_subsys_get
Definition: logsys.c:467
cs_error_t
cs_error_t
The cs_error_t enum.
Definition: corotypes.h:97
logsys_logger::subsys
char subsys[LOGSYS_MAX_SUBSYS_NAMELEN]
Definition: logsys.c:87
__attribute__
typedef __attribute__
logsys_reopen_log_files
cs_error_t logsys_reopen_log_files(void)
Definition: logsys.c:890
logsys_config_debug_set
int logsys_config_debug_set(const char *subsys, unsigned int value)
enabling debug, disable message priority filtering.
Definition: logsys.c:804
logsys_config_mode_get
unsigned int logsys_config_mode_get(const char *subsys)
logsys_config_mode_get
Definition: logsys.c:525
logsys_format_set
int logsys_format_set(const char *format)
configuration bits that can only be done for the whole system
Definition: logsys.c:591
_logsys_subsys_create
int _logsys_subsys_create(const char *subsys, const char *filename)
_logsys_subsys_create
Definition: logsys.c:433
logsys_logger::syslog_priority
int syslog_priority
Definition: logsys.c:91
logsys_logger::mode
unsigned int mode
Definition: logsys.c:89
logsys_priority_name_get
const char * logsys_priority_name_get(unsigned int priority)
logsys_priority_name_get
logsys_format_get
char * logsys_format_get(void)
logsys_format_get
Definition: logsys.c:650
logsys_system_fini
void logsys_system_fini(void)
logsys_system_fini
Definition: logsys.c:286
logsys_config_file_set
int logsys_config_file_set(const char *subsys, const char **error_string, const char *file)
to close a logfile, just invoke this function with a NULL file or if you want to change logfile,...
Definition: logsys.c:537
logsys_blackbox_prefork
void logsys_blackbox_prefork(void)
Definition: logsys.c:878
logsys_blackbox_postfork
void logsys_blackbox_postfork(void)
Definition: logsys.c:884
corotypes.h
LOGSYS_MAX_SUBSYS_COUNT
#define LOGSYS_MAX_SUBSYS_COUNT
Definition: logsys.h:85
logsys_thread_start
int logsys_thread_start(void)
logsys_thread_start
Definition: logsys.c:842
logsys_config_mode_set
int logsys_config_mode_set(const char *subsys, unsigned int mode)
logsys_config_mode_set
Definition: logsys.c:503