summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/log.c20
-rw-r--r--src/log.h2
-rw-r--r--src/log_targets.h2
3 files changed, 21 insertions, 3 deletions
diff --git a/src/log.c b/src/log.c
index 6f3d6da..08382cd 100644
--- a/src/log.c
+++ b/src/log.c
@@ -185,6 +185,7 @@ void log_targets_clear(log_targets_t* targets)
void log_init()
{
+ stdlog.max_prio_ = 0;
stdlog.targets_.first_ = NULL;
}
@@ -193,18 +194,33 @@ void log_close()
log_targets_clear(&stdlog.targets_);
}
+void update_max_prio()
+{
+ log_target_t* tmp = stdlog.targets_.first_;
+ while(tmp) {
+ if(tmp->enabled_ && tmp->max_prio_ > stdlog.max_prio_)
+ stdlog.max_prio_ = tmp->max_prio_;
+
+ tmp = tmp->next_;
+ }
+}
+
int log_add_target(const char* conf)
{
if(!conf)
return -1;
- return log_targets_add(&stdlog.targets_, conf);
+ int ret = log_targets_add(&stdlog.targets_, conf);
+ if(!ret) update_max_prio();
+ return ret;
}
void log_printf(log_prio_t prio, const char* fmt, ...)
{
- static char msg[MSG_LENGTH_MAX];
+ if(stdlog.max_prio_ < prio)
+ return;
+ static char msg[MSG_LENGTH_MAX];
va_list args;
va_start(args, fmt);
diff --git a/src/log.h b/src/log.h
index 0be0566..70f4316 100644
--- a/src/log.h
+++ b/src/log.h
@@ -74,12 +74,14 @@ void log_targets_clear(log_targets_t* targets);
struct log_struct {
+ log_prio_t max_prio_;
log_targets_t targets_;
};
typedef struct log_struct log_t;
void log_init();
void log_close();
+void update_max_prio();
int log_add_target(const char* conf);
void log_printf(log_prio_t prio, const char* fmt, ...);
diff --git a/src/log_targets.h b/src/log_targets.h
index 5ee23d4..0ea8e83 100644
--- a/src/log_targets.h
+++ b/src/log_targets.h
@@ -232,7 +232,7 @@ void log_target_file_open(log_target_t* self)
void log_target_file_log(log_target_t* self, log_prio_t prio, const char* msg)
{
- if(!self || !self->param_)
+ if(!self || !self->param_ || !self->opened_)
return;
fprintf(((log_target_file_param_t*)(self->param_))->file_, "%s-%s\n", log_prio_to_string(prio), msg);