37 only in accordance with the terms of that license and with the |
37 only in accordance with the terms of that license and with the |
38 inclusion of the above copyright notice. This software may not |
38 inclusion of the above copyright notice. This software may not |
39 be provided or otherwise made available to, or used by, any |
39 be provided or otherwise made available to, or used by, any |
40 other person. No title to or ownership of the software is |
40 other person. No title to or ownership of the software is |
41 hereby transferred. |
41 hereby transferred. |
|
42 " |
|
43 ! |
|
44 |
|
45 documentation |
|
46 " |
|
47 A very simple logger for Smalltalk/X. This one is always present. |
|
48 All `Transcript show: 'Processor [info]: xxx' should be rewritten |
|
49 using Logger. |
|
50 |
|
51 Usage: |
|
52 |
|
53 Logger info: 'Hello worlds'. |
|
54 |
|
55 For more examples, see #examples. |
|
56 |
|
57 [author:] |
|
58 Jan Vrany <jan.vrany@fit.cvut.cz> |
|
59 |
|
60 [instance variables:] |
|
61 |
|
62 [class variables:] |
|
63 |
|
64 [see also:] |
|
65 Loggia logging framrwork (stx:goodies/loggia) |
|
66 |
|
67 " |
|
68 ! |
|
69 |
|
70 examples |
|
71 " |
|
72 Simple logging (make sure logging threshold is lower or equal then |
|
73 Logger severityDEBUG, see #loggingThreshold:) |
|
74 [exBegin] |
|
75 Logger debug: 'Hello world!!' |
|
76 [exEnd] |
|
77 |
|
78 You may use #<severity>:with:with: utility to format log message: |
|
79 [exBegin] |
|
80 | hostname port | |
|
81 |
|
82 hostname := 'www.google.com'. |
|
83 port := 80. |
|
84 Logger error: 'Cannot connect to %1 port %2' with: hostname with: port |
|
85 [exEnd] |
|
86 |
|
87 When a log message is costly to construct, you may pass a block returning |
|
88 the message instead of string. Then the log message creation os deferred until |
|
89 really needed (i.e., if the severity is not logged, block is not evaluated. |
|
90 Useful for trace messages (severities DEBUG and TRACE?): |
|
91 [exBegin] |
|
92 | hostname port | |
|
93 |
|
94 hostname := 'www.google.com'. |
|
95 Logger trace: [ 'Connecting to %1' bindWith: (IPSocketAddress hostName:hostname) address ] |
|
96 [exEnd] |
|
97 |
42 " |
98 " |
43 ! ! |
99 ! ! |
44 |
100 |
45 !MiniLogger class methodsFor:'initialization'! |
101 !MiniLogger class methodsFor:'initialization'! |
46 |
102 |
196 self error:'Invalid severity. Use of Logger severityXXX'. |
252 self error:'Invalid severity. Use of Logger severityXXX'. |
197 ^ self. |
253 ^ self. |
198 ]. |
254 ]. |
199 Threshold := severity |
255 Threshold := severity |
200 |
256 |
|
257 " |
|
258 Logger loggingThreshold: Logger severityALL. |
|
259 Logger loggingThreshold: Logger severityINFO. |
|
260 " |
|
261 |
201 "Created: / 13-08-2014 / 14:34:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
262 "Created: / 13-08-2014 / 14:34:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
202 "Modified: / 26-08-2014 / 08:23:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
263 "Modified: / 26-08-2014 / 08:23:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
264 "Modified (comment): / 09-10-2014 / 09:35:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
203 ! ! |
265 ! ! |
204 |
266 |
205 !MiniLogger class methodsFor:'logging'! |
267 !MiniLogger class methodsFor:'logging'! |
206 |
268 |
207 log: message |
269 log: message |
252 ! |
314 ! |
253 |
315 |
254 log: message severity: severity facility: facility originator: originator attachment: attachment |
316 log: message severity: severity facility: facility originator: originator attachment: attachment |
255 "Pricipal logging method. This mimics VM __stxLog__()" |
317 "Pricipal logging method. This mimics VM __stxLog__()" |
256 |
318 |
257 | severityXlated | |
319 | severityXlated messageXlated | |
258 |
320 |
259 severityXlated := severity. |
321 severityXlated := severity. |
260 |
322 |
261 "/ Be backward compatible, allow for symbolic severities |
323 "/ Be backward compatible, allow for symbolic severities |
262 "/ but when encountered, issue a warning... |
324 "/ but when encountered, issue a warning... |
296 self log: 'caller is ', caller printString severity: INFO facility: 'STX' originator: self. |
358 self log: 'caller is ', caller printString severity: INFO facility: 'STX' originator: self. |
297 severityXlated := INFO. |
359 severityXlated := INFO. |
298 ]. |
360 ]. |
299 |
361 |
300 severityXlated value < Threshold value ifTrue:[ ^ self ]. |
362 severityXlated value < Threshold value ifTrue:[ ^ self ]. |
301 |
363 messageXlated := message value. |
302 self log: message severity: severityXlated facility: facility originator: originator attachment: attachment on:Stderr. |
364 |
|
365 self log: messageXlated severity: severityXlated facility: facility originator: originator attachment: attachment on:Stderr. |
303 (Transcript isView) ifTrue:[ |
366 (Transcript isView) ifTrue:[ |
304 self log: message severity: severityXlated facility: facility originator: originator attachment: attachment on:Transcript |
367 self log: messageXlated severity: severityXlated facility: facility originator: originator attachment: attachment on:Transcript |
305 ]. |
368 ]. |
306 |
369 |
307 " |
370 " |
308 Logger log:'test message' severity: #debug facility: 'TEST' |
371 Logger log:'test message' severity: #debug facility: 'TEST' |
309 " |
372 " |
310 |
373 |
311 "Created: / 14-09-2011 / 21:18:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
374 "Created: / 14-09-2011 / 21:18:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
312 "Modified: / 13-08-2014 / 14:38:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
375 "Modified: / 09-10-2014 / 09:22:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
313 "Modified (format): / 26-08-2014 / 09:37:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
314 ! |
376 ! |
315 |
377 |
316 log: message severity: severity originator: originator |
378 log: message severity: severity originator: originator |
317 self log: message severity: severity facility: (self facilityOf: originator) originator: originator |
379 self log: message severity: severity facility: (self facilityOf: originator) originator: originator |
318 |
380 |
588 ! ! |
650 ! ! |
589 |
651 |
590 !MiniLogger class methodsFor:'documentation'! |
652 !MiniLogger class methodsFor:'documentation'! |
591 |
653 |
592 version |
654 version |
593 ^ '$Header: /cvs/stx/stx/libbasic/MiniLogger.st,v 1.8 2014-09-25 09:04:32 vrany Exp $' |
655 ^ '$Header: /cvs/stx/stx/libbasic/MiniLogger.st,v 1.9 2014-10-09 08:47:11 vrany Exp $' |
594 ! |
656 ! |
595 |
657 |
596 version_CVS |
658 version_CVS |
597 ^ '$Header: /cvs/stx/stx/libbasic/MiniLogger.st,v 1.8 2014-09-25 09:04:32 vrany Exp $' |
659 ^ '$Header: /cvs/stx/stx/libbasic/MiniLogger.st,v 1.9 2014-10-09 08:47:11 vrany Exp $' |
598 ! |
660 ! |
599 |
661 |
600 version_HG |
662 version_HG |
601 |
663 |
602 ^ '$Changeset: <not expanded> $' |
664 ^ '$Changeset: <not expanded> $' |
603 ! |
665 ! |
604 |
666 |
605 version_SVN |
667 version_SVN |
606 ^ '$Id: MiniLogger.st,v 1.8 2014-09-25 09:04:32 vrany Exp $' |
668 ^ '$Id: MiniLogger.st,v 1.9 2014-10-09 08:47:11 vrany Exp $' |
607 ! ! |
669 ! ! |
608 |
670 |
609 |
671 |
610 MiniLogger initialize! |
672 MiniLogger initialize! |