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

« back to all changes in this revision

Viewing changes to man/logsys_overview.8

  • 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
 
.\" * Copyright (c) 2007 Red Hat, Inc.
 
2
.\" * Copyright (c) 2007-2009 Red Hat, Inc.
3
3
.\" *
4
4
.\" * All rights reserved.
5
5
.\" *
6
6
.\" * Author: Steven Dake (sdake@redhat.com)
 
7
.\" * Author: Fabio M. Di Nitto (fdinitto@redhat.com)
7
8
.\" *
8
9
.\" * This software licensed under BSD license, the text of which follows:
9
 
.\" * 
 
10
.\" *
10
11
.\" * Redistribution and use in source and binary forms, with or without
11
12
.\" * modification, are permitted provided that the following conditions are met:
12
13
.\" *
31
32
.\" * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32
33
.\" * THE POSSIBILITY OF SUCH DAMAGE.
33
34
.\" */
34
 
.TH LOGSYS_OVERVIEW 8 2007-05-15 "corosync Man Page" "Corosync Cluster Engine Programmer's Manual"
 
35
.TH LOGSYS_OVERVIEW 8 2009-06-16 "corosync Man Page" "Corosync Cluster Engine Programmer's Manual"
35
36
.SH OVERVIEW
36
37
The logsys library provides a generically usable logging and tracing system for
37
38
use by applications.  It supports many features including:
50
51
 
51
52
.SH Declaration of the System logger
52
53
The logsys library is initially configured by including logsys.h and declaring
53
 
a logger.  Once the logger is declared either a subsystem logger or nosubsystem
54
 
logger is declared in every file.
 
54
a logger.  Once the logger is declared, optional subsystem loggers can be
 
55
declared in every file.
55
56
 
56
57
The definition LOGSYS_DECLARE_SYSTEM is placed after the include section of one
57
58
C file in the application.  This declaration creates a constructor function
58
 
which will be called automatically.  This technique avoids the need for calling
59
 
any setup functions in short applications that don't require it.
60
 
 
61
 
#define LOGSYS_DECLARE_SYSTEM(name,mode,file,facility)
62
 
The name parameter is the name of the application.
63
 
The mode parameter is the logging mode of the system.  The following modes
64
 
can be configured by logically ORing these flags:
65
 
LOG_MODE_OUTPUT_FILE: Output all log data to the file parameter of this declaration
66
 
LOG_MODE_OUTPUT_STDERR: Output all log data to the stderr descriptor
67
 
LOG_MODE_OUTPUT_SYSLOG_THREADED: Output all log data to syslog using a non-blocking thread
68
 
LOG_MODE_OUTPUT_SYSLOG_LOSSY: Output all log data without using a thread but potentially losing data.  This mode is not yet implemented.
69
 
LOG_MODE_OUTPUT_SYSLOG_BLOCKING: Output all log data without using a thread and potentially blocking at each syslog call.
70
 
LOG_MODE_DISPLAY_PRIORITY: Output the priority of the log entry in the message contents.  This mode is currently not implemented.
71
 
LOG_MODE_DISPLAY_FILELINE: Output the file and line at which the log message was created.
72
 
LOG_MODE_SHORT_FILELINE: When using LOG_DEBUG level or LOG_MODE_DISPLAY_FILELINE, typically the absolute path to the file (derived at compile-time) is displayed.  Enabling this flag ensures that only the filename and line are displayed.
73
 
LOG_MODE_DISPLAY_TIMESTAMP: Output the timestamp of the message.
74
 
LOG_MODE_BUFFER_BEFORE_CONFIG: This mode is used to buffer log messages before logsys_mode_config is called.  This is useful in applications in which the logging file isn't known before the application is compiled and must be set dynamically.  It is also useful when an application calls fork to disconnect the local tty and should hold logging of messages until after the fork.
75
 
LOG_MODE_FLUSH_AFTER_CONFIG: This mode is used to flush any buffered messages when the LOG_MODE_BUFFER_BEFORE_CONFIG declaration is specified in the declaration of the logger.
76
 
The file parameter specifies the filename that should be used to log messages.  This parameter may be NULL if LOG_MODE_OUTPUT_FILE is not specified.
77
 
The facility parameter is the syslog facility that should be used when logging
 
59
which will be called automatically before main() is executed.  This technique
 
60
avoids the need for calling any setup functions in short applications that don't
 
61
require it and enables full logging capabilities before any application code is
 
62
executed.
 
63
 
 
64
#define LOGSYS_DECLARE_SYSTEM (name, mode, debug, file, file_priority,
 
