MiniLogger.st
branchjv
changeset 20578 39641ba8d6e0
parent 20220 874c664d2cbd
parent 20492 862c7e4b0964
child 20579 9add81aadb7a
--- a/MiniLogger.st	Tue Sep 20 11:37:33 2016 +0100
+++ b/MiniLogger.st	Mon Oct 03 12:44:41 2016 +0100
@@ -15,8 +15,8 @@
 
 Object subclass:#MiniLogger
 	instanceVariableNames:''
-	classVariableNames:'ALL ENTER LEAVE TRACE3 TRACE2 TRACE1 TRACE0 TRACE DEBUG INFO WARN
-		ERROR FATAL NONE Severities Threshold Instance'
+	classVariableNames:'ALL DEBUG ENTER ERROR FATAL INFO Instance LEAVE NONE Severities
+		TRACE TRACE0 TRACE1 TRACE2 TRACE3 Threshold WARN WARNING'
 	poolDictionaries:''
 	category:'System-Debugging-Support'
 !
@@ -114,11 +114,12 @@
     DEBUG := Severity new initializeWithName:#debug value:60.
     INFO := Severity new initializeWithName:#info value:70.
     WARN := Severity new initializeWithName:#warn value:88.
+    WARNING := Severity new initializeWithName:#warning value:88.
     ERROR := Severity new initializeWithName:#error value:99.
     FATAL := Severity new initializeWithName:#fatal value:100.
     NONE := Severity new initializeWithName:#none value:65535.
 
-    Severities := Array new:12.
+    Severities := Array new:13.
     Severities at:1 put:ENTER.
     Severities at:2 put:LEAVE.
     Severities at:3 put:TRACE3.
@@ -129,8 +130,9 @@
     Severities at:8 put:DEBUG.
     Severities at:9 put:INFO.
     Severities at:10 put:WARN.
-    Severities at:11 put:ERROR.
-    Severities at:12 put:FATAL.
+    Severities at:11 put:WARNING.
+    Severities at:12 put:ERROR.
+    Severities at:13 put:FATAL.
 
     Threshold := InfoPrinting ifTrue:[INFO] ifFalse:[WARN].
 
@@ -256,6 +258,7 @@
     "
     Logger loggingThreshold: Logger severityALL.
     Logger loggingThreshold: Logger severityINFO.
+    Logger loggingThreshold: Logger severityNONE.
     "
 
     "Created: / 13-08-2014 / 14:34:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -402,6 +405,13 @@
     "Modified: / 02-12-2014 / 10:54:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+debug: format with: arg1 with: arg2 with:arg3
+    DEBUG value < Threshold value ifTrue:[ ^ self ].
+    self log: (format bindWith: arg1 with: arg2 with:arg3) severity: DEBUG originator: thisContext sender receiver
+
+    "Modified: / 02-12-2014 / 10:54:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 enter: message
     ENTER value < Threshold value ifTrue:[ ^ self ].
     self log: message severity: ENTER originator: thisContext sender receiver
@@ -423,6 +433,13 @@
     "Modified: / 02-12-2014 / 10:54:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+enter: format with: arg1 with: arg2 with:arg3
+    ENTER value < Threshold value ifTrue:[ ^ self ].
+    self log: (format bindWith: arg1 with: arg2 with:arg3) severity: ENTER originator: thisContext sender receiver
+
+    "Modified: / 02-12-2014 / 10:54:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 error: message
     ERROR value < Threshold value ifTrue:[ ^ self ].
     self log: message severity: ERROR originator: thisContext sender receiver
@@ -444,6 +461,13 @@
     "Modified: / 02-12-2014 / 10:54:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+error: format with: arg1 with: arg2 with:arg3
+    ERROR value < Threshold value ifTrue:[ ^ self ].
+    self log: (format bindWith: arg1 with: arg2 with:arg3) severity: ERROR originator: thisContext sender receiver
+
+    "Modified: / 02-12-2014 / 10:54:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 fatal: message
     FATAL value < Threshold value ifTrue:[ ^ self ].
     self log: message severity: FATAL originator: thisContext sender receiver
@@ -465,6 +489,13 @@
     "Modified: / 02-12-2014 / 10:54:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+fatal: format with: arg1 with: arg2 with:arg3
