MOO-cows Mailing List Archive

[Prev][Next][Index][Thread]

Re: Logging to a file, instead of to stderr



On Wed, 20 Mar 1996, Ryan Brown wrote:

> Here you go.
[...]
>   static void
>   do_log(const char *fmt, va_list args, const char *prefix)
>   {
[...]
> + if (log_external_file) {
> +     fp = fopen(external_log, "a");
> +     if (fp) {
> +     	fprintf(fp, "%s: %s", nowstr+4,prefix); /* skip the day of the week */
> +     	vfprintf(fp, fmt, args);
> +     	fclose(fp);
> +     	}
> +     }
> + else {
>       fprintf(stderr, "%s: %s", nowstr + 4, prefix); /* skip the day of week */
>       vfprintf(stderr, fmt, args);
>       fflush(stderr);
> +     }
>   }
>
Wouldn't it be a lot better if it just opened the log when the server starts
and close it when the server shuts down, instead of reopening the log every
time it needs to send a message.  I would suggest just removing the fopen
line, using external_log instead of fp in those lines, replacing the
fclose(fp); with fflush(external_log);, making the -l option open the file
and storing the file descriptor in external_log instead of just the file
name, and adding the code to close it somewhere.  Or maybe just rewrite
all the logging code to write to log_file instead of stderr and then have
the startup code set log_file to either stderr if -l isn't specified, or the
file the fd of the opened file.
                                                              --Dark_Owl


References:

Home | Subject Index | Thread Index