65
syslog_facility, syslog_priority, format, fltsize)
 
66
 
 
67
The name parameter is the name of the application or system.
 
68
 
 
69
The mode parameter is the logging mode of the system.
 
70
The following modes can be configured by logically ORing these flags:
 
71
 
 
72
LOGSYS_MODE_OUTPUT_FILE: Output all log data to the file parameter of this declaration
 
73
 
 
74
LOGSYS_MODE_OUTPUT_STDERR: Output all log data to the stderr descriptor
 
75
 
 
76
LOGSYS_MODE_OUTPUT_SYSLOG: Output all log data to syslog using a non-blocking thread
 
77
 
 
78
LOGSYS_MODE_FORK: This flags tells logsys to queue all data untill the application
 
79
has forked. The application is then responsible to call logsys_fork_completed to flush
 
80
the queue and start logging.
 
81
 
 
82
LOGSYS_MODE_THREADED: Starts a separate thread to handle non-blocking logging operations.
 
83
If this flag is not specified, the logging operations are blocking.
 
84
 
 
85
The debug parameter, if enabled, turns off all messages priority filtering, recording
 
86
everything everywhere.
 
87
 
 
88
The file parameter specifies the filename that should be used to log messages.
 
89
This parameter may be NULL and no log file will be created.
 
90
 
 
91
The file_priority parameter specifies the message priority that should be logged to file.
 
92
 
 
93
The syslog_facility parameter is the syslog facility that should be used when logging
78
94
messages.
79
 
LOG_MODE_NOSUBSYS: Enabling this mode removes the subsystem tag from the beginning of the log lines.  This is not recommended for programs which have multiple subsystems.
80
 
LOG_MODE_FILTER_DEBUG_FROM_SYSLOG: Enabling this mode will stop debug messages from being sent to syslog.
 
95
 
 
96
The syslog_priority, similar to file_priority, specifies the message priority that should be logged to
 
97
syslog.
 
98
 
 
99
The format parameter allows to set custom output format.
 
100
Set to NULL to use built-in default.
 
101
 
 
102
The fltsize parameter specifies the flight recorder buffer size in bytes. The requested value
 
103
is increased by the size of 2 unsigned ints and rounded to the next PAGE_SIZE.
81
104
 
82
105
An example declaration would be:
83
106
 
85
108
 
