Linux syslog

Linux specific questions.
fstreur
Posts: 3
Joined: Jun 17, 2013 15:55

Linux syslog

Postby fstreur » Oct 23, 2013 19:08

Any samples how to call the syslog api in linux/unix?

Thanks in advance.
dkl
Site Admin
Posts: 3212
Joined: Jul 28, 2005 14:45
Location: Germany

Re: Linux syslog

Postby dkl » Oct 24, 2013 18:15

Here's a small example I just made:

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()


And the syslog.bi header:

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


After running the example, I can see the message in /var/log/messages:
$ sudo tail /var/log/messages
[...]
Oct 24 20:12:26 <hostname> just testing syslog(): Hello world!
fstreur
Posts: 3
Joined: Jun 17, 2013 15:55

Re: Linux syslog

Postby fstreur » Nov 10, 2013 13:28

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.
jdmcbride
Posts: 26
Joined: Aug 06, 2016 16:13

Re: Linux syslog

Postby jdmcbride » Oct 14, 2020 21:39

Thank you from 7 years ago. This works perfectly.

Return to “Linux”

Who is online

Users browsing this forum: No registered users and 1 guest