mirror of https://github.com/nirenjan/pinelog.git
Add method to close output stream and reset to default
parent
fb9b51a130
commit
a3eb2c03d7
|
@ -17,6 +17,7 @@ PKG_PROG_PKG_CONFIG
|
||||||
PKG_INSTALLDIR
|
PKG_INSTALLDIR
|
||||||
AX_COMPILER_FLAGS
|
AX_COMPILER_FLAGS
|
||||||
AX_GCC_FUNC_ATTRIBUTE([constructor])
|
AX_GCC_FUNC_ATTRIBUTE([constructor])
|
||||||
|
AX_GCC_FUNC_ATTRIBUTE([destructor])
|
||||||
AX_GCC_FUNC_ATTRIBUTE([format])
|
AX_GCC_FUNC_ATTRIBUTE([format])
|
||||||
|
|
||||||
AC_SUBST([PINELOG_CFLAGS])
|
AC_SUBST([PINELOG_CFLAGS])
|
||||||
|
|
17
pinelog.c
17
pinelog.c
|
@ -87,16 +87,25 @@ void pinelog_set_defaults(void)
|
||||||
log_level = PINELOG_DEFAULT_LEVEL;
|
log_level = PINELOG_DEFAULT_LEVEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if HAVE_FUNC_ATTRIBUTE_DESTRUCTOR
|
||||||
|
__attribute__((destructor))
|
||||||
|
#endif
|
||||||
|
void pinelog_close_output_stream(void)
|
||||||
|
{
|
||||||
|
/* If current output stream is not stdout or stderr, then close it */
|
||||||
|
if (output_stream != NULL && output_stream != stdout && output_stream != stderr) {
|
||||||
|
fclose(output_stream);
|
||||||
|
}
|
||||||
|
output_stream = PINELOG_DEFAULT_STREAM;
|
||||||
|
}
|
||||||
|
|
||||||
int pinelog_set_output_stream(FILE *stream)
|
int pinelog_set_output_stream(FILE *stream)
|
||||||
{
|
{
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If current output stream is not stdout or stderr, then close it */
|
pinelog_close_output_stream();
|
||||||
if (output_stream != stdout && output_stream != stderr) {
|
|
||||||
fclose(output_stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
setlinebuf(stream);
|
setlinebuf(stream);
|
||||||
output_stream = stream;
|
output_stream = stream;
|
||||||
|
|
|
@ -62,6 +62,11 @@ enum {
|
||||||
*/
|
*/
|
||||||
void pinelog_set_defaults(void);
|
void pinelog_set_defaults(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Close the output stream and terminate the logs
|
||||||
|
*/
|
||||||
|
void pinelog_close_output_stream(void);
|
||||||
|
|
||||||
#ifdef PINELOG_TEST
|
#ifdef PINELOG_TEST
|
||||||
/**
|
/**
|
||||||
* @brief Get the pointer to the output stream. Only used in test harness.
|
* @brief Get the pointer to the output stream. Only used in test harness.
|
||||||
|
|
|
@ -181,7 +181,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
printf("1..%u\n", test_id);
|
printf("1..%u\n", test_id);
|
||||||
|
|
||||||
fclose(observed_stream_w);
|
pinelog_close_output_stream();
|
||||||
fclose(observed_stream_r);
|
fclose(observed_stream_r);
|
||||||
close(fifo_fd_w);
|
close(fifo_fd_w);
|
||||||
close(fifo_fd_r);
|
close(fifo_fd_r);
|
||||||
|
|
Loading…
Reference in New Issue