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.

some examples

#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

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -