[PATCH] Logging to file (was: Re: [PATCH] Logging to socket feature)

John Tytgat John.Tytgat at aaug.net
Wed Nov 14 10:54:07 PST 2007


In message <200711141355.46376.juuso.alasuutari at gmail.com>
          Juuso Alasuutari <juuso.alasuutari at gmail.com> wrote:

> [...]
> I'll attach a second revision of the patch. Please shoot holes in it if you 
> find anything you don't like, and I'll do my best to fix them. (Something 
> that I considered doing was making log_file static instead of a global, and 
> making write_to_log_file() a function that accesses it instead of a macro, 
> but I decided to avoid the varargs stuff. But I digress...)
> 
> Juuso
> 
> 
> === added file 'logfile.c'
> --- logfile.c	1970-01-01 00:00:00 +0000
> +++ logfile.c	2007-11-14 11:20:57 +0000
> [...]
> +
> +void
> +close_log_file (void)
> +{
> +  if (log_file)
> +    {
> +      if (fclose (log_file) != EOF)
> +        debug_spew ("Closed log file\n");
> +      else
> +        debug_spew ("Failed to close log file: %s\n", strerror (errno));

Put log_file back to NULL ?

> +    }
> +}
> 
> === added file 'logfile.h'
> --- logfile.h	1970-01-01 00:00:00 +0000
> +++ logfile.h	2007-11-14 11:20:57 +0000
> [...]
> +
> +#ifndef PKG_CONFIG_LOGFILE_H
> +#define PKG_CONFIG_LOGFILE_H
> +
> +#include <stdio.h>
> +#include <errno.h>

I think you only need #include <errno.h> in logfile.c.

> +
> +#define write_to_log_file(x, y...) \
> +if (log_file) fprintf (log_file, x, ## y)

Better have something like:

#define write_to_log_file(x, y...) \
  do { if (log_file) fprintf (log_file, x, ## y); } while (0)

As otherwise:

  if (my_test)
    write_to_log_file ("foo");
  else
    bar ();

will have some confusing run-time behaviour.

John.
-- 
John Tytgat, in his comfy chair at home                                 BASS
John.Tytgat at aaug.net                             ARM powered, RISC OS driven


More information about the pkg-config mailing list