On Oct 10, 2009, at 1:50 AM, Jordan Brown wrote: > 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?
That isn't any better than just (1), because smf already gives each thing a log, and I'm not sure what you meant above by "doesn't play nice w/ log rotation" but those logs *are* rotated. There is a single entry in logadm that triggers a script that rotates all smf logs. That said, I personally think we should extend the SMF schema with a <logfile> XML element to declare other logfiles associated with a service, since many have more than one, and also could indicate the format, result in automatic rotation of those, change their location paths, etc etc. -Mike --- Mike Shapiro, Sun Microsystems Open Storage / Fishworks. blogs.sun.com/mws/