mirror of
git://git.gnupg.org/gnupg.git
synced 2025-04-13 22:21:09 +02:00
(writen, fun_writer, fun_closer): New.
(log_set_file): Add feature to log to a socket. (log_set_file, do_logv): Force printing with prefix and pid.
This commit is contained in:
parent
082e84c273
commit
bba0f77422
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
* logging.c (writen, fun_writer, fun_closer): New.
|
* logging.c (writen, fun_writer, fun_closer): New.
|
||||||
(log_set_file): Add feature to log to a socket.
|
(log_set_file): Add feature to log to a socket.
|
||||||
|
(log_set_file, do_logv): Force printing with prefix and pid.
|
||||||
|
|
||||||
2003-11-13 Werner Koch <wk@gnupg.org>
|
2003-11-13 Werner Koch <wk@gnupg.org>
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ static char prefix_buffer[80];
|
|||||||
static int with_time;
|
static int with_time;
|
||||||
static int with_prefix;
|
static int with_prefix;
|
||||||
static int with_pid;
|
static int with_pid;
|
||||||
|
static int force_prefixes;
|
||||||
|
|
||||||
static int missing_lf;
|
static int missing_lf;
|
||||||
static int errorcount;
|
static int errorcount;
|
||||||
@ -207,6 +208,7 @@ log_set_file (const char *name)
|
|||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
|
force_prefixes = 0;
|
||||||
if (name && !strncmp (name, "socket://", 9) && name[9])
|
if (name && !strncmp (name, "socket://", 9) && name[9])
|
||||||
{
|
{
|
||||||
#if defined (HAVE_FOPENCOOKIE)|| defined (HAVE_FUNOPEN)
|
#if defined (HAVE_FOPENCOOKIE)|| defined (HAVE_FUNOPEN)
|
||||||
@ -237,6 +239,10 @@ log_set_file (const char *name)
|
|||||||
fp = stderr;
|
fp = stderr;
|
||||||
}
|
}
|
||||||
#endif /* Neither fopencookie nor funopen. */
|
#endif /* Neither fopencookie nor funopen. */
|
||||||
|
|
||||||
|
/* We always need to print the prefix and the pid, so that the
|
||||||
|
server reading the socket can do something meanigful. */
|
||||||
|
force_prefixes = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fp = (name && strcmp(name,"-"))? fopen (name, "a") : stderr;
|
fp = (name && strcmp(name,"-"))? fopen (name, "a") : stderr;
|
||||||
@ -259,7 +265,8 @@ void
|
|||||||
log_set_fd (int fd)
|
log_set_fd (int fd)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
|
force_prefixes = 0;
|
||||||
if (fd == 1)
|
if (fd == 1)
|
||||||
fp = stdout;
|
fp = stdout;
|
||||||
else if (fd == 2)
|
else if (fd == 2)
|
||||||
@ -338,7 +345,7 @@ do_logv( int level, const char *fmt, va_list arg_ptr )
|
|||||||
if (level != JNLIB_LOG_CONT)
|
if (level != JNLIB_LOG_CONT)
|
||||||
{ /* Note this does not work for multiple line logging as we would
|
{ /* Note this does not work for multiple line logging as we would
|
||||||
* need to print to a buffer first */
|
* need to print to a buffer first */
|
||||||
if (with_time)
|
if (with_time && !force_prefixes)
|
||||||
{
|
{
|
||||||
struct tm *tp;
|
struct tm *tp;
|
||||||
time_t atime = time (NULL);
|
time_t atime = time (NULL);
|
||||||
@ -348,14 +355,14 @@ do_logv( int level, const char *fmt, va_list arg_ptr )
|
|||||||
1900+tp->tm_year, tp->tm_mon+1, tp->tm_mday,
|
1900+tp->tm_year, tp->tm_mon+1, tp->tm_mday,
|
||||||
tp->tm_hour, tp->tm_min, tp->tm_sec );
|
tp->tm_hour, tp->tm_min, tp->tm_sec );
|
||||||
}
|
}
|
||||||
if (with_prefix)
|
if (with_prefix || force_prefixes)
|
||||||
fputs (prefix_buffer, logstream);
|
fputs (prefix_buffer, logstream);
|
||||||
if (with_pid)
|
if (with_pid || force_prefixes)
|
||||||
fprintf (logstream, "[%u]", (unsigned int)getpid ());
|
fprintf (logstream, "[%u]", (unsigned int)getpid ());
|
||||||
if (!with_time)
|
if (!with_time || force_prefixes)
|
||||||
putc (':', logstream);
|
putc (':', logstream);
|
||||||
/* A leading backspace suppresses the extra space so that we can
|
/* A leading backspace suppresses the extra space so that we can
|
||||||
correclty output, programname, filename and linenumber. */
|
correctly output, programname, filename and linenumber. */
|
||||||
if (fmt && *fmt == '\b')
|
if (fmt && *fmt == '\b')
|
||||||
fmt++;
|
fmt++;
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user