summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anylike.org>2009-12-25 08:19:12 +0000
committerChristian Pointner <equinox@anylike.org>2009-12-25 08:19:12 +0000
commit7320250c8756b780169223cd36f01e604978164a (patch)
tree1d206518934829bceec51c29a874ccc91bd7a066
parentadded options parser (diff)
added logging
-rw-r--r--src/Makefile4
-rw-r--r--src/anylike.c42
-rw-r--r--src/log.c259
-rw-r--r--src/log.h90
-rw-r--r--src/log_targets.h363
5 files changed, 754 insertions, 4 deletions
diff --git a/src/Makefile b/src/Makefile
index 2136d1a..2eed24b 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -29,11 +29,11 @@ endif
EXECUTABLE := anylike
-# log.o \
# sig_handler.o \
# sysexec.o \
-OBJ := options.o \
+OBJ := log.o \
+ options.o \
string_list.o \
anylike.o
diff --git a/src/anylike.c b/src/anylike.c
index 50c7d5d..f7be9c0 100644
--- a/src/anylike.c
+++ b/src/anylike.c
@@ -30,6 +30,7 @@
#include "datatypes.h"
#include "options.h"
+#include "log.h"
int main_loop(options_t* opt)
{
@@ -37,9 +38,11 @@ int main_loop(options_t* opt)
L = lua_open();
luaopen_base(L);
- printf("will now start main_loop.lua:\n");
+ log_printf(NOTICE, "will now start main_loop.lua");
+
lua_dofile(L, "main_loop.lua");
- printf("script.lua just returned\n");
+
+ log_printf(NOTICE, "script.lua just returned");
lua_close(L);
@@ -48,6 +51,8 @@ int main_loop(options_t* opt)
int main(int argc, char* argv[])
{
+ log_init();
+
options_t opt;
int ret = options_parse(&opt, argc, argv);
if(ret) {
@@ -68,14 +73,47 @@ int main(int argc, char* argv[])
ret = 0;
options_clear(&opt);
+ log_close();
exit(ret);
}
+ string_list_element_t* tmp = opt.log_targets_.first_;
+ if(!tmp) {
+ log_add_target("syslog:3,anylike,daemon");
+ }
+ else {
+ while(tmp) {
+ ret = log_add_target(tmp->string_);
+ if(ret) {
+ switch(ret) {
+ case -2: fprintf(stderr, "memory error on log_add_target, exitting\n"); break;
+ case -3: fprintf(stderr, "unknown log target: '%s', exitting\n", tmp->string_); break;
+ case -4: fprintf(stderr, "this log target is only allowed once: '%s', exitting\n", tmp->string_); break;
+ default: fprintf(stderr, "syntax error near: '%s', exitting\n", tmp->string_); break;
+ }
+
+ options_clear(&opt);
+ log_close();
+ exit(ret);
+ }
+ tmp = tmp->next_;
+ }
+ }
+ log_printf(NOTICE, "just started...");
options_parse_post(&opt);
ret = main_loop(&opt);
options_clear(&opt);
+ if(!ret)
+ log_printf(NOTICE, "normal shutdown");
+ else if(ret < 0)
+ log_printf(NOTICE, "shutdown after error");
+ else
+ log_printf(NOTICE, "shutdown after signal");
+
+ log_close();
+
return ret;
}
diff --git a/src/log.c b/src/log.c
new file mode 100644
index 0000000..43a0a5a
--- /dev/null
+++ b/src/log.c
@@ -0,0 +1,259 @@
+/*
+ * uAnytun
+ *
+ * uAnytun is a tiny implementation of SATP. Unlike Anytun which is a full
+ * featured implementation uAnytun has no support for multiple connections
+ * or synchronisation. It is a small single threaded implementation intended
+ * to act as a client on small platforms.
+ * The secure anycast tunneling protocol (satp) defines a protocol used
+ * for communication between any combination of unicast and anycast
+ * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
+ * mode and allows tunneling of every ETHER TYPE protocol (e.g.
+ * ethernet, ip, arp ...). satp directly includes cryptography and
+ * message authentication based on the methodes used by SRTP. It is
+ * intended to deliver a generic, scaleable and secure solution for
+ * tunneling and relaying of packets of any protocol.
+ *
+ *
+ * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ *
+ * This file is part of uAnytun.
+ *
+ * uAnytun is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * uAnytun is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with uAnytun. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "datatypes.h"
+
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define SYSLOG_NAMES
+#include <syslog.h>
+
+#include "log.h"
+
+log_t stdlog;
+
+#include "log_targets.h"
+
+const char* log_prio_to_string(log_prio_t prio)
+{
+ switch(prio) {
+ case ERROR: return "ERROR";
+ case WARNING: return "WARNING";
+ case NOTICE: return "NOTICE";
+ case INFO: return "INFO";
+ case DEBUG: return "DEBUG";
+ }
+ return "UNKNOWN";
+}
+
+log_target_type_t log_target_parse_type(const char* conf)
+{
+ if(!conf)
+ return TARGET_UNKNOWN;
+
+ if(!strncmp(conf, "syslog", 6)) return TARGET_SYSLOG;
+ if(!strncmp(conf, "file", 4)) return TARGET_FILE;
+ if(!strncmp(conf, "stdout", 6)) return TARGET_STDOUT;
+ if(!strncmp(conf, "stderr", 6)) return TARGET_STDERR;
+
+ 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(); 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);
+ return -1;
+ }
+ prioptr++;
+ if(!isdigit(prioptr[0]) || (prioptr[1] != 0 && prioptr[1] != ',')) {
+ free(new_target);
+ return -1;
+ }
+ new_target->max_prio_ = prioptr[0] - '0';
+ if(new_target->max_prio_ > 0)
+ new_target->enabled_ = 1;
+
+ if(new_target->init != NULL) {
+ const char* confptr = NULL;
+ if(prioptr[1] != 0)
+ confptr = prioptr+2;
+
+ int ret = (*new_target->init)(new_target, confptr);
+ if(ret) {
+ free(new_target);
+ return ret;
+ }
+ }
+
+ if(new_target->open != NULL)
+ (*new_target->open)(new_target);
+
+
+ if(!targets->first_) {
+ targets->first_ = new_target;
+ }
+ else {
+ log_target_t* tmp = targets->first_;
+ while(tmp->next_)
+ tmp = tmp->next_;
+
+ tmp->next_ = new_target;
+ }
+ return 0;
+}
+
+void log_targets_log(log_targets_t* targets, log_prio_t prio, const char* msg)
+{
+ if(!targets)
+ return;
+
+ log_target_t* tmp = targets->first_;
+ while(tmp) {
+ if(tmp->log != NULL && tmp->enabled_ && tmp->max_prio_ >= prio)
+ (*tmp->log)(tmp, prio, msg);
+
+ tmp = tmp->next_;
+ }
+}
+
+void log_targets_clear(log_targets_t* targets)
+{
+ if(!targets)
+ return;
+
+ while(targets->first_) {
+ log_target_t* tmp = targets->first_;
+ targets->first_ = tmp->next_;
+ if(tmp->close != NULL)
+ (*tmp->close)(tmp);
+ if(tmp->clear != NULL)
+ (*tmp->clear)(tmp);
+ free(tmp);
+ }
+}
+
+
+void log_init()
+{
+ stdlog.max_prio_ = 0;
+ stdlog.targets_.first_ = NULL;
+}
+
+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;
+
+ 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, ...)
+{
+ if(stdlog.max_prio_ < prio)
+ return;
+
+ static char msg[MSG_LENGTH_MAX];
+ va_list args;
+
+ va_start(args, fmt);
+ vsnprintf(msg, MSG_LENGTH_MAX, fmt, args);
+ va_end(args);
+
+ log_targets_log(&stdlog.targets_, prio, msg);
+}
+
+void log_print_hex_dump(log_prio_t prio, const u_int8_t* buf, u_int32_t len)
+{
+ if(stdlog.max_prio_ < prio)
+ return;
+
+ static char msg[MSG_LENGTH_MAX];
+
+ if(!buf) {
+ snprintf(msg, MSG_LENGTH_MAX, "(NULL)");
+ }
+ else {
+ u_int32_t i;
+ int offset = snprintf(msg, MSG_LENGTH_MAX, "dump(%d): ", len);
+ if(offset < 0)
+ return;
+ u_int8_t* ptr = &msg[offset];
+
+ for(i=0; i < len; i++) {
+ if(((i+1)*3) >= (MSG_LENGTH_MAX - offset))
+ break;
+ snprintf(ptr, 3, "%02X ", buf[i]);
+ ptr+=3;
+ }
+ }
+ log_targets_log(&stdlog.targets_, prio, msg);
+}
diff --git a/src/log.h b/src/log.h
new file mode 100644
index 0000000..2717622
--- /dev/null
+++ b/src/log.h
@@ -0,0 +1,90 @@
+/*
+ * uAnytun
+ *
+ * uAnytun is a tiny implementation of SATP. Unlike Anytun which is a full
+ * featured implementation uAnytun has no support for multiple connections
+ * or synchronisation. It is a small single threaded implementation intended
+ * to act as a client on small platforms.
+ * The secure anycast tunneling protocol (satp) defines a protocol used
+ * for communication between any combination of unicast and anycast
+ * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
+ * mode and allows tunneling of every ETHER TYPE protocol (e.g.
+ * ethernet, ip, arp ...). satp directly includes cryptography and
+ * message authentication based on the methodes used by SRTP. It is
+ * intended to deliver a generic, scaleable and secure solution for
+ * tunneling and relaying of packets of any protocol.
+ *
+ *
+ * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ *
+ * This file is part of uAnytun.
+ *
+ * uAnytun is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * uAnytun is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with uAnytun. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef UANYTUN_log_h_INCLUDED
+#define UANYTUN_log_h_INCLUDED
+
+#define MSG_LENGTH_MAX 150
+
+enum log_prio_enum { ERROR = 1, WARNING = 2, NOTICE = 3,
+ INFO = 4, DEBUG = 5 };
+typedef enum log_prio_enum log_prio_t;
+
+const char* log_prio_to_string(log_prio_t prio);
+
+enum log_target_type_enum { TARGET_SYSLOG , TARGET_STDOUT, TARGET_STDERR, TARGET_FILE , TARGET_UNKNOWN };
+typedef enum log_target_type_enum log_target_type_t;
+
+struct log_target_struct {
+ log_target_type_t type_;
+ int (*init)(struct log_target_struct* self, const char* conf);
+ void (*open)(struct log_target_struct* self);
+ void (*log)(struct log_target_struct* self, log_prio_t prio, const char* msg);
+ void (*close)(struct log_target_struct* self);
+ void (*clear)(struct log_target_struct* self);
+ int opened_;
+ int enabled_;
+ log_prio_t max_prio_;
+ void* param_;
+ struct log_target_struct* next_;
+};
+typedef struct log_target_struct log_target_t;
+
+
+struct log_targets_struct {
+ log_target_t* first_;
+};
+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);
+
+
+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, ...);
+void log_print_hex_dump(log_prio_t prio, const u_int8_t* buf, u_int32_t len);
+
+#endif
diff --git a/src/log_targets.h b/src/log_targets.h
new file mode 100644
index 0000000..8db3812
--- /dev/null
+++ b/src/log_targets.h
@@ -0,0 +1,363 @@
+/*
+ * uAnytun
+ *
+ * uAnytun is a tiny implementation of SATP. Unlike Anytun which is a full
+ * featured implementation uAnytun has no support for multiple connections
+ * or synchronisation. It is a small single threaded implementation intended
+ * to act as a client on small platforms.
+ * The secure anycast tunneling protocol (satp) defines a protocol used
+ * for communication between any combination of unicast and anycast
+ * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
+ * mode and allows tunneling of every ETHER TYPE protocol (e.g.
+ * ethernet, ip, arp ...). satp directly includes cryptography and
+ * message authentication based on the methodes used by SRTP. It is
+ * intended to deliver a generic, scaleable and secure solution for
+ * tunneling and relaying of packets of any protocol.
+ *
+ *
+ * Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
+ *
+ * This file is part of uAnytun.
+ *
+ * uAnytun is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * uAnytun is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with uAnytun. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef UANYTUN_log_targets_h_INCLUDED
+#define UANYTUN_log_targets_h_INCLUDED
+
+#include <time.h>
+
+static char* get_time_formatted()
+{
+ char* time_string;
+ time_t t = time(NULL);
+ if(t < 0)
+ time_string = "<time read error>";
+ else {
+ time_string = ctime(&t);
+ if(!time_string)
+ time_string = "<time format error>";
+ else {
+ char* newline = strchr(time_string, '\n');
+ if(newline)
+ newline[0] = 0;
+ }
+ }
+ return time_string;
+}
+
+enum syslog_facility_enum { USER = LOG_USER, MAIL = LOG_MAIL,
+ DAEMON = LOG_DAEMON, AUTH = LOG_AUTH,
+ SYSLOG = LOG_SYSLOG, LPR = LOG_LPR,
+ NEWS = LOG_NEWS, UUCP = LOG_UUCP,
+ CRON = LOG_CRON, AUTHPRIV = LOG_AUTHPRIV,
+ FTP = LOG_FTP, LOCAL0 = LOG_LOCAL0,
+ LOCAL1 = LOG_LOCAL1, LOCAL2 = LOG_LOCAL2,
+ LOCAL3 = LOG_LOCAL3, LOCAL4 = LOG_LOCAL4,
+ LOCAL5 = LOG_LOCAL5, LOCAL6 = LOG_LOCAL6,
+ LOCAL7 = LOG_LOCAL7 };
+typedef enum syslog_facility_enum syslog_facility_t;
+
+struct log_target_syslog_param_struct {
+ char* logname_;
+ syslog_facility_t facility_;
+};
+typedef struct log_target_syslog_param_struct log_target_syslog_param_t;
+
+int log_target_syslog_init(log_target_t* self, const char* conf)
+{
+ if(!self || (conf && conf[0] == 0))
+ return -1;
+
+ self->param_ = malloc(sizeof(log_target_syslog_param_t));
+ if(!self->param_)
+ return -2;
+
+ char* logname;
+ const char* end = NULL;
+ if(!conf)
+ logname = strdup("uanytun");
+ else {
+ end = strchr(conf, ',');
+ if(end) {
+ size_t len = (size_t)(end - conf);
+ if(!len) {
+ free(self->param_);
+ return -1;
+ }
+ logname = malloc(len+1);
+ if(logname) {
+ strncpy(logname, conf, len);
+ logname[len] = 0;
+ }
+ }
+ else
+ logname = strdup(conf);
+ }
+
+ if(!logname) {
+ free(self->param_);
+ return -2;
+ }
+ ((log_target_syslog_param_t*)(self->param_))->logname_ = logname;
+
+ if(!end) {
+ ((log_target_syslog_param_t*)(self->param_))->facility_ = DAEMON;
+ return 0;
+ }
+
+ if(end[1] == 0 || end[1] == ',') {
+ free(logname);
+ free(self->param_);
+ return -1;
+ }
+
+ const char* start = end + 1;
+ end = strchr(start, ',');
+ int i;
+ for(i=0;;++i) {
+ if(facilitynames[i].c_name == NULL) {
+ free(logname);
+ free(self->param_);
+ return -1;
+ }
+
+ if(( end && !strncmp(start, facilitynames[i].c_name, (size_t)(end - start)) && facilitynames[i].c_name[(size_t)(end-start)] == 0) ||
+ (!end && !strcmp(start, facilitynames[i].c_name))) {
+ ((log_target_syslog_param_t*)(self->param_))->facility_ = facilitynames[i].c_val;
+ break;
+ }
+ }
+
+ return 0;
+}
+
+void log_target_syslog_open(log_target_t* self)
+{
+ if(!self || !self->param_)
+ return;
+
+ openlog(((log_target_syslog_param_t*)(self->param_))->logname_, LOG_PID, ((log_target_syslog_param_t*)(self->param_))->facility_);
+ self->opened_ = 1;
+}
+
+void log_target_syslog_log(log_target_t* self, log_prio_t prio, const char* msg)
+{
+ if(!self || !self->param_ || !self->opened_)
+ return;
+
+ syslog((prio + 2) | ((log_target_syslog_param_t*)(self->param_))->facility_, "%s", msg);
+}
+
+void log_target_syslog_close(log_target_t* self)
+{
+ closelog();
+ self->opened_ = 0;
+}
+
+void log_target_syslog_clear(log_target_t* self)
+{
+ if(!self || !self->param_)
+ return;
+
+ if(((log_target_syslog_param_t*)(self->param_))->logname_)
+ free(((log_target_syslog_param_t*)(self->param_))->logname_);
+
+ free(self->param_);
+}
+
+log_target_t* log_target_syslog_new()
+{
+ log_target_t* tmp = malloc(sizeof(log_target_t));
+ if(!tmp)
+ return NULL;
+
+ tmp->type_ = TARGET_SYSLOG;
+ tmp->init = &log_target_syslog_init;
+ tmp->open = &log_target_syslog_open;
+ tmp->log = &log_target_syslog_log;
+ tmp->close = &log_target_syslog_close;
+ tmp->clear = &log_target_syslog_clear;
+ tmp->opened_ = 0;
+ tmp->enabled_ = 0;
+ tmp->max_prio_ = NOTICE;
+ tmp->param_ = NULL;
+ tmp->next_ = NULL;
+
+ return tmp;
+}
+
+
+struct log_target_file_param_struct {
+ char* logfilename_;
+ FILE* file_;
+};
+typedef struct log_target_file_param_struct log_target_file_param_t;
+
+int log_target_file_init(log_target_t* self, const char* conf)
+{
+ if(!self || (conf && conf[0] == 0))
+ return -1;
+
+ self->param_ = malloc(sizeof(log_target_file_param_t));
+ if(!self->param_)
+ return -2;
+
+ char* logfilename;
+ if(!conf)
+ logfilename = strdup("uanytun.log");
+ else {
+ const char* end = strchr(conf, ',');
+ if(end) {
+ size_t len = (size_t)(end - conf);
+ if(!len) {
+ free(self->param_);
+ return -1;
+ }
+ logfilename = malloc(len+1);
+ if(logfilename) {
+ strncpy(logfilename, conf, len);
+ logfilename[len] = 0;
+ }
+ }
+ else
+ logfilename = strdup(conf);
+ }
+
+ if(!logfilename) {
+ free(self->param_);
+ return -2;
+ }
+ ((log_target_file_param_t*)(self->param_))->logfilename_ = logfilename;
+ ((log_target_file_param_t*)(self->param_))->file_ = NULL;
+
+ return 0;
+}
+
+void log_target_file_open(log_target_t* self)
+{
+ if(!self || !self->param_)
+ return;
+
+ ((log_target_file_param_t*)(self->param_))->file_ = fopen(((log_target_file_param_t*)(self->param_))->logfilename_, "w");
+ if(((log_target_file_param_t*)(self->param_))->file_)
+ self->opened_ = 1;
+}
+
+void log_target_file_log(log_target_t* self, log_prio_t prio, const char* msg)
+{
+ if(!self || !self->param_ || !self->opened_)
+ return;
+
+ fprintf(((log_target_file_param_t*)(self->param_))->file_, "%s %s: %s\n", get_time_formatted(), log_prio_to_string(prio), msg);
+ fflush(((log_target_file_param_t*)(self->param_))->file_);
+}
+
+void log_target_file_close(log_target_t* self)
+{
+ if(!self || !self->param_)
+ return;
+
+ fclose(((log_target_file_param_t*)(self->param_))->file_);
+ self->opened_ = 0;
+}
+
+void log_target_file_clear(log_target_t* self)
+{
+ if(!self || !self->param_)
+ return;
+
+ if(((log_target_file_param_t*)(self->param_))->logfilename_)
+ free(((log_target_file_param_t*)(self->param_))->logfilename_);
+
+ free(self->param_);
+}
+
+
+log_target_t* log_target_file_new()
+{
+ log_target_t* tmp = malloc(sizeof(log_target_t));
+ if(!tmp)
+ return NULL;
+
+ tmp->type_ = TARGET_FILE;
+ tmp->init = &log_target_file_init;
+ tmp->open = &log_target_file_open;
+ tmp->log = &log_target_file_log;
+ tmp->close = &log_target_file_close;
+ tmp->clear = &log_target_file_clear;
+ tmp->opened_ = 0;
+ tmp->enabled_ = 0;
+ tmp->max_prio_ = NOTICE;
+ tmp->param_ = NULL;
+ tmp->next_ = NULL;
+
+ return tmp;
+}
+
+
+void log_target_stdout_log(log_target_t* self, log_prio_t prio, const char* msg)
+{
+ printf("%s %s: %s\n", get_time_formatted(), log_prio_to_string(prio), msg);
+}
+
+log_target_t* log_target_stdout_new()
+{
+ log_target_t* tmp = malloc(sizeof(log_target_t));
+ if(!tmp)
+ return NULL;
+
+ tmp->type_ = TARGET_STDOUT;
+ tmp->init = NULL;
+ tmp->open = NULL;
+ tmp->log = &log_target_stdout_log;
+ tmp->close = NULL;
+ tmp->clear = NULL;
+ tmp->opened_ = 0;
+ tmp->enabled_ = 0;
+ tmp->max_prio_ = NOTICE;
+ tmp->param_ = NULL;
+ tmp->next_ = NULL;
+
+ return tmp;
+}
+
+
+void log_target_stderr_log(log_target_t* self, log_prio_t prio, const char* msg)
+{
+ fprintf(stderr, "%s %s: %s\n", get_time_formatted(), log_prio_to_string(prio), msg);
+}
+
+log_target_t* log_target_stderr_new()
+{
+ log_target_t* tmp = malloc(sizeof(log_target_t));
+ if(!tmp)
+ return NULL;
+
+ tmp->type_ = TARGET_STDERR;
+ tmp->init = NULL;
+ tmp->open = NULL;
+ tmp->log = &log_target_stderr_log;
+ tmp->close = NULL;
+ tmp->clear = NULL;
+ tmp->opened_ = 0;
+ tmp->enabled_ = 0;
+ tmp->max_prio_ = NOTICE;
+ tmp->param_ = NULL;
+ tmp->next_ = NULL;
+
+ return tmp;
+}
+
+#endif