How to log messages in LINUX/UNIX using SYSLOG

Rajnilari2015
Posted by Rajnilari2015 under Others category on | Points: 40 | Views : 247
The is a special logging framework available in UNIX call as SYSLOG. In this example, we will see how can we log an INFO to syslog

#include <stdio.h>
#include <unistd.h>
#include <syslog.h>

int main(void) {

openlog("mySYSLOG", 0, LOG_USER);
syslog(LOG_INFO, "HELLO WORLD...LOG THIS MESSAGE");
closelog();
return 0;
}


First we have to include <syslog.h> header file. Then we need to open a connection by using the openlog function.Finally we need to log the message by using the syslog function. The syslog function acts like the PRINTF function of C language.
Hope this helps.

Comments or Responses

Login to post response