summaryrefslogtreecommitdiff
path: root/debug.c
diff options
context:
space:
mode:
Diffstat (limited to 'debug.c')
-rw-r--r--debug.c41
1 files changed, 26 insertions, 15 deletions
diff --git a/debug.c b/debug.c
index cea1ff7..eb87723 100644
--- a/debug.c
+++ b/debug.c
@@ -56,6 +56,7 @@ struct dbg_config_t {
#endif
int fd;
int file_fd;
+ int stdout_no_date;
#ifdef WITH_DBG_SYSLOG
const char* syslog_host;
int syslog_port;
@@ -110,6 +111,7 @@ dbg_status_t dbg_init(unsigned int flags, ...)
dbg_config.fd = -1;
dbg_config.file_fd = -1;
+ dbg_config.stdout_no_date = 0;
int end = 0;
@@ -124,6 +126,9 @@ dbg_status_t dbg_init(unsigned int flags, ...)
case DBG_OPTION_FD:
dbg_config.fd = va_arg(vl, int);
break;
+ case DBG_OPTION_STDOUT_NO_DATE:
+ dbg_config.stdout_no_date = va_arg(vl, int);
+ break;
case DBG_OPTION_FILENAME:
if(dbg_config.flags & DBG_FLAG_OUTPUT_TO_FILE) {
const char *filename = (const char*)va_arg(vl, char*);
@@ -177,9 +182,6 @@ void dbg_close()
dbg_mutex_close();
}
-const char * const debug_class_str[] =
- { "fixme", "err", "warn", "info", "debug" };
-
/*
static unsigned int gettid()
{
@@ -203,16 +205,20 @@ static int dbg_create_header(char *hdr, size_t size)
t.tm_sec);
}
-static int dbg_output_fd(int fd, const char *msg)
+static int dbg_output_fd(int fd, const char *msg, bool withdate)
{
+ int s;
+
if(fd == -1) return 1;
- char hdr[32];
- dbg_create_header(hdr, sizeof(hdr));
+ if(withdate) {
+ char hdr[32];
+ dbg_create_header(hdr, sizeof(hdr));
+
+ s = write(fd, hdr, strlen(hdr));
+ s = write(fd, " ", 1);
+ }
- int s = -1;
- s = write(fd, hdr, strlen(hdr));
- s = write(fd, " ", 1);
s = write(fd, msg, strlen(msg));
if(msg[strlen(msg) - 1] != '\n') {
s = write(fd, "\n", 1);
@@ -227,6 +233,10 @@ int __debug(const char *func, const int line,
int result = 0;
int sz;
+ // NOTE: This must be identical to the debug_class_str in debug_filter.c
+ const char * const debug_class_str[] =
+ { "fixme", "err", "warn", "info", "debug" };
+
dbg_mutex_lock();
#ifdef WITH_DBG_FILTER
@@ -238,7 +248,6 @@ int __debug(const char *func, const int line,
//
char buf[1024];
-
sz = snprintf(buf, sizeof(buf),
"%s:%s:%s:%d ",
debug_class_str[(unsigned)cl], ch, func, line);
@@ -252,26 +261,28 @@ int __debug(const char *func, const int line,
//
if(dbg_config.flags & DBG_FLAG_OUTPUT_TO_STDOUT) {
- dbg_output_fd(STDOUT_FILENO, buf);
+ dbg_output_fd(STDOUT_FILENO, buf, dbg_config.stdout_no_date == 0);
}
if(dbg_config.flags & DBG_FLAG_OUTPUT_TO_STDERR) {
- dbg_output_fd(STDERR_FILENO, buf);
+ dbg_output_fd(STDERR_FILENO, buf, true);
}
if(dbg_config.flags & DBG_FLAG_OUTPUT_TO_FD) {
- dbg_output_fd(dbg_config.fd, buf);
+ dbg_output_fd(dbg_config.fd, buf, true);
}
if(dbg_config.flags & DBG_FLAG_OUTPUT_TO_FILE) {
- dbg_output_fd(dbg_config.file_fd, buf);
+ dbg_output_fd(dbg_config.file_fd, buf, true);
}
+#ifdef WITH_DBG_SYSLOG
if(dbg_config.flags & DBG_FLAG_OUTPUT_TO_SYSLOG) {
dbg_syslog_output(buf);
}
+#endif
-// done:
+done:
dbg_mutex_unlock();
return result;