summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-02-23 14:46:42 +0000
committerChristian Pointner <equinox@anytun.org>2009-02-23 14:46:42 +0000
commit0f593f1d7456d0374ed0ede5dae302cbb1627169 (patch)
treeec697672b072d671f56049389eeaada927248eb0 /src
parentadded extended logging support (diff)
added duplicates detection for new logging
fixed file logging (flush)
Diffstat (limited to 'src')
-rw-r--r--src/log.c24
-rw-r--r--src/log.h1
-rw-r--r--src/log_targets.h1
3 files changed, 24 insertions, 2 deletions
diff --git a/src/log.c b/src/log.c
index aea8ff4..c3748d7 100644
--- a/src/log.c
+++ b/src/log.c
@@ -73,22 +73,42 @@ log_target_type_t log_target_parse_type(const char* conf)
return TARGET_UNKNOWN;
}
+int log_targets_target_exists(log_targets_t* targets, log_target_type_t type)
+{
+ if(!targets && !targets->first_)
+ return 0;
+
+ log_target_t* tmp = targets->first_;
+ while(tmp) {
+ if(tmp->type_ == type)
+ return 1;
+ tmp = tmp->next_;
+ }
+ return 0;
+}
+
int log_targets_add(log_targets_t* targets, const char* conf)
{
if(!targets)
return -1;
log_target_t* new_target = NULL;
+ int duplicates_allowed = 0;
switch(log_target_parse_type(conf)) {
case TARGET_SYSLOG: new_target = log_target_syslog_new(); break;
- case TARGET_FILE: new_target = log_target_file_new(); break;
+ case TARGET_FILE: new_target = log_target_file_new(); duplicates_allowed = 1; break;
case TARGET_STDOUT: new_target = log_target_stdout_new(); break;
case TARGET_STDERR: new_target = log_target_stderr_new(); break;
default: return -3;
}
if(!new_target)
return -2;
-
+
+ if(!duplicates_allowed && log_targets_target_exists(targets, new_target->type_)) {
+ free(new_target);
+ return -4;
+ }
+
const char* prioptr = strchr(conf, ':');
if(!prioptr || prioptr[1] == 0) {
free(new_target);
diff --git a/src/log.h b/src/log.h
index 293a28f..0be0566 100644
--- a/src/log.h
+++ b/src/log.h
@@ -67,6 +67,7 @@ struct log_targets_struct {
};
typedef struct log_targets_struct log_targets_t;
+int log_targets_target_exists(log_targets_t* targets, log_target_type_t type);
int log_targets_add(log_targets_t* targets, const char* conf);
void log_targets_log(log_targets_t* targets, log_prio_t prio, const char* msg);
void log_targets_clear(log_targets_t* targets);
diff --git a/src/log_targets.h b/src/log_targets.h
index 66f13a0..8357f4d 100644
--- a/src/log_targets.h
+++ b/src/log_targets.h
@@ -236,6 +236,7 @@ void log_target_file_log(log_target_t* self, log_prio_t prio, const char* msg)
return;
fprintf(((log_target_file_param_t*)(self->param_))->file_, "%s-%s\n", log_prio_to_string(prio), msg);
+ fflush(((log_target_file_param_t*)(self->param_))->file_);
}
void log_target_file_close(log_target_t* self)