Any samples how to call the syslog api in linux/unix?
Thanks in advance.
Linux syslog
Re: Linux syslog
Here's a small example I just made:
And the syslog.bi header:
After running the example, I can see the message in /var/log/messages:
Code: Select all
#include once "syslog.bi"
openlog("just testing syslog()", 0, LOG_USER)
syslog(LOG_USER or LOG_INFO, !"%s\n", "Hello world!")
closelog()
Code: Select all
'' syslog.bi
#include once "crt/stdarg.bi"
#define LOG_EMERG 0
#define LOG_ALERT 1
#define LOG_CRIT 2
#define LOG_ERR 3
#define LOG_WARNING 4
#define LOG_NOTICE 5
#define LOG_INFO 6
#define LOG_DEBUG 7
#define LOG_PRIMASK &h07
#define LOG_PRI(p) ((p) and LOG_PRIMASK)
#define LOG_MAKEPRI(fac, pri) ((fac) or (pri))
#define LOG_KERN (0 shl 3)
#define LOG_USER (1 shl 3)
#define LOG_MAIL (2 shl 3)
#define LOG_DAEMON (3 shl 3)
#define LOG_AUTH (4 shl 3)
#define LOG_SYSLOG (5 shl 3)
#define LOG_LPR (6 shl 3)
#define LOG_NEWS (7 shl 3)
#define LOG_UUCP (8 shl 3)
#define LOG_CRON (9 shl 3)
#define LOG_AUTHPRIV (10 shl 3)
#define LOG_FTP (11 shl 3)
#define LOG_LOCAL0 (16 shl 3)
#define LOG_LOCAL1 (17 shl 3)
#define LOG_LOCAL2 (18 shl 3)
#define LOG_LOCAL3 (19 shl 3)
#define LOG_LOCAL4 (20 shl 3)
#define LOG_LOCAL5 (21 shl 3)
#define LOG_LOCAL6 (22 shl 3)
#define LOG_LOCAL7 (23 shl 3)
#define LOG_NFACILITIES 24
#define LOG_FACMASK &h03f8
#define LOG_FAC(p) (((p) and LOG_FACMASK) shr 3)
#define LOG_MASK(pri) (1 shl (pri))
#define LOG_UPTO(pri) ((1 shl ((pri)+1)) - 1)
#define LOG_PID &h01
#define LOG_CONS &h02
#define LOG_ODELAY &h04
#define LOG_NDELAY &h08
#define LOG_NOWAIT &h10
#define LOG_PERROR &h20
extern "C"
declare sub closelog()
declare sub openlog(byval as const zstring ptr, byval as long, byval as long)
declare function setlogmask(byval as long) as long
declare sub syslog(byval as long, byval as const zstring ptr, ...)
declare sub vsyslog(byval as long, byval as const zstring ptr, byval as va_list)
end extern
$ sudo tail /var/log/messages
[...]
Oct 24 20:12:26 <hostname> just testing syslog(): Hello world!
Re: Linux syslog
Thanks a lot, works for me. Would also like to include the pid of the process that logs
Do you happen to no some coding/function for that too.
Thanks.
Do you happen to no some coding/function for that too.
Thanks.
Re: Linux syslog
Thank you from 7 years ago. This works perfectly.