~ubuntu-branches/ubuntu/precise/corosync/precise-proposed

« back to all changes in this revision

Viewing changes to include/corosync/engine/logsys.h

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2009-08-21 09:29:56 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090821092956-w9qxxxx3zeoh8dem
Tags: 1.0.0-4ubuntu2
* debian/control:
  - 'Ubuntu Developers' instead of 'Ubuntu Core Developers'
    as maintainer
  - Bump debhelper dependecy to 7

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Copyright (c) 2002-2004 MontaVista Software, Inc.
3
 
 * Copyright (c) 2006-2007 Red Hat, Inc.
 
3
 * Copyright (c) 2006-2009 Red Hat, Inc.
4
4
 *
5
5
 * Author: Steven Dake (sdake@redhat.com)
6
6
 * Author: Lon Hohberger (lhh@redhat.com)
 
7
 * Author: Fabio M. Di Nitto (fdinitto@redhat.com)
7
8
 *
8
9
 * All rights reserved.
9
10
 *
10
11
 * This software licensed under BSD license, the text of which follows:
11
 
 * 
 
12
 *
12
13
 * Redistribution and use in source and binary forms, with or without
13
14
 * modification, are permitted provided that the following conditions are met:
14
15
 *
37
38
#define LOGSYS_H_DEFINED
38
39
 
39
40
#include <stdarg.h>
 
41
#include <stdlib.h>
40
42
#include <syslog.h>
41
 
#include <assert.h>
 
43
#include <pthread.h>
 
44
#include <limits.h>
 
45
 
 
46
#ifdef __cplusplus
 
