Skip to content

Instantly share code, notes, and snippets.

@philippeback
Created September 22, 2014 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philippeback/078944c4f6a3bdfe582f to your computer and use it in GitHub Desktop.
Save philippeback/078944c4f6a3bdfe582f to your computer and use it in GitHub Desktop.
FFI from Pharo
'From Pharo3.0 of 18 March 2013 [Latest update: #30847] on 22 September 2014 at 7:18:21.92721 pm'!
Object subclass: #Syslog
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'FFI-Unix-Examples'!
!Syslog commentStamp: 'PhilippeBack 9/22/2014 19:16' prior: 0!
A Syslog is an example of FFI to write to the system log using FFI and glibc.!
!Syslog methodsFor: 'bindings' stamp: 'PhilippeBack 9/22/2014 19:00'!
syslog: prority format: format string: string
<cdecl: short 'syslog' (short char* char*) module: '/lib/libc-2.12.so'>
^self externalCallFailed! !
!Syslog methodsFor: 'bindings' stamp: 'PhilippeBack 9/22/2014 18:54'!
openlog: logName option: option facility: facility
<cdecl: void 'openlog' (char* short short) module: '/lib/libc-2.12.so'>
^self externalCallFailed! !
!Syslog methodsFor: 'bindings' stamp: 'PhilippeBack 9/22/2014 18:49'!
callC: aString
<cdecl: short 'puts' (char*) module: '/lib/libc-2.12.so'>
^self externalCallFailed! !
!Syslog methodsFor: 'bindings' stamp: 'PhilippeBack 9/22/2014 19:17'!
puts: aString
<cdecl: short 'puts' (char*) module: '/lib/libc-2.12.so'>
^self externalCallFailed! !
!Syslog methodsFor: 'bindings' stamp: 'PhilippeBack 9/22/2014 18:55'!
closelog
<cdecl: void 'closelog' () module: '/lib/libc-2.12.so'>
^self externalCallFailed! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
Syslog class
instanceVariableNames: ''!
!Syslog class commentStamp: '<historical>' prior: 0!
!
!Syslog class methodsFor: 'example' stamp: 'PhilippeBack 9/22/2014 19:18'!
example
"self example"
| log |
log := Syslog new.
log puts: 'About to write to syslog'.
log openlog: 'testlog' option: 3 facility: 8.
log syslog: 0 format: '%s: I am writing to syslog now ', DateAndTime now asString string: 'PharoVM'.
log closelog.
log puts: 'Done!!'.! !
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment