I Import the GNU C syslog functions to post in the system's syslog (I add an include at the end of the post). The import have some strange behavior, the syslog functions need the strings in ASCII format, so I use the pseudotype during import. But, the function openlog() didn't accept it, if I use the pseudotype, there are undefiened symbols in the syslog, e. g.:
Code: Select all
Nov 25 12:29:32 xxxxxx-Linux Í[4649]: 4649]:
Nov 25 12:33:13 xxxxxx-Linux Ḟŵâ[4687]:
Nov 25 12:34:40 xxxxxx-Linux +Q"ú[4708]:
Nov 25 12:35:14 xxxxxx-Linux Ḟ$Ö[4729]: 9]:
The include:
Code: Select all
; C header for syslog (GNU C utils)
; option flags for openlog
#LOG_PID = $01 ;log the pid with each message
#LOG_CONS = $02 ;log on the console if errors in sending
#LOG_ODELAY = $04 ;delay open until first syslog() (Default)
#LOG_NDELAY = $08 ;don't delay open
#LOG_NOWAIT = $10 ;don't wait for console forks: DEPRECATED
#LOG_PERROR = $20 ;log to stderr as well
; facility codes, I comment the not useful codes
;#LOG_KERN = (0<<3) ; kernel messages
#LOG_USER = (1<<3) ; random user-level messages
#LOG_MAIL = (2<<3) ; mail system
#LOG_DAEMON = (3<<3) ; system daemons
;#LOG_AUTH = (4<<3) ; security/authorization messages
;#LOG_SYSLOG = (5<<3) ; messages generated internally by syslogd
#LOG_LPR = (6<<3) ; line printer subsystem
#LOG_NEWS = (7<<3) ; network news subsystem
;#LOG_UUCP = (8<<3) ; UUCP subsystem
;#LOG_CRON = (9<<3) ; clock daemon
#LOG_AUTHPRIV = (10<<3) ; security/authorization messages (private)
#LOG_NFACILITIES = 24 ; current number of facilities
#LOG_FACMASK = $03f8 ; mask to extract facility part
; priorities (these are ordered)
Enumeration 0
#LOG_EMERG ; system is unusable
#LOG_ALERT ; action must be taken immediately
#LOG_CRIT ; critical conditions
#LOG_ERR ; error conditions
#LOG_WARNING ; warning conditions
#LOG_NOTICE ; normal but significant condition
#LOG_INFO ; informational
#LOG_DEBUG ; debug-level messages
EndEnumeration
; macro to create the facility_priority code for the SYSLOG command
Macro LOG_MAKEPRI(fac, pri)
(((fac) << 3) | (pri))
EndMacro
; to get the syslog comamnds work inside purebasic, u have to import them
; this C functions need the strings in ASCII format
ImportC ""
openlog_ (*ident, option.i, facility.i = #Null) As "openlog" ; I did not use the pseudotype, because it did not work at all, in the sysslog are undefined symbols
syslog_ (facility_priority.i, format.p-ascii) As "syslog"
closelog_() As "closelog"
EndImport
Procedure.i toAsc(String.s)
Protected.l l = Len(String)
Static.s ascString
ascString = Space(l)
PokeS(@ascString, String, l+1, #PB_Ascii)
ProcedureReturn @ascString
EndProcedure
Macro SysLog(ProgramName, Facility, Priority, Message)
;openlog_(toAsc(ProgramName), #LOG_PID, Facility) ; use the PID in the log and writes to stderr
openlog_(toAsc(ProgramName), #LOG_PID)
syslog_(LOG_MAKEPRI(Facility, Priority), Message)
closelog_()
EndMacro
; special internal constant, u can switch inside PB with DEFINED compiler function to enable syslog feature
#ENABLE_SYSLOG = #True