47
extern "C" {
 
48
#endif
42
49
 
43
50
/*
44
 
 * MODE_OUTPUT_SYSLOG_* modes are mutually exclusive
 
51
 * All of the LOGSYS_MODE's can be ORed together for combined behavior
 
52
 *
 
53
 * FORK and THREADED are ignored for SUBSYSTEMS
45
54
 */
46
 
#define LOG_MODE_OUTPUT_FILE            (1<<0)
47
 
#define LOG_MODE_OUTPUT_STDERR          (1<<1)
48
 
#define LOG_MODE_OUTPUT_SYSLOG_THREADED (1<<2)
49
 
#define LOG_MODE_OUTPUT_SYSLOG_LOSSY    (1<<3)
50
 
#define LOG_MODE_OUTPUT_SYSLOG_BLOCKING (1<<4)
51
 
#define LOG_MODE_DISPLAY_PRIORITY       (1<<5)
52
 
#define LOG_MODE_DISPLAY_FILELINE       (1<<6)
53
 
#define LOG_MODE_DISPLAY_TIMESTAMP      (1<<7)
54
 
#define LOG_MODE_BUFFER_BEFORE_CONFIG   (1<<8)
55
 
#define LOG_MODE_FLUSH_AFTER_CONFIG     (1<<9)
56
 
#define LOG_MODE_SHORT_FILELINE         (1<<10)
57
 
#define LOG_MODE_NOSUBSYS               (1<<11)
58
 
#define LOG_MODE_FILTER_DEBUG_FROM_SYSLOG       (1<<12)
 
55
#define LOGSYS_MODE_OUTPUT_FILE         (1<<0)
 
56
#define LOGSYS_MODE_OUTPUT_STDERR       (1<<1)
 
57
#define LOGSYS_MODE_OUTPUT_SYSLOG       (1<<2)
 
58
#define LOGSYS_MODE_FORK                (1<<3)
 
59
#define LOGSYS_MODE_THREADED            (1<<4)
59
60
 
60
61
/*
61
62
 * Log priorities, compliant with syslog and SA Forum Log spec.
62
63
 */
63
 
#define LOG_LEVEL_EMERG                 LOG_EMERG
64
 
#define LOG_LEVEL_ALERT                 LOG_ALERT
65
 
#define LOG_LEVEL_CRIT                  LOG_CRIT
66
 
#define LOG_LEVEL_ERROR                 LOG_ERR
67
 
#define LOG_LEVEL_WARNING               LOG_WARNING
68
 
#define LOG_LEVEL_SECURITY              LOG_WARNING // corosync specific
69
 
#define LOG_LEVEL_NOTICE                LOG_NOTICE
70
 
#define LOG_LEVEL_INFO                  LOG_INFO
71
 
#define LOG_LEVEL_DEBUG                 LOG_DEBUG
72
 
 
73
 
/*
74
 
** Log tags, used by _logsys_trace macros, uses 32 bits => 32 different tags
75
 
*/      
76
 
#define LOGSYS_TAG_LOG                  (1<<0)
77
 
#define LOGSYS_TAG_ENTER                (1<<1)
78
 
#define LOGSYS_TAG_LEAVE                (1<<2)
79
 
#define LOGSYS_TAG_TRACE1               (1<<3)
80
 
#define LOGSYS_TAG_TRACE2               (1<<4)
81
 
#define LOGSYS_TAG_TRACE3               (1<<5)
82
 
#define LOGSYS_TAG_TRACE4               (1<<6)
83
 
#define LOGSYS_TAG_TRACE5               (1<<7)
84
 
#define LOGSYS_TAG_TRACE6               (1<<8)
85
 
#define LOGSYS_TAG_TRACE7               (1<<9)
86
 
#define LOGSYS_TAG_TRACE8               (1<<10)
87
 
 
88
 
/*
89
 
 * External API
90
 
 */
91
 
 
92
 
struct logsys_logger {
93
 
        char subsys[6];
94
 
        unsigned int priority;
95
 
        unsigned int tags;
96
 
        unsigned int mode;
97
 
};
98
 
 
99
 
extern struct logsys_logger logsys_loggers[];
100
 
 
101
 
extern int logsys_single_id;
102
 
 
103
 
extern inline int logsys_mkpri (int priority, int id);
104
 
 
105
 
extern void logsys_config_mode_set (
 
64
#define LOGSYS_LEVEL_EMERG              LOG_EMERG
 
65
#define LOGSYS_LEVEL_ALERT              LOG_ALERT
 
66
#define LOGSYS_LEVEL_CRIT               LOG_CRIT
 
67
#define LOGSYS_LEVEL_ERROR              LOG_ERR
 
68
#define LOGSYS_LEVEL_WARNING            LOG_WARNING
 
69
#define LOGSYS_LEVEL_NOTICE             LOG_NOTICE
 
70
#define LOGSYS_LEVEL_INFO               LOG_INFO
 
71
#define LOGSYS_LEVEL_DEBUG              LOG_DEBUG
 
72
 
 
73
/*
 
74
 * All of the LOGSYS_RECID's are mutually exclusive. Only one RECID at any time
 
75
 * can be specified.
 
76
 *
 
77
 * RECID_LOG indicates a message that should be sent to log. Anything else
 
78
 * is stored only in the flight recorder.
 
79
 */
 
80
 
 
81
#define LOGSYS_RECID_MAX                ((UINT_MAX) >> LOGSYS_SUBSYSID_END)
 
82
 
 
83
#define LOGSYS_RECID_LOG                (LOGSYS_RECID_MAX - 1)
 
84
#define LOGSYS_RECID_ENTER              (LOGSYS_RECID_MAX - 2)
 
85
#define LOGSYS_RECID_LEAVE              (LOGSYS_RECID_MAX - 3)
 
86
#define LOGSYS_RECID_TRACE1             (LOGSYS_RECID_MAX - 4)
 
87
#define LOGSYS_RECID_TRACE2             (LOGSYS_RECID_MAX - 5)
 
88
#define LOGSYS_RECID_TRACE3             (LOGSYS_RECID_MAX - 6)
 
89
#define LOGSYS_RECID_TRACE4             (LOGSYS_RECID_MAX - 7)
 
90
#define LOGSYS_RECID_TRACE5             (LOGSYS_RECID_MAX - 8)
 
91
#define LOGSYS_RECID_TRACE6             (LOGSYS_RECID_MAX - 9)
 
92
#define LOGSYS_RECID_TRACE7             (LOGSYS_RECID_MAX - 10)
 
93
#define LOGSYS_RECID_TRACE8             (LOGSYS_RECID_MAX - 11)
 
94
 
 
95
 
 
96
/*
 
97
 * Internal APIs that must be globally exported
 
98
 * (External API below)
 
99
 */
 
100
 
 
101
/*
 
102
 * logsys_logger bits
 
103
 *
 
104
 * SUBSYS_COUNT defines the maximum number of subsystems
 
105
 * SUBSYS_NAMELEN defines the maximum len of a subsystem name
 
106
 */
 
107
#define LOGSYS_MAX_SUBSYS_COUNT         64
 
108
#define LOGSYS_MAX_SUBSYS_NAMELEN       64
 
109
 
 
110
/*
 
111
 * rec_ident explained:
 
112
 *
 
113
 * rec_ident is an unsigned int and carries bitfields information
 
114
 * on subsys_id, log priority (level) and type of message (RECID).
 
115
 *
 
116
 * level values are imported from syslog.h.
 
117
 * At the time of writing it's a 3 bits value (0 to 7).
 
118
 *
 
119
 * subsys_id is any value between 0 and 64 (LOGSYS_MAX_SUBSYS_COUNT)
 
120
 *
 
121
 * RECID identifies the type of message. A set of predefined values
 
122
 * are available via logsys, but other custom values can be defined
 
123
 * by users.
 
124
 *
 
125
 * ----
 
126
 * bitfields:
 
127
 *
 
128
 * 0  - 2 level
 
129
 * 3  - 9 subsysid
 
130
 * 10 - n RECID
 
131
 */
 
132
 
 
133
#define LOGSYS_LEVEL_END                (3)
 
134
#define LOGSYS_SUBSYSID_END             (LOGSYS_LEVEL_END + 7)
 
135
 
 
136
#define LOGSYS_RECID_LEVEL_MASK         (LOG_PRIMASK)
 
137
#define LOGSYS_RECID_SUBSYSID_MASK      ((2 << (LOGSYS_SUBSYSID_END - 1)) - \
 
138
                                        (LOG_PRIMASK + 1))
 
139
#define LOGSYS_RECID_RECID_MASK         (UINT_MAX - \
 
140
                                        (LOGSYS_RECID_SUBSYSID_MASK + LOG_PRIMASK))
 
