c - Daemon logging in Linux -
so have daemon running on linux system, , want have record of activities: log. question is, "best" way accomplish this?
my first idea open file , write it.
file* log = fopen("logfile.log", "w"); /* daemon works...needs write log */ fprintf(log, "foo%s\n", (char*)bar); /* ...all done, close file */ fclose(log);
is there inherently wrong logging way? there better way, such framework built linux?
unix has had long while special logging framework called syslog. type in shell
man 3 syslog
and you'll c interface it.
#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; }
Comments
Post a Comment