Search code examples
clinuxubuntusyslog

How to use syslog to log some message on terminal?


I have to use syslog to log a message on terminal. I found a code on internet but it is not working. code:

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

int main(void) 
{    
openlog("slog", LOG_PID|LOG_CONS, LOG_USER);  
syslog(LOG_INFO, "A different kind of Hello world ... ");
closelog();  
 return 0;
}

Solution

  • Thanks to all for comments and answers.

    Now, I am able to print a message on the terminal by using LOG_PERROR option in openlog() function.There is no need of LOG_CONS option to print on console. Thanks to @Cheatah for the help. openlog("slog", LOG_PID|LOG_PERROR, LOG_USER);

    Thank you.