141
 
 
142
#define LOGSYS_ENCODE_RECID(level,subsysid,recid) \
 
143
        (((recid) << LOGSYS_SUBSYSID_END) | \
 
144
        ((subsysid) << LOGSYS_LEVEL_END) | \
 
145
        (level))
 
146
 
 
147
#define LOGSYS_DECODE_LEVEL(rec_ident) \
 
148
        ((rec_ident) & LOGSYS_RECID_LEVEL_MASK)
 
149
 
 
150
#define LOGSYS_DECODE_SUBSYSID(rec_ident) \
 
151
        (((rec_ident) & LOGSYS_RECID_SUBSYSID_MASK) >> LOGSYS_LEVEL_END)
 
152
 
 
153
#define LOGSYS_DECODE_RECID(rec_ident) \
 
154
        (((rec_ident) & LOGSYS_RECID_RECID_MASK) >> LOGSYS_SUBSYSID_END)
 
155
 
 
156
#ifndef LOGSYS_UTILS_ONLY
 
157
 
 
158
extern int _logsys_system_setup(
 
159
        const char *mainsystem,
 
160
        unsigned int mode,
 
161
        unsigned int debug,
 
162
        const char *logfile,
 
163
        int logfile_priority,
 
164
        int syslog_facility,
 
165
        int syslog_priority);
 
166
 
 
167
extern int _logsys_config_subsys_get (
 
168
        const char *subsys);
 
169
 
 
170
extern unsigned int _logsys_subsys_create (const char *subsys);
 
171
 
 
172
extern int _logsys_rec_init (unsigned int size);
 
