/*********************************************************************************
|
* Copyright: (C) 2025 LingYun IoT System Studio
|
* All rights reserved.
|
*
|
* Filename: syslog.c
|
* Description: This file is syslog() example code.
|
*
|
* Version: 1.0.0(10/28/2025)
|
* Author: Guo Wenxue <guowenxue@gmail.com>
|
* ChangeLog: 1, Release initial version on "10/28/2025 02:15:06 PM"
|
*
|
********************************************************************************/
|
|
#include <stdio.h>
|
#include <string.h>
|
#include <unistd.h>
|
#include <string.h>
|
#include <errno.h>
|
#include <syslog.h>
|
#include <libgen.h> /* basename() */
|
|
int main(int argc, char **argv)
|
{
|
char *progname = basename(argv[0]);
|
|
if( daemon(0, 0) < 0)
|
{
|
printf("Program daemon() failure: %s\n", strerror(errno));
|
return -1;
|
}
|
openlog("daemon", LOG_CONS | LOG_PID, 0);
|
syslog(LOG_NOTICE, "Program '%s'start running\n", progname);
|
syslog(LOG_WARNING, "Program '%s' running with a warnning message\n", progname );
|
syslog(LOG_EMERG, "Program '%s' running with a emergency message\n", progname );
|
while(1)
|
{
|
//Do Something here
|
;
|
}
|
|
syslog(LOG_NOTICE, "Program '%s' stop running\n", progname);
|
closelog();
|
|
return 0;
|
}
|