MiniLogger.st
changeset 20529 e026fd505d16
parent 20509 0baa8cacf896
child 20579 9add81aadb7a
child 20610 37a18361b46b
--- a/MiniLogger.st	Tue Oct 04 12:57:34 2016 +0200
+++ b/MiniLogger.st	Wed Oct 05 13:59:21 2016 +0200
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 2012-2014 by Jan Vrany & eXept Software AG
               All Rights Reserved
@@ -864,15 +862,15 @@
 log: message severity: severity facility: facilityArg originator: originator attachment: attachment on:aStream
     "Pricipal logging method. This mimics VM __stxLog__()"
 
-    | facility severityName messageProperlyEncoded words|
+    |facility severityName messageProperlyEncoded words messageAsSent|
 
     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:[ 
+    "/ we have to recode the message using locale-specific encoding
+    (message isWideString and:[ aStream isExternalStream ]) ifTrue:[
         OperatingSystem isMSWINDOWSlike ifTrue:[
             messageProperlyEncoded := message utf8Encoded.
         ] ifFalse:[
@@ -880,7 +878,7 @@
         ]
     ].
     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.
@@ -897,18 +895,20 @@
             messageProperlyEncoded := (messageProperlyEncoded copyFrom:2) withoutSeparators.
         ].
     ].
-    
-    "/ Timestamp now printOn:aStream format:'%(year)-%(mon)-%(day) %h:%m:%s.%i'.
-    "/ aStream space.
-    aStream 
-        nextPutLine:
-            (self logFormat
+    messageAsSent := (self logFormat
                 bindWith:(facility ? 'STX')
                 with:severityName
                 with:(Timestamp now printStringFormat:(self timestampFormat))
                 with:originator printString
-                with:messageProperlyEncoded)
-                
+                with:messageProperlyEncoded).
+    aStream isView ifFalse:[
+        messageAsSent := messageAsSent string utf8Encoded
+    ].
+
+    "/ Timestamp now printOn:aStream format:'%(year)-%(mon)-%(day) %h:%m:%s.%i'.
+    "/ aStream space.
+    aStream nextPutLine: messageAsSent
+
     "
      'hello' infoPrintCR.