173
 
 
174
extern void _logsys_log_vprintf (
 
175
        unsigned int rec_ident,
 
176
        const char *function_name,
 
177
        const char *file_name,
 
178
        int file_line,
 
179
        const char *format,
 
180
        va_list ap) __attribute__((format(printf, 5, 0)));
 
181
 
 
182
extern void _logsys_log_printf (
 
183
        unsigned int rec_ident,
 
184
        const char *function_name,
 
185
        const char *file_name,
 
186
        int file_line,
 
187
        const char *format,
 
188
        ...) __attribute__((format(printf, 5, 6)));
 
189
 
 
190
extern void _logsys_log_rec (
 
191
        unsigned int rec_ident,
 
192
        const char *function_name,
 
193
        const char *file_name,
 
194
        int file_line,
 
195
        ...);
 
196
 
 
197
extern int _logsys_wthread_create (void);
 
198
 
 
199
static int logsys_subsys_id __attribute__((unused)) = LOGSYS_MAX_SUBSYS_COUNT;
 
200
 
 
201
/*
 
202
 * External API - init
 
203
 * See below:
 
204
 *
 
205
 * LOGSYS_DECLARE_SYSTEM
 
206
 * LOGSYS_DECLARE_SUBSYS
 
207
 *
 
208
 */
 
209
extern void logsys_fork_completed (void);
 
210
 
 
211
extern void logsys_atexit (void);
 
212
 
 
213
/*
 
214
 * External API - misc
 
215
 */
 
216
extern void logsys_flush (void);
 
217
 
 
218
extern int logsys_log_rec_store (const char *filename);
 
219
 
 
220
/*
 
221
 * External API - configuration
 
222
 */
 
223
 
 
224
/*
 
225
 * configuration bits that can only be done for the whole system
 
226
 */
 
227
extern int logsys_format_set (
 
228
        const char *format);
 
229
 
 
230
extern char *logsys_format_get (void);
 
231
 
 
232
/*
 
233
 * per system/subsystem settings.
 
234
 *
 
235
 * NOTE: once a subsystem is created and configured, changing
 
236
 * the default does NOT affect the subsystems.
 
237
 *
 
238
 * Pass a NULL subsystem to change them all
 
239
 */
 
240
extern unsigned int logsys_config_syslog_facility_set (
 
241
        const char *subsys,
 
242
        unsigned int facility);
 
243
 
 
244
extern unsigned int logsys_config_syslog_priority_set (
 
245
        const char *subsys,
 
246
        unsigned int priority);
 
247
 
 
248
extern unsigned int logsys_config_mode_set (
 
249
        const char *subsys,
106
250
        unsigned int mode);
107
251
 
108
 
extern unsigned int logsys_config_mode_get (void);
 
252
extern unsigned int logsys_config_mode_get (
 
253
        const char *subsys);
109
254
 
 
255
/*
 
256
 * to close a logfile, just invoke this function with a NULL
 
257
 * file or if you want to change logfile, the old one will
 
258
 * be closed for you.
 
259
 */
110
260
extern int logsys_config_file_set (
111
 
        char **error_string,
112
 
        char *file);
113
 
 
114
 
extern void logsys_config_facility_set (
115
 
        char *name,
116
 
        unsigned int facility);
117
 
 
118
 
extern unsigned int logsys_config_subsys_set (
119
 
        const char *subsys,
120
 
        unsigned int tags,
 
261
        const char *subsys,
 
262
        const char **error_string,
 
263
        const char *file);
 
264
 
 
265
extern unsigned int logsys_config_logfile_priority_set (
 
266
        const char *subsys,
121
267
        unsigned int priority);
122
268
 
123
 
extern int logsys_config_subsys_get (
 
269
/*
 
270
 * enabling debug, disable message priority filtering.
 
271
 * everything is sent everywhere. priority values
 
272
 * for file and syslog are not overwritten.
 
273
 */
 
274
extern unsigned int logsys_config_debug_set (
124
275
        const char *subsys,
125
 
        unsigned int *tags,
126
 
        unsigned int *priority);
 
276
        unsigned int value);
