23139
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
|
3 |
"
|
|
4 |
COPYRIGHT (c) 2018 by eXept Software AG
|
|
5 |
All Rights Reserved
|
|
6 |
|
|
7 |
This software is furnished under a license and may be used
|
|
8 |
only in accordance with the terms of that license and with the
|
|
9 |
inclusion of the above copyright notice. This software may not
|
|
10 |
be provided or otherwise made available to, or used by, any
|
|
11 |
other person. No title to or ownership of the software is
|
|
12 |
hereby transferred.
|
|
13 |
"
|
|
14 |
"{ Package: 'stx:libbasic' }"
|
|
15 |
|
|
16 |
"{ NameSpace: Smalltalk }"
|
|
17 |
|
|
18 |
MiniLogger subclass:#UnixSyslogInterface
|
|
19 |
instanceVariableNames:''
|
|
20 |
classVariableNames:'LOG_EMERG LOG_ALERT LOG_CRIT LOG_ERR LOG_WARNING LOG_NOTICE
|
|
21 |
LOG_INFO LOG_DEBUG LOG_KERN LOG_USER LOG_MAIL LOG_DAEMON LOG_AUTH
|
|
22 |
LOG_SYSLOG LOG_LPR LOG_NEWS LOG_UUCP LOG_CRON LOG_AUTHPRIV
|
|
23 |
LOG_FTP LOG_LOCAL0 LOG_LOCAL1 LOG_LOCAL2 LOG_LOCAL3 LOG_LOCAL4
|
|
24 |
LOG_LOCAL5 LOG_LOCAL6 LOG_LOCAL7 LOG_PID LOG_CONS LOG_ODELAY
|
23220
|
25 |
LOG_NDELAY LOG_PERROR PriorityMapping DefaultSyslogFacility
|
|
26 |
DefaultSyslogFacilityString PriorityToStringMapping UseCommand'
|
23139
|
27 |
poolDictionaries:''
|
|
28 |
category:'System-Debugging-Support'
|
|
29 |
!
|
|
30 |
|
|
31 |
!UnixSyslogInterface class methodsFor:'documentation'!
|
|
32 |
|
|
33 |
copyright
|
|
34 |
"
|
|
35 |
COPYRIGHT (c) 2018 by eXept Software AG
|
|
36 |
All Rights Reserved
|
|
37 |
|
|
38 |
This software is furnished under a license and may be used
|
|
39 |
only in accordance with the terms of that license and with the
|
|
40 |
inclusion of the above copyright notice. This software may not
|
|
41 |
be provided or otherwise made available to, or used by, any
|
|
42 |
other person. No title to or ownership of the software is
|
|
43 |
hereby transferred.
|
|
44 |
|
|
45 |
"
|
|
46 |
!
|
|
47 |
|
|
48 |
documentation
|
|
49 |
"
|
|
50 |
This logger logs messages via the Unix/Linux syslog system call
|
|
51 |
(so it is not available in Windows).
|
|
52 |
It uses any log method implemented in the syslog system call, e.g.
|
|
53 |
logging via network.
|
|
54 |
|
|
55 |
[author:]
|
|
56 |
Stefan Vogel
|
|
57 |
|
|
58 |
[class variables:]
|
|
59 |
DefaultSyslogFacility Integer the default facility of syslog (e.g. self LOG_LOCAL0).
|
|
60 |
This is different from the Logger facility arg.
|
|
61 |
|
|
62 |
[see also:]
|
|
63 |
MiniLogger
|
|
64 |
"
|
|
65 |
!
|
|
66 |
|
|
67 |
examples
|
|
68 |
"
|
|
69 |
[exBegin]
|
|
70 |
Logger := self.
|
|
71 |
self info:'%1 info demo » (%2%)' with:'stx' with:16.
|
|
72 |
self warning:'%1 warning demo (%2%)' with:'stx' with:16.
|
|
73 |
self error:'%1 error demo (%2%)' with:'stx' with:16.
|
|
74 |
self fatal:'%1 fatal demo (%2%)' with:'stx' with:16.
|
24134
|
75 |
Logger := MiniLogger.
|
23139
|
76 |
[exEnd]
|
|
77 |
|
|
78 |
[exBegin]
|
|
79 |
self openlog:'stx' option:0 facility:self LOG_USER.
|
|
80 |
self syslog:self LOG_WARNING message:'%1 demo (%2%)' arguments:#('stx' 16).
|
|
81 |
self closelog.
|
|
82 |
[exEnd]
|
|
83 |
"
|
|
84 |
! !
|
|
85 |
|
|
86 |
!UnixSyslogInterface class methodsFor:'initialization'!
|
|
87 |
|
|
88 |
initialize
|
|
89 |
|
|
90 |
"/ Priorities
|
|
91 |
PriorityMapping := Dictionary new.
|
|
92 |
PriorityMapping
|
|
93 |
at:FATAL put:0; "/ LOG_EMERG: system is unusable
|
|
94 |
"/ 1 LOG_ALERT: action must be taken immediately
|
|
95 |
"/ 2 LOG_CRIT: critical conditions
|
|
96 |
at:ERROR put:3; "/ LOG_ERR: error conditions
|
|
97 |
at:WARNING put:4; "/ LOG_WARNING: warning conditions
|
|
98 |
at:WARN put:4;
|
|
99 |
"/ 5 LOG_NOTICE: normal but significant condition
|
|
100 |
at:INFO put:6; "/ LOG_INFO: informational
|
|
101 |
at:DEBUG put:7; "/ LOG_DEBUG: informational
|
|
102 |
at:TRACE0 put:7; "/ LOG_DEBUG: informational
|
|
103 |
at:TRACE1 put:7; "/ LOG_DEBUG: informational
|
|
104 |
at:TRACE2 put:7; "/ LOG_DEBUG: informational
|
|
105 |
at:TRACE3 put:7; "/ LOG_DEBUG: informational
|
|
106 |
at:ENTER put:7; "/ LOG_DEBUG: informational
|
|
107 |
at:LEAVE put:7. "/ LOG_DEBUG: informational
|
|
108 |
|
|
109 |
"/ Facilities
|
|
110 |
LOG_KERN := (0<<3). "/ kernel messages
|
|
111 |
LOG_USER := (1<<3). "/ random user-level messages
|
|
112 |
LOG_MAIL := (2<<3). "/ mail system
|
|
113 |
LOG_DAEMON := (3<<3). "/ system daemons
|
|
114 |
LOG_AUTH := (4<<3). "/ security/authorization messages
|
|
115 |
LOG_SYSLOG := (5<<3). "/ messages generated internally by syslogd
|
|
116 |
LOG_LPR := (6<<3). "/ line printer subsystem
|
|
117 |
LOG_NEWS := (7<<3). "/ network news subsystem
|
|
118 |
LOG_UUCP := (8<<3). "/ UUCP subsystem
|
|
119 |
LOG_CRON := (9<<3). "/ clock daemon
|
|
120 |
LOG_AUTHPRIV := (10<<3). "/ security/authorization messages (private)
|
|
121 |
LOG_FTP := (11<<3). "/ ftp daemon
|
|
122 |
|
|
123 |
"/ other codes through 15 reserved for system use
|
|
124 |
LOG_LOCAL0 := (16<<3). "/ reserved for local use
|
|
125 |
LOG_LOCAL1 := (17<<3). "/ reserved for local use
|
|
126 |
LOG_LOCAL2 := (18<<3). "/ reserved for local use
|
|
127 |
LOG_LOCAL3 := (19<<3). "/ reserved for local use
|
|
128 |
LOG_LOCAL4 := (20<<3). "/ reserved for local use
|
|
129 |
LOG_LOCAL5 := (21<<3). "/ reserved for local use
|
|
130 |
LOG_LOCAL6 := (22<<3). "/ reserved for local use
|
|
131 |
LOG_LOCAL7 := (23<<3). "/ reserved for local use
|
|
132 |
|
|
133 |
"/ Options
|
|
134 |
LOG_PID := 16r01. "/ log the pid with each message
|
|
135 |
LOG_CONS := 16r02. "/ log on the console if errors in sending
|
|
136 |
LOG_ODELAY := 16r04. "/ delay open until first syslog() (default)
|
|
137 |
LOG_NDELAY := 16r08. "/ don't delay open
|
|
138 |
LOG_PERROR := 16r20. "/ log to stderr as well
|
|
139 |
|
|
140 |
DefaultSyslogFacility := LOG_LOCAL4.
|
23220
|
141 |
DefaultSyslogFacilityString := 'local4'.
|
|
142 |
PriorityToStringMapping := #('emerg' 'alert' 'crit' 'err' 'warning' 'notice' 'info' 'debug').
|
23464
|
143 |
|
|
144 |
"/ no access to FFI / ObjectFileLoader here; do this lazy, when actually needed
|
|
145 |
UseCommand := nil.
|
23139
|
146 |
|
|
147 |
"Created: / 24-02-2018 / 15:37:22 / stefan"
|
23226
|
148 |
"Modified: / 22-07-2018 / 15:21:01 / Stefan Vogel"
|
23464
|
149 |
"Modified: / 24-10-2018 / 19:38:10 / Claus Gittinger"
|
23139
|
150 |
! !
|
|
151 |
|
|
152 |
!UnixSyslogInterface class methodsFor:'accessing'!
|
|
153 |
|
|
154 |
defaultSyslogFacility
|
|
155 |
^ DefaultSyslogFacility
|
|
156 |
!
|
|
157 |
|
|
158 |
defaultSyslogFacility:anInteger
|
|
159 |
"set the default facility of syslog (e.g. self LOG_LOCAL0).
|
|
160 |
This is different from the Logger facility arg."
|
|
161 |
|
|
162 |
DefaultSyslogFacility := anInteger.
|
|
163 |
|
|
164 |
"Modified (comment): / 28-06-2018 / 11:37:16 / Stefan Vogel"
|
|
165 |
! !
|
|
166 |
|
|
167 |
!UnixSyslogInterface class methodsFor:'accessing-facilities'!
|
|
168 |
|
|
169 |
LOG_AUTH
|
|
170 |
^ LOG_AUTH
|
|
171 |
!
|
|
172 |
|
|
173 |
LOG_AUTHPRIV
|
|
174 |
^ LOG_AUTHPRIV
|
|
175 |
!
|
|
176 |
|
|
177 |
LOG_CRON
|
|
178 |
^ LOG_CRON
|
|
179 |
!
|
|
180 |
|
|
181 |
LOG_DAEMON
|
|
182 |
^ LOG_DAEMON
|
|
183 |
!
|
|
184 |
|
|
185 |
LOG_FTP
|
|
186 |
^ LOG_FTP
|
|
187 |
!
|
|
188 |
|
|
189 |
LOG_KERN
|
|
190 |
^ LOG_KERN
|
|
191 |
!
|
|
192 |
|
|
193 |
LOG_LOCAL0
|
|
194 |
^ LOG_LOCAL0
|
|
195 |
!
|
|
196 |
|
|
197 |
LOG_LOCAL1
|
|
198 |
^ LOG_LOCAL1
|
|
199 |
!
|
|
200 |
|
|
201 |
LOG_LOCAL2
|
|
202 |
^ LOG_LOCAL2
|
|
203 |
!
|
|
204 |
|
|
205 |
LOG_LOCAL3
|
|
206 |
^ LOG_LOCAL3
|
|
207 |
!
|
|
208 |
|
|
209 |
LOG_LOCAL4
|
|
210 |
^ LOG_LOCAL4
|
|
211 |
!
|
|
212 |
|
|
213 |
LOG_LOCAL5
|
|
214 |
^ LOG_LOCAL5
|
|
215 |
!
|
|
216 |
|
|
217 |
LOG_LOCAL6
|
|
218 |
^ LOG_LOCAL6
|
|
219 |
!
|
|
220 |
|
|
221 |
LOG_LOCAL7
|
|
222 |
^ LOG_LOCAL7
|
|
223 |
!
|
|
224 |
|
|
225 |
LOG_LPR
|
|
226 |
^ LOG_LPR
|
|
227 |
!
|
|
228 |
|
|
229 |
LOG_MAIL
|
|
230 |
^ LOG_MAIL
|
|
231 |
!
|
|
232 |
|
|
233 |
LOG_NEWS
|
|
234 |
^ LOG_NEWS
|
|
235 |
!
|
|
236 |
|
|
237 |
LOG_SYSLOG
|
|
238 |
^ LOG_SYSLOG
|
|
239 |
!
|
|
240 |
|
|
241 |
LOG_USER
|
|
242 |
^ LOG_USER
|
|
243 |
!
|
|
244 |
|
|
245 |
LOG_UUCP
|
|
246 |
^ LOG_UUCP
|
|
247 |
! !
|
|
248 |
|
|
249 |
!UnixSyslogInterface class methodsFor:'accessing-options'!
|
|
250 |
|
|
251 |
LOG_CONS
|
|
252 |
^ LOG_CONS
|
|
253 |
!
|
|
254 |
|
|
255 |
LOG_NDELAY
|
|
256 |
^ LOG_NDELAY
|
|
257 |
!
|
|
258 |
|
|
259 |
LOG_ODELAY
|
|
260 |
^ LOG_ODELAY
|
|
261 |
!
|
|
262 |
|
|
263 |
LOG_PERROR
|
|
264 |
^ LOG_PERROR
|
|
265 |
!
|
|
266 |
|
|
267 |
LOG_PID
|
|
268 |
^ LOG_PID
|
|
269 |
! !
|
|
270 |
|
|
271 |
!UnixSyslogInterface class methodsFor:'accessing-priorities'!
|
|
272 |
|
|
273 |
LOG_ALERT
|
|
274 |
^ LOG_ALERT
|
|
275 |
!
|
|
276 |
|
|
277 |
LOG_CRIT
|
|
278 |
^ LOG_CRIT
|
|
279 |
!
|
|
280 |
|
|
281 |
LOG_DEBUG
|
|
282 |
^ LOG_DEBUG
|
|
283 |
!
|
|
284 |
|
|
285 |
LOG_EMERG
|
|
286 |
^ LOG_EMERG
|
|
287 |
!
|
|
288 |
|
|
289 |
LOG_ERR
|
|
290 |
^ LOG_ERR
|
|
291 |
!
|
|
292 |
|
|
293 |
LOG_INFO
|
|
294 |
^ LOG_INFO
|
|
295 |
!
|
|
296 |
|
|
297 |
LOG_NOTICE
|
|
298 |
^ LOG_NOTICE
|
|
299 |
!
|
|
300 |
|
|
301 |
LOG_WARNING
|
|
302 |
^ LOG_WARNING
|
|
303 |
! !
|
|
304 |
|
|
305 |
!UnixSyslogInterface class methodsFor:'api'!
|
|
306 |
|
|
307 |
apiSyslog:priority format:format message:message
|
|
308 |
<cdecl: int 'syslog' (int char* char*) >
|
|
309 |
^ self primitiveFailed.
|
|
310 |
|
|
311 |
"
|
|
312 |
self openlog:'stx2' option:0 facility:self LOG_LOCAL7.
|
|
313 |
self syslog:self LOG_WARNING message:'stx %% demo'.
|
|
314 |
self closelog.
|
|
315 |
"
|
|
316 |
|
|
317 |
"Created: / 27-06-2018 / 23:11:57 / Stefan Vogel"
|
|
318 |
!
|
|
319 |
|
|
320 |
closelog
|
|
321 |
<cdecl: int 'closelog' (void) >
|
|
322 |
^ self primitiveFailed.
|
|
323 |
|
|
324 |
"Created: / 24-02-2018 / 13:35:20 / stefan"
|
|
325 |
"Modified: / 24-02-2018 / 22:54:55 / stefan"
|
|
326 |
!
|
|
327 |
|
|
328 |
libraryName
|
|
329 |
^ 'libc.so.6'
|
|
330 |
|
|
331 |
"Created: / 24-02-2018 / 13:39:49 / stefan"
|
23226
|
332 |
"Modified: / 22-07-2018 / 15:22:49 / Stefan Vogel"
|
23139
|
333 |
!
|
|
334 |
|
|
335 |
openlog:ident option:option facility:facility
|
|
336 |
<cdecl: int 'openlog' (char* int int) >
|
|
337 |
^ self primitiveFailed.
|
|
338 |
|
|
339 |
"
|
|
340 |
self new openlog:'stx' option:0 facility:0.
|
|
341 |
self new closelog.
|
|
342 |
"
|
|
343 |
|
|
344 |
"Created: / 24-02-2018 / 13:27:11 / stefan"
|
|
345 |
"Modified: / 24-02-2018 / 22:55:01 / stefan"
|
|
346 |
! !
|
|
347 |
|
|
348 |
!UnixSyslogInterface class methodsFor:'logging'!
|
|
349 |
|
23147
|
350 |
syslog:priority message:message arguments:argArray
|
|
351 |
self apiSyslog:priority format:'%s' message:(message bindWithArguments:argArray).
|
|
352 |
|
|
353 |
|
|
354 |
"
|
|
355 |
self openlog:'stx' option:0 facility:self LOG_USER.
|
|
356 |
self syslog:self LOG_WARNING message:'%1 demo (%2%)' arguments:#('stx' 16).
|
|
357 |
self closelog.
|
|
358 |
"
|
|
359 |
|
|
360 |
"Created: / 24-02-2018 / 23:16:05 / stefan"
|
|
361 |
"Modified: / 27-06-2018 / 23:13:23 / Stefan Vogel"
|
|
362 |
! !
|
|
363 |
|
|
364 |
!UnixSyslogInterface class methodsFor:'private'!
|
|
365 |
|
23139
|
366 |
basicLog:message severity:severity facility:facility originator:originator attachment:attachment
|
|
367 |
|priority messageAsSent|
|
|
368 |
|
|
369 |
priority := PriorityMapping at:severity ifAbsent:5.
|
|
370 |
messageAsSent :=
|
23151
|
371 |
'%1%2%3: %4'
|
23139
|
372 |
bindWith:(facility ? 'STX')
|
|
373 |
"/ with:'' "/ severity name
|
|
374 |
"/ with:'' "/ (Timestamp now printStringFormat:(self timestampFormat))
|
23151
|
375 |
with:(originator notEmptyOrNil ifTrue:'+' ifFalse:[''])
|
23139
|
376 |
with:originator
|
|
377 |
with:message.
|
|
378 |
|
|
379 |
messageAsSent := messageAsSent string. "take care of Texts"
|
|
380 |
|
23464
|
381 |
UseCommand isNil ifTrue:[
|
|
382 |
"/ determine if a shell-command should be used, or if an FFI call can be used
|
|
383 |
"/ if we have FFI support, we do not have to use the command.
|
|
384 |
"/ No reference to ObjectFileLoader (in different package) here.
|
|
385 |
"/ otherwise, standalone programs without libcomp will no longer work
|
|
386 |
"/ (especially tests in stc/tests)
|
|
387 |
UseCommand := [
|
|
388 |
self closelog. "/ an FFI-call
|
|
389 |
false.
|
|
390 |
] on:(Error "PrimitiveFailure, ObjectFileLoader::ObjectFileLoadError") do:[
|
|
391 |
true.
|
|
392 |
].
|
|
393 |
].
|
|
394 |
|
23220
|
395 |
UseCommand ifTrue:[
|
|
396 |
"if we do not support FFI, use a comman interface"
|
|
397 |
OperatingSystem
|
23331
|
398 |
"/ --id doesn't work with RedHat 7.0
|
|
399 |
"/ executeCommand:('/usr/bin/logger --id=%1 -p %2.%3'
|
|
400 |
executeCommand:('/usr/bin/logger -p %2.%3'
|
23220
|
401 |
bindWith:OperatingSystem getProcessId
|
|
402 |
with:DefaultSyslogFacilityString with:(PriorityToStringMapping at:priority+1))
|
|
403 |
inputFrom:messageAsSent readStream
|
|
404 |
outputTo:nil
|
|
405 |
errorTo:Transcript.
|
|
406 |
^ self.
|
|
407 |
].
|
|
408 |
|
23326
|
409 |
messageAsSent containsNon7BitAscii ifTrue:[
|
|
410 |
messageAsSent := OperatingSystem encodePath:messageAsSent.
|
|
411 |
].
|
23139
|
412 |
self apiSyslog:(priority bitOr:DefaultSyslogFacility) format:'%s' message:messageAsSent.
|
|
413 |
|
|
414 |
"
|
|
415 |
self warning:'%1 warning demo » (%2%)' with:'stx' with:16.
|
|
416 |
self fatal:'%1 fatal demo (%2%)' with:'stx' with:16.
|
|
417 |
self closelog.
|
|
418 |
"
|
|
419 |
|
|
420 |
"Created: / 28-06-2018 / 11:08:04 / Stefan Vogel"
|
23331
|
421 |
"Modified: / 12-09-2018 / 12:31:13 / Stefan Vogel"
|
23464
|
422 |
"Modified: / 24-10-2018 / 19:39:05 / Claus Gittinger"
|
23147
|
423 |
! !
|
23139
|
424 |
|
23147
|
425 |
!UnixSyslogInterface class methodsFor:'queries'!
|
23139
|
426 |
|
23147
|
427 |
canLog
|
|
428 |
^ true
|
23139
|
429 |
|
23147
|
430 |
"Created: / 28-06-2018 / 11:55:46 / Stefan Vogel"
|
23139
|
431 |
! !
|
|
432 |
|
|
433 |
!UnixSyslogInterface class methodsFor:'documentation'!
|
|
434 |
|
|
435 |
version
|
|
436 |
^ '$Header$'
|
|
437 |
!
|
|
438 |
|
|
439 |
version_CVS
|
|
440 |
^ '$Header$'
|
|
441 |
! !
|
|
442 |
|
|
443 |
|
|
444 |
UnixSyslogInterface initialize!
|