Back on that topic of how to log... I find myself adding a bunch of debug/log type messages to my application, which makes me want to reconsider the best, or at least easy and not horrible, way to get them written to a file somewhere.
The three obvious answers are: 1) Just printf them, and rely on SMF's output redirection. Problem: doesn't play nice with log rotation. 2) syslog(). Problems: Heavyweight, mixes them in with other application output, very verbose format makes reading difficult. 3) Write to some application-unique log file. Problem: no standardization, must roll your own log rotation. But how about something like this? void log(char *fmt, ...) { static char *logfile = NULL; va_list va; FILE *f; if (logfile == NULL) { logfile = get_smf_string("restarter/logfile"); } f = fopen(logfile, "a"); if (f == NULL) f = stdout; va_start(va, fmt); vfprintf(f, fmt, va); va_end(va); if (f != stdout) fclose(f); } ... where get_smf_string() is left as an exercise for the reader. Heavier than just printf, but (I believe) lighter than syslog, and neatly goes into the service-specific log file. Can't be rerouted using syslog.conf, but then again for debug/trace type output it's not clear that's desirable anyway... and it's heavy. We should probably have a more structured logging facility (e.g. to facilitate data mining), but that's pretty heavyweight, both from the standpoint of designing and implementing such a thing and from the standpoint of using it to add debugging output to an application. Thoughts?