127
277
 
 
278
/*
 
279
 * External API - helpers
 
280
 *
 
281
 * convert facility/priority to/from name/values
 
282
 */
128
283
extern int logsys_facility_id_get (
129
284
        const char *name);
130
285
 
137
292
extern const char *logsys_priority_name_get (
138
293
        unsigned int priority);
139
294
 
140
 
extern void logsys_flush (void);
141
 
 
142
 
extern void logsys_atsegv (void);
143
 
 
144
 
/*
145
 
 * Internal APIs that must be globally exported
146
 
 */
147
 
extern unsigned int _logsys_subsys_create (const char *ident,
148
 
        unsigned int priority);
149
 
 
150
 
extern void _logsys_nosubsys_set (void);
151
 
 
152
 
extern int _logsys_wthread_create (void);
153
 
 
154
 
extern void logsys_log_printf (char *file, int line, int priority,
155
 
        char *format, ...) __attribute__((format(printf, 4, 5)));
156
 
 
157
 
extern void _logsys_log_printf2 (char *file, int line, int priority,
158
 
        int id, char *format, ...) __attribute__((format(printf, 5, 6)));
159
 
 
160
 
extern void _logsys_trace (char *file, int line, int tag, int id,
161
 
        char *format, ...) __attribute__((format(printf, 5, 6)));
 
295
extern int logsys_thread_priority_set (
 
296
        int policy,
 
297
        const struct sched_param *param,
 
298
        unsigned int after_log_ops_yield);
162
299
 
163
300
/*
164
301
 * External definitions
165
302
 */
166
 
#define LOGSYS_DECLARE_SYSTEM(name,mode,file,facility)                  \
167
 
__attribute__ ((constructor)) static void logsys_system_init (void)     \
 
303
extern void *logsys_rec_end;
 
304
 
 
305
#define LOGSYS_REC_END (&logsys_rec_end)
 
306
 
 
307
#define LOGSYS_DECLARE_SYSTEM(name,mode,debug,file,file_priority,       \
 
308
                syslog_facility,syslog_priority,format,fltsize)         \
 
309
__attribute__ ((constructor))                                           \
 
