--- a/MiniLogger.st Wed Oct 08 15:09:01 2014 +0200
+++ b/MiniLogger.st Thu Oct 09 10:47:11 2014 +0200
@@ -40,6 +40,62 @@
other person. No title to or ownership of the software is
hereby transferred.
"
+!
+
+documentation
+"
+ A very simple logger for Smalltalk/X. This one is always present.
+ All `Transcript show: 'Processor [info]: xxx' should be rewritten
+ using Logger.
+
+ Usage:
+
+ Logger info: 'Hello worlds'.
+
+ For more examples, see #examples.
+
+ [author:]
+ Jan Vrany <jan.vrany@fit.cvut.cz>
+
+ [instance variables:]
+
+ [class variables:]
+
+ [see also:]
+ Loggia logging framrwork (stx:goodies/loggia)
+
+"
+!
+
+examples
+"
+ Simple logging (make sure logging threshold is lower or equal then
+ Logger severityDEBUG, see #loggingThreshold:)
+ [exBegin]
+ Logger debug: 'Hello world!!'
+ [exEnd]
+
+ You may use #<severity>:with:with: utility to format log message:
+ [exBegin]
+ | hostname port |
+
+ hostname := 'www.google.com'.
+ port := 80.
+ Logger error: 'Cannot connect to %1 port %2' with: hostname with: port
+ [exEnd]
+
+ When a log message is costly to construct, you may pass a block returning
+ the message instead of string. Then the log message creation os deferred until
+ really needed (i.e., if the severity is not logged, block is not evaluated.
+ Useful for trace messages (severities DEBUG and TRACE?):
+ [exBegin]
+ | hostname port |
+
+ hostname := 'www.google.com'.
+ Logger trace: [ 'Connecting to %1' bindWith: (IPSocketAddress hostName:hostname) address ]
+ [exEnd]
+
+"
! !
!MiniLogger class methodsFor:'initialization'!
@@ -198,8 +254,14 @@
].
Threshold := severity
+ "
+ Logger loggingThreshold: Logger severityALL.
+ Logger loggingThreshold: Logger severityINFO.
+ "
+
"Created: / 13-08-2014 / 14:34:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 26-08-2014 / 08:23:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified (comment): / 09-10-2014 / 09:35:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!MiniLogger class methodsFor:'logging'!
@@ -254,7 +316,7 @@
log: message severity: severity facility: facility originator: originator attachment: attachment
"Pricipal logging method. This mimics VM __stxLog__()"
- | severityXlated |
+ | severityXlated messageXlated |
severityXlated := severity.
@@ -298,10 +360,11 @@
].
severityXlated value < Threshold value ifTrue:[ ^ self ].
+ messageXlated := message value.
- self log: message severity: severityXlated facility: facility originator: originator attachment: attachment on:Stderr.
+ self log: messageXlated severity: severityXlated facility: facility originator: originator attachment: attachment on:Stderr.
(Transcript isView) ifTrue:[
- self log: message severity: severityXlated facility: facility originator: originator attachment: attachment on:Transcript
+ self log: messageXlated severity: severityXlated facility: facility originator: originator attachment: attachment on:Transcript
].
"
@@ -309,8 +372,7 @@
"
"Created: / 14-09-2011 / 21:18:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 13-08-2014 / 14:38:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified (format): / 26-08-2014 / 09:37:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 09-10-2014 / 09:22:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
log: message severity: severity originator: originator
@@ -590,11 +652,11 @@
!MiniLogger class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/MiniLogger.st,v 1.8 2014-09-25 09:04:32 vrany Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/MiniLogger.st,v 1.9 2014-10-09 08:47:11 vrany Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/MiniLogger.st,v 1.8 2014-09-25 09:04:32 vrany Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/MiniLogger.st,v 1.9 2014-10-09 08:47:11 vrany Exp $'
!
version_HG
@@ -603,7 +665,7 @@
!
version_SVN
- ^ '$Id: MiniLogger.st,v 1.8 2014-09-25 09:04:32 vrany Exp $'
+ ^ '$Id: MiniLogger.st,v 1.9 2014-10-09 08:47:11 vrany Exp $'
! !