summaryrefslogtreecommitdiffstats
path: root/src/shared/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/log.c')
-rw-r--r--src/shared/log.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/shared/log.c b/src/shared/log.c
index 055acb4..3a4739d 100644
--- a/src/shared/log.c
+++ b/src/shared/log.c
@@ -3,7 +3,7 @@
*
* Copyright(c) 2011-2012 Simon Rettberg
*
- * This file may be licensed under the terms of of the
+ * This file may be licensed under the terms of the
* GNU General Public License Version 2 (the ``GPL'').
*
* Software distributed under the License is distributed
@@ -18,7 +18,7 @@
*
*/
-#include "log.h"
+#include <dnbd3/shared/log.h>
#include <stdarg.h>
#include <pthread.h>
#include <stdlib.h>
@@ -36,6 +36,7 @@ static _Atomic logmask_t maskCon = 15;
static char *logFile = NULL;
static int logFd = -1;
+static FILE *logOutStream;
static bool consoleTimestamps = false;
@@ -43,6 +44,10 @@ static bool consoleTimestamps = false;
static int writeLevel(char *buffer, logmask_t level);
+void log_init(void) {
+ logOutStream = stdout;
+}
+
bool log_hasMask(const logmask_t mask)
{
return ( ( maskFile | maskCon ) & mask ) == mask;
@@ -63,6 +68,15 @@ void log_setConsoleTimestamps(bool on)
consoleTimestamps = on;
}
+int log_setConsoleOutputStream(FILE *outputStream)
+{
+ if ( outputStream != stdout && outputStream != stderr )
+ return -EINVAL;
+
+ logOutStream = outputStream;
+ return 0;
+}
+
bool log_openLogFile(const char *path)
{
pthread_mutex_lock( &logLock );
@@ -93,10 +107,10 @@ void logadd(const logmask_t mask, const char *fmt, ...)
struct tm timeinfo;
char buffer[LINE_LEN];
bool toFile = maskFile & mask;
- bool toStdout = maskCon & mask;
+ bool toOutStream = maskCon & mask;
size_t offset;
- if ( toFile || ( toStdout && consoleTimestamps ) ) {
+ if ( toFile || ( toOutStream && consoleTimestamps ) ) {
time( &rawtime );
localtime_r( &rawtime, &timeinfo );
offset = strftime( buffer, LINE_LEN, "[%d.%m. %H:%M:%S] ", &timeinfo );
@@ -134,15 +148,11 @@ void logadd(const logmask_t mask, const char *fmt, ...)
}
pthread_mutex_unlock( &logLock );
}
- if ( toStdout ) {
- if ( consoleTimestamps ) stdoutLine = buffer;
-#ifdef AFL_MODE
- fputs( stdoutLine, stderr );
- fflush( stderr );
-#else
- fputs( stdoutLine, stdout );
- fflush( stdout );
-#endif
+ if ( toOutStream ) {
+ if ( consoleTimestamps )
+ stdoutLine = buffer;
+ fputs( stdoutLine, logOutStream );
+ fflush( logOutStream );
}
}