310
static void logsys_system_init (void)                                   \
168
311
{                                                                       \
169
 
        char *error_string;                                             \
170
 
                                                                        \
171
 
        logsys_config_mode_set (mode);                                  \
172
 
        logsys_config_file_set (&error_string, (file));                 \
173
 
        logsys_config_facility_set (name, (facility));                  \
174
 
        if (((mode) & LOG_MODE_BUFFER_BEFORE_CONFIG) == 0) {            \
175
 
                _logsys_wthread_create ();                              \
 
312
        if (_logsys_system_setup (name,mode,debug,file,file_priority,   \
 
313
                        syslog_facility,syslog_priority) < 0) {         \
 
314
                fprintf (stderr,                                        \
 
315
                        "Unable to setup logging system: %s.\n", name); \
 
316
                exit (-1);                                              \
 
317
        }                                                               \
 
318
                                                                        \
 
319
        if (logsys_format_set (format) < 0) {                           \
 
320
                fprintf (stderr,                                        \
 
321
                        "Unable to setup logging format.\n");           \
 
322
                exit (-1);                                              \
 
323
        }                                                               \
 
324
                                                                        \
 
325
        if (_logsys_rec_init (fltsize) < 0) {                           \
 
326
                fprintf (stderr,                                        \
 
327
                        "Unable to initialize log flight recorder.\n"); \
 
328
                exit (-1);                                              \
 
329
        }                                                               \
 
330
                                                                        \
 
331
        if (_logsys_wthread_create() < 0) {                             \
 
332
                fprintf (stderr,                                        \
 
333
                        "Unable to initialize logging thread.\n");      \
 
334
                exit (-1);                                              \
176
335
        }                                                               \
177
336
}
178
337
 
179
 
static unsigned int logsys_subsys_id __attribute__((unused)) = -1;      \
180
 
 
181
 
#define LOGSYS_DECLARE_NOSUBSYS(priority)                               \
182
 
__attribute__ ((constructor)) static void logsys_nosubsys_init (void)   \
 
338
#define LOGSYS_DECLARE_SUBSYS(subsys)                                   \
 
339
__attribute__ ((constructor))                                           \
 
340
static void logsys_subsys_init (void)                                   \
183
341
{                                                                       \
184
 
        unsigned int pri, tags;                                         \
185
 
                                                                        \
186
342
        logsys_subsys_id =                                              \
187
 
                logsys_config_subsys_get("MAIN", &tags, &pri);          \
188
 
                                                                        \
 
343
                _logsys_subsys_create ((subsys));                       \
189
344
        if (logsys_subsys_id == -1) {                                   \
190
 
                _logsys_nosubsys_set();                                 \
191
 
                logsys_subsys_id =                                      \
192
 
                        _logsys_subsys_create ("MAIN", (priority));     \
193
 
        }                                                               \
194
 
}
195
 
 
196
 
#define LOGSYS_DECLARE_SUBSYS(subsys,priority)                          \
197
 
__attribute__ ((constructor)) static void logsys_subsys_init (void)     \
198
 
{                                                                       \
199
 
        unsigned int pri, tags;                                         \
200
 
                                                                        \
201
 
        logsys_subsys_id =                                              \
202
 
                logsys_config_subsys_get((subsys), &tags, &pri);        \
203
 
                                                                        \
204
 
        if (logsys_subsys_id == -1)                                     \
205
 
                logsys_subsys_id =                                      \
206
 
                        _logsys_subsys_create ((subsys), (priority));   \
207
 
}
208
 
 
209
 
#define log_printf(lvl, format, args...) do {                           \
210
 
        if (logsys_single_id)                                           \
211
 
                logsys_subsys_id = 0;                                   \
212
 
        assert (logsys_subsys_id != -1);                                \
213
 
        if ((lvl) <= logsys_loggers[logsys_subsys_id].priority) {       \
214
 
                _logsys_log_printf2 (__FILE__, __LINE__, lvl,           \
215
 
                        logsys_subsys_id, (format), ##args);            \
216
 
        }                                                               \
217
 
} while(0)
218
 
 
219
 
#define dprintf(format, args...) do {                                   \
220
 
        if (logsys_single_id)                                           \
221
 
                logsys_subsys_id = 0;                                   \
222
 
        assert (logsys_subsys_id != -1);                                \
223
 
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
224
 
                _logsys_log_printf2 (__FILE__, __LINE__, LOG_DEBUG,     \
225
 
                        logsys_subsys_id, (format), ##args);            \
226
 
        }                                                               \
227
 
} while(0)
228
 
 
229
 
#define ENTER_VOID() do {                                               \
230
 
        if (logsys_single_id)                                           \
231
 
                logsys_subsys_id = 0;                                   \
232
 
        assert (logsys_subsys_id != -1);                                \
233
 
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
234
 
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_ENTER,    \
235
 
                        logsys_subsys_id, ">%s\n", __FUNCTION__);       \
236
 
        }                                                               \
237
 
} while(0)
238
 
 
239
 
#define ENTER(format, args...) do {                                     \
240
 
        if (logsys_single_id)                                           \
241
 
                logsys_subsys_id = 0;                                   \
242
 
        assert (logsys_subsys_id != -1);                                \
243
 
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
244
 
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_ENTER,    \
245
 
                        logsys_subsys_id, ">%s: " format, __FUNCTION__, \
246
 
                        ##args);                                        \
247
 
        }                                                               \
248
 
} while(0)
249
 
 
250
 
#define LEAVE_VOID() do {                                               \
251
 
        if (logsys_single_id)                                           \
252
 
                logsys_subsys_id = 0;                                   \
253
 
        assert (logsys_subsys_id != -1);                                \
254
 
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
255
 
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_LEAVE,    \
256
 
                        logsys_subsys_id, "<%s\n", __FUNCTION__);       \
257
 
        }                                                               \
258
 
} while(0)
259
 
 
260
 
#define LEAVE(format, args...) do {                                     \
261
 
        if (logsys_single_id)                                           \
