corosync 3.1.7
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
52extern "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
103extern int logsys_format_set (
104 const char *format);
105
110extern char *logsys_format_get (void);
111
125 const char *subsys,
126 unsigned int facility);
127
135 const char *subsys,
136 unsigned int priority);
137
144extern int logsys_config_mode_set (
145 const char *subsys,
146 unsigned int mode);
147
153extern unsigned int logsys_config_mode_get (
154 const char *subsys);
155
159void logsys_config_apply(void);
160
171extern 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
195extern int logsys_config_debug_set (
196 const char *subsys,
197 unsigned int value);
198
205extern int logsys_config_debug_get (
206 const char *subsys);
207
208/*
209 * External API - helpers
210 *
211 * convert facility/priority to/from name/values
212 */
218extern int logsys_priority_id_get (
219 const char *name);
220
226extern const char *logsys_priority_name_get (
227 unsigned int priority);
228
237extern int _logsys_system_setup(
238 const char *mainsystem,
239 unsigned int mode,
240 int syslog_facility,
241 int syslog_priority);
242
246extern void logsys_system_fini (void);
247
253extern int _logsys_config_subsys_get (
254 const char *subsys);
255
262extern int _logsys_subsys_create (const char *subsys, const char *filename);
263
268extern int logsys_thread_start (void);
269
270extern void logsys_blackbox_set(int enable);
271
272extern void logsys_blackbox_prefork(void);
273
274extern void logsys_blackbox_postfork(void);
275
277
281static int logsys_subsys_id __attribute__((unused)) = LOGSYS_MAX_SUBSYS_COUNT;
282
290#define LOGSYS_DECLARE_SYSTEM(name,mode,syslog_facility,syslog_priority)\
291QB_LOG_INIT_DATA(logsys_qb_init); \
292__attribute__ ((constructor)) \
293static void logsys_system_init (void) \
294{ \
295 if (_logsys_system_setup (name,mode,syslog_facility,syslog_priority) < 0) { \
296 fprintf (stderr, \
297 "Unable to setup logging system: %s.\n", name); \
298 exit (-1); \
299 } \
300}
301
306#define LOGSYS_DECLARE_SUBSYS(subsys) \
307__attribute__ ((constructor)) \
308static void logsys_subsys_init (void) \
309{ \
310 logsys_subsys_id = \
311 _logsys_subsys_create ((subsys), __FILE__); \
312 if (logsys_subsys_id == -1) { \
313 fprintf (stderr, \
314 "Unable to create logging subsystem: %s.\n", subsys); \
315 exit (-1); \
316 } \
317}
318
326#define LOGSYS_PERROR(err_num, level, fmt, args...) do { \
327 char _error_str[LOGSYS_MAX_PERROR_MSG_LEN]; \
328 const char *_error_ptr = qb_strerror_r(err_num, _error_str, sizeof(_error_str)); \
329 qb_log(level, fmt ": %s (%d)", ##args, _error_ptr, err_num); \
330 } while(0)
331
332#define log_printf(level, format, args...) qb_log(level, format, ##args)
333#define ENTER qb_enter
334#define LEAVE qb_leave
335#define TRACE1(format, args...) qb_log(LOG_TRACE, "TRACE1:" #format, ##args)
336#define TRACE2(format, args...) qb_log(LOG_TRACE, "TRACE2:" #format, ##args)
337#define TRACE3(format, args...) qb_log(LOG_TRACE, "TRACE3:" #format, ##args)
338#define TRACE4(format, args...) qb_log(LOG_TRACE, "TRACE4:" #format, ##args)
339#define TRACE5(format, args...) qb_log(LOG_TRACE, "TRACE5:" #format, ##args)
340#define TRACE6(format, args...) qb_log(LOG_TRACE, "TRACE6:" #format, ##args)
341#define TRACE7(format, args...) qb_log(LOG_TRACE, "TRACE7:" #format, ##args)
342#define TRACE8(format, args...) qb_log(LOG_TRACE, "TRACE8:" #format, ##args)
343
344#endif /* LOGSYS_UTILS_ONLY */
345
346#ifdef __cplusplus
347}
348#endif
349
350#endif /* LOGSYS_H_DEFINED */
cs_error_t
The cs_error_t enum.
Definition: corotypes.h:98
uint32_t value
unsigned int logsys_config_mode_get(const char *subsys)
logsys_config_mode_get
Definition: logsys.c:527
const char * logsys_priority_name_get(unsigned int priority)
logsys_priority_name_get
int logsys_config_mode_set(const char *subsys, unsigned int mode)
logsys_config_mode_set
Definition: logsys.c:505
void logsys_blackbox_set(int enable)
Definition: logsys.c:883
void logsys_blackbox_prefork(void)
Definition: logsys.c:897
void logsys_system_fini(void)
logsys_system_fini
Definition: logsys.c:286
char * logsys_format_get(void)
logsys_format_get
Definition: logsys.c:652
int logsys_config_debug_get(const char *subsys)
Return the debug flag for this subsys.
Definition: logsys.c:806
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:539
int logsys_config_syslog_priority_set(const char *subsys, unsigned int priority)
logsys_config_syslog_priority_set
Definition: logsys.c:664
void logsys_config_apply(void)
logsys_config_apply
Definition: logsys.c:792
int logsys_priority_id_get(const char *name)
logsys_priority_id_get
Definition: logsys.c:849
int logsys_config_logfile_priority_set(const char *subsys, unsigned int priority)
logsys_config_logfile_priority_set
Definition: logsys.c:691
int logsys_thread_start(void)
logsys_thread_start
Definition: logsys.c:861
int logsys_config_debug_set(const char *subsys, unsigned int value)
enabling debug, disable message priority filtering.
Definition: logsys.c:823
int _logsys_config_subsys_get(const char *subsys)
_logsys_config_subsys_get
Definition: logsys.c:469
int _logsys_subsys_create(const char *subsys, const char *filename)
_logsys_subsys_create
Definition: logsys.c:435
int logsys_config_syslog_facility_set(const char *subsys, unsigned int facility)
per system/subsystem settings.
Definition: logsys.c:657
cs_error_t logsys_reopen_log_files(void)
Definition: logsys.c:909
void logsys_blackbox_postfork(void)
Definition: logsys.c:903
int _logsys_system_setup(const char *mainsystem, unsigned int mode, int syslog_facility, int syslog_priority)
_logsys_system_setup
Definition: logsys.c:304
#define LOGSYS_MAX_SUBSYS_COUNT
Definition: logsys.h:85
int logsys_format_set(const char *format)
configuration bits that can only be done for the whole system
Definition: logsys.c:593
typedef __attribute__