summaryrefslogtreecommitdiff
path: root/src/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/log.c')
-rw-r--r--src/log.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/log.c b/src/log.c
index e167c5c..353fa06 100644
--- a/src/log.c
+++ b/src/log.c
@@ -32,6 +32,7 @@
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
+#include <pthread.h>
#define SYSLOG_NAMES
#include <syslog.h>
@@ -151,6 +152,7 @@ void log_targets_log(log_targets_t* targets, log_prio_t prio, const char* msg)
if(!targets)
return;
+ pthread_mutex_lock(&(stdlog.log_mutex_));
log_target_t* tmp = targets->first_;
while(tmp) {
if(tmp->log != NULL && tmp->enabled_ && tmp->max_prio_ >= prio)
@@ -158,6 +160,7 @@ void log_targets_log(log_targets_t* targets, log_prio_t prio, const char* msg)
tmp = tmp->next_;
}
+ pthread_mutex_unlock(&(stdlog.log_mutex_));
}
void log_targets_clear(log_targets_t* targets)
@@ -181,10 +184,12 @@ void log_init()
{
stdlog.max_prio_ = 0;
stdlog.targets_.first_ = NULL;
+ pthread_mutex_init(&(stdlog.log_mutex_), NULL);
}
void log_close()
{
+ pthread_mutex_destroy(&(stdlog.log_mutex_));
log_targets_clear(&stdlog.targets_);
}
@@ -214,7 +219,7 @@ void log_printf(log_prio_t prio, const char* fmt, ...)
if(stdlog.max_prio_ < prio)
return;
- static char msg[MSG_LENGTH_MAX];
+ char msg[MSG_LENGTH_MAX];
va_list args;
va_start(args, fmt);
@@ -229,7 +234,7 @@ void log_print_hex_dump(log_prio_t prio, const uint8_t* buf, uint32_t len)
if(stdlog.max_prio_ < prio)
return;
- static char msg[MSG_LENGTH_MAX];
+ char msg[MSG_LENGTH_MAX];
if(!buf) {
snprintf(msg, MSG_LENGTH_MAX, "(NULL)");