262
 
                logsys_subsys_id = 0;                                   \
263
 
        assert (logsys_subsys_id != -1);                                \
264
 
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
265
 
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_LEAVE,    \
266
 
                        logsys_subsys_id, "<%s: " format,               \
267
 
                        __FUNCTION__, ##args);                          \
268
 
        }                                                               \
 
345
                fprintf (stderr,                                        \
 
346
                "Unable to create logging subsystem: %s.\n", subsys);   \
 
347
                exit (-1);                                              \
 
348
        }                                                               \
 
349
}
 
350
 
 
351
#define log_rec(rec_ident, args...)                                     \
 
352
do {                                                                    \
 
353
        _logsys_log_rec (rec_ident,  __FUNCTION__,                      \
 
354
                __FILE__,  __LINE__, ##args,                            \
 
355
                LOGSYS_REC_END);                                        \
 
356
} while(0)
 
357
 
 
358
#define log_printf(level, format, args...)                              \
 
359
 do {                                                                   \
 
360
        _logsys_log_printf (                                            \
 
361
                LOGSYS_ENCODE_RECID(level,                              \
 
362
                                    logsys_subsys_id,                   \
 
363
                                    LOGSYS_RECID_LOG),                  \
 
364
                 __FUNCTION__, __FILE__, __LINE__,                      \
 
365
                format, ##args);                                        \
 
366
} while(0)
 
367
 
 
368
#define ENTER() do {                                                    \
 
369
        _logsys_log_rec (                                               \
 
370
                LOGSYS_ENCODE_RECID(LOGSYS_LEVEL_DEBUG,                 \
 
371
                                    logsys_subsys_id,                   \
 
372
                                    LOGSYS_RECID_ENTER),                \
 
373
                __FUNCTION__, __FILE__,  __LINE__, LOGSYS_REC_END);     \
 
374
} while(0)
 
375
 
 
376
#define LEAVE() do {                                                    \
 
377
        _logsys_log_rec (                                               \
 
378
                LOGSYS_ENCODE_RECID(LOGSYS_LEVEL_DEBUG,                 \
 
379
                                    logsys_subsys_id,                   \
 
380
                                    LOGSYS_RECID_LEAVE),                \
 
381
                __FUNCTION__, __FILE__,  __LINE__, LOGSYS_REC_END);     \
 
382
} while(0)
 
383
 
 
384
#define TRACE(recid, format, args...) do {                              \
 
385
        _logsys_log_printf (                                            \
 
386
                LOGSYS_ENCODE_RECID(LOGSYS_LEVEL_DEBUG,                 \
 
387
                                    logsys_subsys_id,                   \
 
388
                                    recid),                             \
 
389
                 __FUNCTION__, __FILE__, __LINE__,                      \
 
390
                format, ##args);                                        \
269
391
} while(0)
270
392
 
271
393
#define TRACE1(format, args...) do {                                    \
272
 
        if (logsys_single_id)                                           \
273
 
                logsys_subsys_id = 0;                                   \
274
 
        assert (logsys_subsys_id != -1);                                \
275
 
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
276
 
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE1,   \
277
 
                        logsys_subsys_id, (format), ##args);            \
278
 
        }                                                               \
 
394
        TRACE(LOGSYS_RECID_TRACE1, format, ##args);                     \
279
395
} while(0)
280
396
 
281
397
#define TRACE2(format, args...) do {                                    \
282
 
        if (logsys_single_id)                                           \
283
 
                logsys_subsys_id = 0;                                   \
284
 
        assert (logsys_subsys_id != -1);                                \
285
 
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
286
 
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE2,   \
287
 
                        logsys_subsys_id, (format), ##args);            \
288
 
        }                                                               \
289
 
} while(0)
290
 
 
291
 
#define TRACE3(format, args...) do { \
292
 
        if (logsys_single_id)                                           \
293
 
                logsys_subsys_id = 0;                                   \
294
 
        assert (logsys_subsys_id != -1);                                \