86
109
... (other #includes)
87
110
 
88
 
LOGSYS_DECLARE_SYSTEM ("my_example_app",
89
 
        LOG_MODE_OUTPUT_STDERR | LOG_MODE_OUTPUT_SYSLOG_THREADED | LOG_MODE_OUTPUT_FILE,
90
 
        "/tmp/log",
91
 
        LOG_DAEMON);
92
 
 
93
 
This would output any logging messages to stderr, syslog, and the file /tmp/log.
94
 
 
95
 
.SH Declaration of subsystems or no subsystems
 
111
LOGSYS_DECLARE_SYSTEM ("test",                            /* name */
 
112
        LOGSYS_MODE_OUTPUT_STDERR | LOGSYS_MODE_THREADED, /* mode */
 
113
        0,                                                /* debug */
 
114
        NULL,                                             /* logfile path */
 
115
        LOGSYS_LEVEL_INFO,                                /* logfile_priority */
 
116
        LOG_DAEMON,                                       /* syslog facility */
 
117
        LOGSYS_LEVEL_INFO,                                /* syslog level */
 
118
        NULL,                                             /* use default format */
 
119
        1000000);                                         /* flight recorder size */
 
120
 
 
121
 
 
122
.SH Declaration of subsystems
96
123
The logsys library supports the logging of information to one main system or
97
 
subsystem.  This is specified in each individual object file in the system.
98
 
 
99
 
if no subsystems are desired, The define LOGSYS_DECLARE_NOSUBSYS should be
100
 
declared for every object file in the system.  These object files are usually C
101
 
files.
102
 
 
103
 
An example of using this would be
104
 
 
105
 
LOGSYS_DECLARE_NOSUBSYS (LOG_LEVEL_INFO);
106
 
 
107
 
Any messages of LOG_LEVEL_INFO priority or higher would be logged.
108
 
 
109
 
If subsystems are desired, the define LOGSYS_DECLARE_SUBSYS should be declared
110
 
for every object file in the system.  It is possible to use the same subsystem
111
 
name in separate object files.  In this case, the individual logging parameters
112
 
for those subsystem identifier will be used.
113
 
 
114
 
An example of using this would be
115
 
LOGSYS_DECLARE_SUBSYS ("SYS1", LOG_LEVEL_INFO);
116
 
 
117
 
Any message of LOG_LEVEL_INFO priority or higher would be logged and any
118
 
logging within the object file this declaration is specified within will be
119
 
logged to the SYS1 subsystem identifier.
 
124
subsystem.  This is specified in each individual object C file in the system
 
125
and it is entirely optional.
 
126
 
 
127
An example:
 
128
 
 
129
LOGSYS_DECLARE_SUBSYS ("subsystest");
 
130
 
 
131
It is possible to use the same subsystem name in separate object files.
 
132
In this case, the individual logging parameters for those subsystem identifier
 
133
will be used.
 
134
 
 
135
A newly created subsystem inherits the system configuration at the time of
 
136
creation.
 
137
 
 
138
It is possible to override every configuration option on a subsystem base
 
139
throught the configuration API.
120
140
 
121
141
.SH Logging Messages
122
142
The definition log_printf is used to log information to the log.  It works
123
143
in a similiar fashion to printf, except it has a first parameter of level
124
144
which may be the following:
125
 
LOG_EMERG
126
 
LOG_ALERT
127
 
LOG_CRIT
128
 
LOG_ERR
129
 
LOG_WARNING
130
 
LOG_NOTICE
131
 
LOG_INFO
132
 
LOG_DEBUG
 
145
LOGSYS_LEVEL_EMERG
 
146
LOGSYS_LEVEL_ALERT
 
147
LOGSYS_LEVEL_CRIT
 
148
LOGSYS_LEVEL_ERR
 
149
LOGSYS_LEVEL_WARNING
 
150
LOGSYS_LEVEL_NOTICE
 
151
LOGSYS_LEVEL_INFO
 
152
LOGSYS_LEVEL_DEBUG
133
153
 
134
154
An example of using log_printf would be
135
155
 
136
 
log_printf (LOG_EMERG, "This is an emergency %s value %d\n", string, value);
137
 
 
138
 
Tracing of functions can be done using ENTER_VOID() or ENTER (format, args) LEAVE_VOID() or LEAVE (format, args);
139
 
 
140
 
An exmaple of using ENTER_VOID is
141
 
void funtion (void) {
142
 
ENTER_VOID();
143
 
... function contents ...
144
 
LEAVE_VOID();
145
 
}
146
 
 
147
 
An example of using ENTER is 
 
156
log_printf (LOGSYS_LEVEL_EMERG, "This is an emergency %s value %d\n", string, value);
 
157
 
 
158
Tracing of functions can be done using ENTER(), LEAVE();
 
159
 
 
160
An example of using ENTER is
148
161
void function (char *name) {
149
 
ENTER ("The name is %s\n", name);
 
162
ENTER();
150
163
... function contents ...
151
 
LEAVE ("Bye\n");
 
164
LEAVE();
152
165
}
153
166
 
154
167
Individual tracing levels are supported through the macros
162
175
char *name = "test";
163
176
TRACE7 ("This is a trace 7 log with name %s\n", name);
164
177
 
 
178
Note that ENTER/LEAVE/TRACE* calls are recorded only in the flight recorder.
 
179
 
165
180
.SH "SEE ALSO"
166
 
.BR logsys_config_mode_set (3),
167
 
.BR logsys_config_file_set (3),
168
 
.BR logsys_config_facility_set (3),
169
 
.BR logsys_config_facility_set (3),
170
 
.BR logsys_config_priority_set (3),
171
 
.BR logsys_config_subsys_set (3),
172
 
.BR logsys_config_subsys_get (3),
 
181
.BR logsys_fork_completed (3),
 
182
.BR logsys_atexit (3),
 
183
.BR logsys_log_rec_store (3),
 
184
.BR logsys_format_set (3),
 
185
.BR logsys_format_get (3),
 
186
.BR logsys_config_mode_set (3),
 
187
.BR logsys_config_file_set (3),
 
188
.BR logsys_config_syslog_facility_set (3),
 
189
.BR logsys_config_syslog_facility_get (3),
 
190
.BR logsys_config_mode_set (3),
 
191
.BR logsys_config_mode_get (3),
 
192
.BR logsys_config_file_set (3),
 
193
.BR logsys_config_logfile_priority_set (3),
 
194
.BR logsys_config_debug_set (3),
173
195
.BR logsys_facility_id_get (3),
 
196
.BR logsys_facility_name_get (3),
174
197
.BR logsys_priority_id_get (3),
175
 
.BR logsys_flush (3),
176
 
.BR logsys_atsegv (3),
 
198
.BR logsys_priority_name_get (3),
177
199
.PP