+    FATAL value < Threshold value ifTrue:[ ^ self ].
+    self log: (format bindWith: arg1 with: arg2 with:arg3) severity: FATAL originator: thisContext sender receiver
+
+    "Modified: / 02-12-2014 / 10:54:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 info: message
     INFO value < Threshold value ifTrue:[ ^ self ].
     self log: message severity: INFO originator: thisContext sender receiver
@@ -486,6 +517,13 @@
     "Modified: / 02-12-2014 / 10:55:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+info: format with: arg1 with: arg2 with:arg3
+    INFO value < Threshold value ifTrue:[ ^ self ].
+    self log: (format bindWith: arg1 with: arg2 with:arg3) severity: INFO originator: thisContext sender receiver
+
+    "Modified: / 02-12-2014 / 10:55:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 leave: message
     LEAVE value < Threshold value ifTrue:[ ^ self ].
     self log: message severity: LEAVE originator: thisContext sender receiver
@@ -507,6 +545,13 @@
     "Modified: / 02-12-2014 / 10:55:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+leave: format with: arg1 with: arg2 with:arg3
+    LEAVE value < Threshold value ifTrue:[ ^ self ].
+    self log: (format bindWith: arg1 with: arg2 with:arg3) severity: LEAVE originator: thisContext sender receiver
+
+    "Modified: / 02-12-2014 / 10:55:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 trace0: message
     TRACE0 value < Threshold value ifTrue:[ ^ self ].
     self log: message severity: TRACE0 originator: thisContext sender receiver
@@ -528,6 +573,13 @@
     "Modified: / 02-12-2014 / 10:55:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+trace0: format with: arg1 with: arg2 with:arg3
+    TRACE0 value < Threshold value ifTrue:[ ^ self ].
+    self log: (format bindWith: arg1 with: arg2 with:arg3) severity: TRACE0 originator: thisContext sender receiver
+
+    "Modified: / 02-12-2014 / 10:55:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 trace1: message
     TRACE1 value < Threshold value ifTrue:[ ^ self ].
     self log: message severity: TRACE1 originator: thisContext sender receiver
@@ -549,6 +601,13 @@
     "Modified: / 02-12-2014 / 10:55:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+trace1: format with: arg1 with: arg2 with:arg3
+    TRACE1 value < Threshold value ifTrue:[ ^ self ].
+    self log: (format bindWith: arg1 with: arg2 with:arg3) severity: TRACE1 originator: thisContext sender receiver
+
+    "Modified: / 02-12-2014 / 10:55:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 trace2: message
     TRACE2 value < Threshold value ifTrue:[ ^ self ].
     self log: message severity: TRACE2 originator: thisContext sender receiver
@@ -570,6 +629,13 @@
     "Modified: / 02-12-2014 / 10:55:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+trace2: format with: arg1 with: arg2 with:arg3
+    TRACE2 value < Threshold value ifTrue:[ ^ self ].
+    self log: (format bindWith: arg1 with: arg2 with:arg3) severity: TRACE2 originator: thisContext sender receiver
+
+    "Modified: / 02-12-2014 / 10:55:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 trace3: message
     TRACE3 value < Threshold value ifTrue:[ ^ self ].
     self log: message severity: TRACE3 originator: thisContext sender receiver
@@ -591,6 +657,13 @@
     "Modified: / 02-12-2014 / 10:56:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+trace3: format with: arg1 with: arg2 with:arg3
+    TRACE3 value < Threshold value ifTrue:[ ^ self ].
+    self log: (format bindWith: arg1 with: arg2 with:arg3) severity: TRACE3 originator: thisContext sender receiver
+
+    "Modified: / 02-12-2014 / 10:56:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 trace: message
     TRACE value < Threshold value ifTrue:[ ^ self ].
     self log: message severity: TRACE originator: thisContext sender receiver
@@ -612,6 +685,13 @@
     "Modified: / 02-12-2014 / 10:56:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+trace: format with: arg1 with: arg2 with:arg3
+    TRACE value < Threshold value ifTrue:[ ^ self ].
+    self log: (format bindWith: arg1 with: arg2 with:arg3) severity: TRACE originator: thisContext sender receiver
+
+    "Modified: / 02-12-2014 / 10:56:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 warning: message
     WARN value < Threshold value ifTrue:[ ^ self ].
     self log: message severity: WARN originator: thisContext sender receiver
