#FEATURE by stefan
authorStefan Vogel <sv@exept.de>
Thu, 19 Jul 2018 12:23:48 +0200
changeset 23220 6b814a812eb4
parent 23219 a043f994d4bc
child 23221 637fe0932dff
#FEATURE by stefan class: UnixSyslogInterface class definition class: UnixSyslogInterface class changed: #basicLog:severity:facility:originator:attachment: #initialize Support for systems not having FFI: use /usr/bin/logger command interface (SMC)
UnixSyslogInterface.st
--- a/UnixSyslogInterface.st	Thu Jul 19 12:21:52 2018 +0200
+++ b/UnixSyslogInterface.st	Thu Jul 19 12:23:48 2018 +0200
@@ -22,7 +22,8 @@
 		LOG_SYSLOG LOG_LPR LOG_NEWS LOG_UUCP LOG_CRON LOG_AUTHPRIV
 		LOG_FTP LOG_LOCAL0 LOG_LOCAL1 LOG_LOCAL2 LOG_LOCAL3 LOG_LOCAL4
 		LOG_LOCAL5 LOG_LOCAL6 LOG_LOCAL7 LOG_PID LOG_CONS LOG_ODELAY
-		LOG_NDELAY LOG_PERROR PriorityMapping DefaultSyslogFacility'
+		LOG_NDELAY LOG_PERROR PriorityMapping DefaultSyslogFacility
+		DefaultSyslogFacilityString PriorityToStringMapping UseCommand'
 	poolDictionaries:''
 	category:'System-Debugging-Support'
 !
@@ -137,9 +138,18 @@
     LOG_PERROR := 16r20.    "/ log to stderr as well
 
     DefaultSyslogFacility := LOG_LOCAL4.
+    DefaultSyslogFacilityString := 'local4'.
+    PriorityToStringMapping := #('emerg' 'alert' 'crit' 'err' 'warning' 'notice' 'info' 'debug').
+    UseCommand := [
+                      "if we have FFI support, we do not have to use the command"  
+                      self closelog.
+                      false.
+                  ] on:PrimitiveFailure do:[
+                      true.
+                  ].
 
     "Created: / 24-02-2018 / 15:37:22 / stefan"
-    "Modified: / 28-06-2018 / 11:32:10 / Stefan Vogel"
+    "Modified (format): / 19-07-2018 / 11:24:04 / Stefan Vogel"
 ! !
 
 !UnixSyslogInterface class methodsFor:'accessing'!
@@ -373,6 +383,18 @@
         messageAsSent := OperatingSystem encodePath:messageAsSent.
     ].
 
+    UseCommand ifTrue:[
+        "if we do not support FFI, use a comman interface"
+        OperatingSystem 
+            executeCommand:('/usr/bin/logger --id=%1 -p %2.%3' 
+                             bindWith:OperatingSystem getProcessId 
+                                 with:DefaultSyslogFacilityString with:(PriorityToStringMapping at:priority+1))
+            inputFrom:messageAsSent readStream
+            outputTo:nil
+            errorTo:Transcript.
+        ^ self.
+    ].
+
     self apiSyslog:(priority bitOr:DefaultSyslogFacility) format:'%s' message:messageAsSent.
 
     "
@@ -382,7 +404,7 @@
     "
 
     "Created: / 28-06-2018 / 11:08:04 / Stefan Vogel"
-    "Modified: / 28-06-2018 / 15:01:25 / Stefan Vogel"
+    "Modified (format): / 19-07-2018 / 11:37:21 / Stefan Vogel"
 ! !
 
 !UnixSyslogInterface class methodsFor:'queries'!