1LOGSYS_OVERVIEW(8)Corosync Cluster Engine Programmer's ManualLOGSYS_OVERVIEW(8)
2
3
4
6 logsys_overview - Logsys Library Overview
7
9 The logsys library provides a generically usable logging and tracing
10 system for use by applications. It supports many features including:
11
12 Configurable subsystem logging or single system logging
13
14 Threaded non-blocking logging of log output data for better non-block‐
15 ing performance
16
17 Support for 8 tracing levels and tracing the entering and leaving of
18 functions
19
20 Declaration of logging system or subsystem without calling any func‐
21 tions
22
23 Dynamic reconfiguration of the logging system parameters
24
25 Logging to syslog, file, stderr.
26
27
29 The logsys library is initially configured by including logsys.h and
30 declaring a logger. Once the logger is declared, optional subsystem
31 loggers can be declared in every file.
32
33 The definition LOGSYS_DECLARE_SYSTEM is placed after the include sec‐
34 tion of one C file in the application. This declaration creates a con‐
35 structor function which will be called automatically before main() is
36 executed. This technique avoids the need for calling any setup func‐
37 tions in short applications that don't require it and enables full log‐
38 ging capabilities before any application code is executed.
39
40 #define LOGSYS_DECLARE_SYSTEM (name, mode, debug, file, file_priority,
41 syslog_facility, syslog_priority, format, fltsize)
42
43 The name parameter is the name of the application or system.
44
45 The mode parameter is the logging mode of the system. The following
46 modes can be configured by logically ORing these flags:
47
48 LOGSYS_MODE_OUTPUT_FILE: Output all log data to the file parameter of
49 this declaration
50
51 LOGSYS_MODE_OUTPUT_STDERR: Output all log data to the stderr descriptor
52
53 LOGSYS_MODE_OUTPUT_SYSLOG: Output all log data to syslog using a non-
54 blocking thread
55
56 LOGSYS_MODE_FORK: This flags tells logsys to queue all data untill the
57 application has forked. The application is then responsible to call
58 logsys_fork_completed to flush the queue and start logging.
59
60 LOGSYS_MODE_THREADED: Starts a separate thread to handle non-blocking
61 logging operations. If this flag is not specified, the logging opera‐
62 tions are blocking.
63
64 The debug parameter, if enabled, turns off all messages priority fil‐
65 tering, recording everything everywhere.
66
67 The file parameter specifies the filename that should be used to log
68 messages. This parameter may be NULL and no log file will be created.
69
70 The file_priority parameter specifies the message priority that should
71 be logged to file.
72
73 The syslog_facility parameter is the syslog facility that should be
74 used when logging messages.
75
76 The syslog_priority, similar to file_priority, specifies the message
77 priority that should be logged to syslog.
78
79 The format parameter allows to set custom output format. Set to NULL
80 to use built-in default.
81
82 The fltsize parameter specifies the flight recorder buffer size in
83 bytes. The requested value is increased by the size of 2 unsigned ints
84 and rounded to the next PAGE_SIZE.
85
86 An example declaration would be:
87
88 #include <corosync/logsys.h>
89
90
91 LOGSYS_DECLARE_SYSTEM ("test", /* name */
92 LOGSYS_MODE_OUTPUT_STDERR | LOGSYS_MODE_THREADED, /* mode */
93 0, /* debug */
94 NULL, /* logfile
95 path */
96 LOGSYS_LEVEL_INFO, /* log‐
97 file_priority */
98 LOG_DAEMON, /* syslog
99 facility */
100 LOGSYS_LEVEL_INFO, /* syslog
101 level */
102 NULL, /* use
103 default format */
104 1000000); /* flight
105 recorder size */
106
107
108
110 The logsys library supports the logging of information to one main sys‐
111 tem or subsystem. This is specified in each individual object C file
112 in the system and it is entirely optional.
113
114 An example:
115
116 LOGSYS_DECLARE_SUBSYS ("subsystest");
117
118 It is possible to use the same subsystem name in separate object files.
119 In this case, the individual logging parameters for those subsystem
120 identifier will be used.
121
122 A newly created subsystem inherits the system configuration at the time
123 of creation.
124
125 It is possible to override every configuration option on a subsystem
126 base throught the configuration API.
127
128
130 The definition log_printf is used to log information to the log. It
131 works in a similiar fashion to printf, except it has a first parameter
132 of level which may be the following: LOGSYS_LEVEL_EMERG
133 LOGSYS_LEVEL_ALERT LOGSYS_LEVEL_CRIT LOGSYS_LEVEL_ERR
134 LOGSYS_LEVEL_WARNING LOGSYS_LEVEL_NOTICE LOGSYS_LEVEL_INFO
135 LOGSYS_LEVEL_DEBUG
136
137 An example of using log_printf would be
138
139 log_printf (LOGSYS_LEVEL_EMERG, "This is an emergency %s value %d\n",
140 string, value);
141
142 Tracing of functions can be done using ENTER(), LEAVE();
143
144 An example of using ENTER is void function (char *name) { ENTER();
145 LEAVE(); }
146
147 Individual tracing levels are supported through the macros TRACE1(for‐
148 mat, args) TRACE2(format, args) TRACE8(format, args)
149
150 An example of using TRACE is
151
152 char *name = "test"; TRACE7 ("This is a trace 7 log with name %s\n",
153 name);
154
155 Note that ENTER/LEAVE/TRACE* calls are recorded only in the flight
156 recorder.
157
158
160 logsys_fork_completed(3), logsys_atexit(3), logsys_log_rec_store(3),
161 logsys_format_set(3), logsys_format_get(3), logsys_config_mode_set(3),
162 logsys_config_file_set(3), logsys_config_syslog_facility_set(3),
163 logsys_config_syslog_facility_get(3), logsys_config_mode_set(3),
164 logsys_config_mode_get(3), logsys_config_file_set(3), logsys_con‐
165 fig_logfile_priority_set(3), logsys_config_debug_set(3), logsys_facil‐
166 ity_id_get(3), logsys_facility_name_get(3), logsys_priority_id_get(3),
167 logsys_priority_name_get(3),
168
169corosync Man Page 2009-06-16 LOGSYS_OVERVIEW(8)