295
 
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
296
 
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE3,   \
297
 
                        logsys_subsys_id, (format), ##args);            \
298
 
    }                                                                   \
299
 
} while(0)
300
 
 
301
 
#define TRACE4(format, args...) do { \
302
 
        if (logsys_single_id)                                           \
303
 
                logsys_subsys_id = 0;                                   \
304
 
        assert (logsys_subsys_id != -1);                                \
305
 
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
306
 
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE4,   \
307
 
                        logsys_subsys_id, (format), ##args);            \
308
 
        }                                                               \
 
398
        TRACE(LOGSYS_RECID_TRACE2, format, ##args);                     \
 
399
} while(0)
 
400
 
 
401
#define TRACE3(format, args...) do {                                    \
 
402
        TRACE(LOGSYS_RECID_TRACE3, format, ##args);                     \
 
403
} while(0)
 
404
 
 
405
#define TRACE4(format, args...) do {                                    \
 
406
        TRACE(LOGSYS_RECID_TRACE4, format, ##args);                     \
309
407
} while(0)
310
408
 
311
409
#define TRACE5(format, args...) do {                                    \
312
 
        if (logsys_single_id)                                           \
313
 
                logsys_subsys_id = 0;                                   \
314
 
        assert (logsys_subsys_id != -1);                                \
315
 
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
316
 
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE5,   \
317
 
                logsys_subsys_id, (format), ##args);                    \
318
 
        }                                                               \
 
410
        TRACE(LOGSYS_RECID_TRACE5, format, ##args);                     \
319
411
} while(0)
320
412
 
321
413
#define TRACE6(format, args...) do {                                    \
322
 
        if (logsys_single_id)                                           \
323
 
                logsys_subsys_id = 0;                                   \
324
 
        assert (logsys_subsys_id != -1);                                \
325
 
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
326
 
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE6,   \
327
 
                        logsys_subsys_id, (format), ##args);            \
328
 
        }                                                               \
 
414
        TRACE(LOGSYS_RECID_TRACE6, format, ##args);                     \
329
415
} while(0)
330
416
 
331
417
#define TRACE7(format, args...) do {                                    \
332
 
        if (logsys_single_id)                                           \
333
 
                logsys_subsys_id = 0;                                   \
334
 
        assert (logsys_subsys_id != -1);                                \
335
 
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
336
 
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE7,   \
337
 
                         logsys_subsys_id, (format), ##args);           \
338
 
        }                                                               \
 
418
        TRACE(LOGSYS_RECID_TRACE7, format, ##args);                     \
339
419
} while(0)
340
420
 
341
421
#define TRACE8(format, args...) do {                                    \
342
 
        if (logsys_single_id)                                           \
343
 
                logsys_subsys_id = 0;                                   \
344
 
        assert (logsys_subsys_id != -1);                                \
345
 
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
346
 
        _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE8,           \
347
 
         logsys_subsys_id, (format), ##args);                           \
348
 
        }                                                               \
349
 
} while(0)
350
 
 
351
 
extern void _logsys_config_priority_set (unsigned int id, unsigned int priority);
352
 
 
353
 
#define logsys_config_priority_set(priority) do {                       \
354
 
        if (logsys_single_id)                                           \
355
 
                logsys_subsys_id = 0;                                   \
356
 
        assert (logsys_subsys_id != -1);                                \
357
 
        _logsys_config_priority_set (logsys_subsys_id, priority);       \
358
 
} while(0)
359
 
 
360
 
/* simple, function-based api */
361
 
 
362
 
int logsys_init (char *name, int mode, int facility, int priority, char *file);
363
 
int logsys_conf (char *name, int mode, int facility, int priority, char *file);
364
 
void logsys_exit (void);
 
422
        TRACE(LOGSYS_RECID_TRACE8, format, ##args);                     \
 
423
} while(0)
 
424
 
 
425
#endif /* LOGSYS_UTILS_ONLY */
 
426
 
 
427
#ifdef __cplusplus
 
428
}
 
429
#endif
365
430
 
366
431
#endif /* LOGSYS_H_DEFINED */