@@ -626,11 +706,18 @@
     "Modified: / 02-12-2014 / 10:56:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-warning: format with: arg1 with: arg2
+warning:format with:arg1 with:arg2
     WARN value < Threshold value ifTrue:[ ^ self ].
     self log: (format bindWith: arg1 with: arg2) severity: WARN originator: thisContext sender receiver
 
     "Modified: / 02-12-2014 / 10:56:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+warning:format with:arg1 with:arg2 with:arg3
+    WARN value < Threshold value ifTrue:[ ^ self ].
+    self log: (format bindWith:arg1 with:arg2 with:arg3) severity: WARN originator: thisContext sender receiver
+
+    "Modified: / 02-12-2014 / 10:56:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !MiniLogger class methodsFor:'private'!
@@ -657,12 +744,15 @@
     "Created: / 15-09-2011 / 10:20:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-log: message severity: severity facility: facility originator: originator attachment: attachment on:aStream
+log: message severity: severity facility: facilityArg originator: originator attachment: attachment on:aStream
     "Pricipal logging method. This mimics VM __stxLog__()"
 
-    | messageProperlyEncoded |
+    | facility severityName messageProperlyEncoded words|
 
+    facility := facilityArg.
     messageProperlyEncoded := message.
+    severityName := severity name.
+    
     "/ If the message is Unicode 16/32 string and stream is external,
     "/ we have to recode the message using locale-specific encoding 
     (message isWideString and:[ aStream isExternalStream ]) ifTrue:[ 
@@ -672,26 +762,53 @@
             messageProperlyEncoded := OperatingSystem encodePath: message.
         ]
     ].
-
+    messageProperlyEncoded := messageProperlyEncoded withoutSeparators.
+    
+    "/ hack to allow calls from infPrint/errorPrint.
+    "/ if this is an oldStyle infoPrint or errorPrint, do not append another facility and severity
+    words := message asCollectionOfWords.
+    (words size > 2
+    and:[ words first isAlphaNumeric
+    and:[(words second startsWith:$[ )
+    and:[(words second endsWith:$] ) or:[(words second endsWith:']:' )]]]]) ifTrue:[
+        facility := words first.
+        severityName := words second copyButFirst.
+        severityName := severityName copyTo:(severityName indexOf:$])-1.
+        messageProperlyEncoded := messageProperlyEncoded copyFrom:(messageProperlyEncoded indexOf:$])+1.
+        messageProperlyEncoded := messageProperlyEncoded withoutSeparators.
+        (messageProperlyEncoded startsWith:$:) ifTrue:[
+            messageProperlyEncoded := (messageProperlyEncoded copyFrom:2) withoutSeparators.
+        ].
+    ].
+    
+    "/ Timestamp now printOn:aStream format:'%(year)-%(mon)-%(day) %h:%m:%s.%i'.
+    "/ aStream space.
     aStream
         nextPutAll: facility ? 'STX';
-        space;
-        nextPut:$[;
-        nextPutAll: severity name;
-        nextPut:$];
-        space.
+        nextPutAll:' [';
+        nextPutAll: severityName;
+        nextPutAll:']'.
 
-    aStream nextPut:$(.
+    aStream nextPutAll:' ('.
     Timestamp now printOn:aStream format:'%(year)-%(mon)-%(day) %h:%m:%s.%i'.
-    aStream nextPut:$).
-    aStream space.
-    originator class name printOn: aStream.
-    aStream nextPutAll: ': '.
+    aStream nextPutAll:'): '.
+
     aStream nextPutAll: messageProperlyEncoded.
     aStream cr.
 
     "
      Logger log:'test message' severity: #debug facility: 'TEST'
+     Logger log:'test message' severity: #info facility: 'TEST'
+     Logger log:'test message' severity: #warning facility: 'TEST'
+     Logger log:'test message' severity: #error facility: 'TEST'
+     'test message' infoPrintCR
+     'test message' errorPrintCR
+    "
+    "backward compatibility with infoPrint/errorPrint callers:
+     'foo [info] test message' infoPrintCR
+     'bar [error] test message' errorPrintCR
+     'foo [info]: test message' infoPrintCR
+     'bar [error]: test message' errorPrintCR
     "
 
     "Created: / 14-09-2011 / 21:18:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"