diff options
Diffstat (limited to 'jnlib/logging.c')
-rw-r--r-- | jnlib/logging.c | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/jnlib/logging.c b/jnlib/logging.c index 2e0d53ae..647e757c 100644 --- a/jnlib/logging.c +++ b/jnlib/logging.c @@ -89,12 +89,37 @@ log_set_file( const char *name ) } setvbuf( fp, NULL, _IOLBF, 0 ); - if( logstream && logstream != stderr ) - fclose( logstream ); + if (logstream && logstream != stderr && logstream != stdout) + fclose( logstream ); logstream = fp; missing_lf = 0; } +void +log_set_fd (int fd) +{ + FILE *fp; + + if (fd == 1) + fp = stdout; + else if (fd == 2) + fp = stderr; + else + fp = fdopen (fd, "a"); + if (!fp) + { + fprintf (stderr, "failed to fdopen log fd %d: %s\n", + fd, strerror(errno)); + return; + } + setvbuf (fp, NULL, _IOLBF, 0); + + if (logstream && logstream != stderr && logstream != stdout) + fclose( logstream); + logstream = fp; + missing_lf = 0; +} + void log_set_prefix (const char *text, unsigned int flags) @@ -110,6 +135,23 @@ log_set_prefix (const char *text, unsigned int flags) with_pid = (flags & 4); } + +const char * +log_get_prefix (unsigned int *flags) +{ + if (flags) + { + *flags = 0; + if (with_prefix) + *flags |= 1; + if (with_time) + *flags |= 2; + if (with_pid) + *flags |=4; + } + return prefix_buffer; +} + int log_get_fd() { |