summaryrefslogtreecommitdiff
path: root/debug.c
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2012-12-13 10:00:30 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2012-12-13 10:00:30 +0100
commitbf73de8ded17a3841b2fc0e4d5d10b490182e2ff (patch)
tree55a68a416e7a42ed0018c59b8fc77308ff308bcf /debug.c
parent19d68b15981f50f96b0220516334cd9622fe8b17 (diff)
Fix compilation without any modules. Add warning to debug_syslog if symbol not set, but the files is being compiled. Change symbol-not-set error in debug_filter to warning. Add do-not-print-date option for stdout output. Fix missing reference to extern debug_class_str.
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;