File: xlog.3

package info (click to toggle)
xinetd 1%3A2.3.15.4-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,324 kB
  • sloc: ansic: 15,809; makefile: 207; sh: 165; perl: 92
file content (297 lines) | stat: -rw-r--r-- 7,068 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
.\"(c) Copyright 1992, 1993 by Panagiotis Tsirigotis
.\"All rights reserved.  The file named COPYRIGHT specifies the terms
.\"and conditions for redistribution.
.\"
.\" $Id$
.TH XLOG 3X "15 June 1993"
xlog_parms, xlog_create, xlog_destroy, xlog_write, xlog_control -- general purpose logging facility
.SH SYNOPSIS
.LP
.nf
.ft B
#include "xlog.h"
.LP
.ft B
xlog_h xlog_create( type, id, flags, ... )
xlog_e type ;
char *id ;
int flags ;
.LP
.ft B
int xlog_parms( type, ... )
xlog_e type ;
.LP
.ft B
void xlog_destroy( xlog )
xlog_h xlog ;
.LP
.ft B
void xlog_write( xlog, buf, len, flags, ... )
xlog_h xlog ;
char buf[] ;
int len ;
int flags ;
.LP
.ft B
int xlog_control( xlog, cmd, ... )
xlog_h xlog ;
xlog_cmd_e cmd ;
.SH DESCRIPTION
The purpose of this library is to provide a general purpose logging facility
by providing
.I xlogs,
logging objects that may be connected to various existent logging facilities.
Currently, the only logging facilities supported are
.I "syslog(3)"
and logging to files.
Log entries are timestamped lines which may contain arbitrary information.
.\" ********************* xlog_create ***********************
.LP
.B xlog_create()
creates a new xlog of the specified
.I type.
Possible type values are:
.RS
.TP 20
.SB XLOG_SYSLOG
Varargs: \fIint facility, int priority\fP.
The xlog will be connected to
.I "syslog(3)."
.I facility
determines the syslog facility to use for logged messages and
.I priority
is the default message priority.
.TP
.SB XLOG_FILELOG
Varargs: \fIchar *pathname, int flags [, int flags]\fP.
The xlog will be connected to the file identified by
.I pathname.
The variable part of the argument list has the same semantics as the
argument list of the
.I "open(2)"
system call.
.RE
.LP
All xlogs have an id, specified by the
.I id
argument. The
.I flags
argument is formed by ORing one or more of the following constants:
.RS
.TP 20
.SB XLOG_NO_ERRNO
do not replace
.I "%m"
with an explanation of the current value of errno.
.TP
.SB XLOG_NO_SIZECHECK
.I "(XLOG_FILELOG only)"
do not perform size checks on the file.
.TP
.SB XLOG_PRINT_ID
precede each log entry with the xlog id
.TP
.SB XLOG_PRINT_PID
precede each log entry with the process id
(the process id will follow the xlog id)
.RE
.LP
Flags that do not apply to the xlog are ignored.
The contant
.SM XLOG_NOFLAGS
can be used if you don't want to specify any flags.
.\" ********************* xlog_parms ***********************
.LP
.B xlog_parms()
sets default parameters for the specified xlog
.I type:
.RS
.TP 20
.SB XLOG_SYSLOG
3 arguments are expected which correspond one-to-one to the arguments of
.I "openlog(3)."
The defaults, in case this function is not used, are:
"XLOG", LOG_PID + LOG_NOWAIT, LOG_USER
.TP
.SB XLOG_FILELOG
No action.
.RE
.LP
.B xlog_parms()
should be invoked before any xlogs of the specified type
are created.
.\" ********************* xlog_destroy ***********************
.LP
.B xlog_destroy()
destroys an xlog. The action taken depends on the type of the xlog:
.RS
.TP 20
.SB XLOG_SYSLOG
if this is the last xlog using syslog, then
.I "closelog(3)"
is invoked.
.TP
.SB XLOG_FILELOG
The file is closed.
.RE
.\" ********************* xlog_control ***********************
.LP
.B xlog_control()
applies control operations to an xlog. Certain operations are common to
all xlogs while others are type-specific. The common ones are:
.RS
.TP 15
.SB XLOG_LINK
Argument list: \fIxlog_h link_to\fP.
Link the specified xlog to the one provided as argument.
(if the argument is
.SM NULL
any existent link is severed).
Linking xlogs has the effect that if one finds an error it uses the
other to report it.
.TP
.SB XLOG_CALLBACK
Argument list: \fIvoid (*callback)(), void *arg\fP.
This function will be invoked in case of error while writing a log
entry. It will be given
3 arguments: the xlog handle, an integer that indicates the type
of error and the
.I arg
specified in this call. Possible errors include:
.RS
.TP 15
.SB XLOG_ENOMEM
lack of memory
.TP
.SB XLOG_EOPEN
.I "open(2)"
failed
.TP
.SB XLOG_EFSTAT
.I "fstat(2)"
failed
.TP
.SB XLOG_ESIZE
hard limit exceeded
.RE
.TP
.SB XLOG_SETFLAG
Argument list: \fIint flag, int *value\fP.
The value of
.I flag
(one of those listed before) is set according to
.I "*value"
which should be either 0 or 1.
The old flag value is placed in
.I "*value."
.TP
.SB XLOG_GETFLAG
Argument list: \fIint flag, int *value\fP.
The value of
.I flag
(one of those listed before) is placed in
.I "*value."
.RE
.LP
Xlogs of type
.B XLOG_SYSLOG
also support the following operations:
.RS
.TP 15
.SB XLOG_FACILITY
Argument list: \fIint facility\fP.
Sets the syslog facility to the specified value.
.TP
.SB XLOG_LEVEL
Argument list: \fIint level\fP.
Sets the default syslog level for this xlog to the specified value.
.TP
.SB XLOG_PREEXEC
Argument list: \fIvoid\fP.
Prepares the xlog for an impending exec operation
.TP
.SB XLOG_POSTEXEC
Argument list: \fIvoid\fP.
Informs the xlog that the exec failed
.RE
.LP
Xlogs of type
.B XLOG_FILELOG
also support the following operations:
.RS
.TP 15
.SB XLOG_LIMITS
Argument list: \fIunsigned soft_limit, unsigned hard_limit\fP.
Sets soft and hard limits on the size of the file.
When any of the limits is exceeded a message is sent to the linked xlog.
(if there is no linked xlog, no message is sent)
When the soft limit is exceeded a warning message is sent to the linked xlog
(if the linked xlog is of the
.SB XLOG_SYSLOG
type, the message will be sent at the
.I LOG_ALERT
level).
If the exceeded limit is the hard limit, logging is terminated.
The actual file size is checked every time this operation is applied to
the file.
If logging was terminated because the hard limit was exceeded and
this operation increases the hard limit beyond the actual file size,
logging will be resumed.
.TP
.SB XLOG_SIZECHECK
Argument list: \fIvoid\fP.
Checks the actual file size.
.TP
.SB XLOG_GETFD
Argument list: \fIint *value\fP.
Places in
.I "*value"
the file descriptor of the log file.
.RE
.\" ********************* xlog_write ***********************
.LP
.B xlog_write()
writes a message to the specified xlog. A
.SM NEWLINE
is always appended to the message.
The first occurrence of "%m" in
.I buf
is replaced by a string explaining the current value of
.I errno.
The
.I flags
argument is formed in the same way as in
.B xlog_create().
One additional constant is available:
.RS
.TP 20
.SB XLOG_SET_LEVEL
.I "(XLOG_SYSLOG only)"
the next argument is an integer that should be used as the syslog level
for this message instead of the default level of the xlog.
.RE
.SH "RETURN VALUES"
.B xlog_create()
returns an xlog handle or
.SM NULL
if it fails.
.LP
.B xlog_control()
returns an error code (it returns
.SM XLOG_ENOERROR
if it is successful).
.LP
.B xlog_parms()
returns an error code (it returns
.SM XLOG_ENOERROR
if it is successful).
.SH "SEE ALSO"
openlog(3), syslog(3), closelog(3)
.SH BUGS
.LP
Only the first occurrence of
.I "%m"
is replaced by an errno explanation.
.LP
There is no check for cycles when linking xlogs. In particular it is
possible to link a xlog to itself.