aboutsummaryrefslogtreecommitdiffstats
path: root/src/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/log.c')
-rw-r--r--src/log.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/log.c b/src/log.c
index 3e94f30..a9995b8 100644
--- a/src/log.c
+++ b/src/log.c
@@ -68,6 +68,8 @@ static char rcsid[] = "$Id$";
#include "project.h"
+#include <syslog.h>
+
typedef struct
{
LOG_SIGNATURE;
@@ -78,6 +80,15 @@ typedef struct
int needs_newline;
} File_Log;
+typedef struct
+{
+ LOG_SIGNATURE;
+ char buf[256];
+ unsigned ptr;
+ int priority;
+} Syslog_Log;
+
+
static Log *loggers = NULL;
@@ -301,6 +312,73 @@ file_log_new (char *fn, int rotate)
return (Log *) l;
}
+
+
+static void
+slog_log_bytes (Log * _l, void *_buf, int len)
+{
+ Syslog_Log *l = (Syslog_Log *) _l;
+ uint8_t *buf = (uint8_t *) _buf;
+
+ while (len--)
+ {
+ if (*buf == '\n')
+ {
+ l->buf[l->ptr]=0;
+ syslog(l->priority,"%s",l->buf);
+ l->ptr=0;
+ }
+ else
+ {
+ l->buf[l->ptr++]=*buf;
+ }
+
+
+ if (l->ptr==(sizeof(l->buf)-1)) {
+ l->buf[l->ptr]=0;
+ syslog(l->priority,"%s",l->buf);
+ l->ptr=0;
+ }
+
+ buf++;
+ }
+}
+
+static void
+slog_log (Log * _l, char *buf)
+{
+ Syslog_Log *l = (Syslog_Log *) _l;
+
+ syslog(l->priority,"%s",buf);
+}
+
+static void
+slog_close (Log * _l)
+{
+ free (_l);
+}
+
+
+
+
+Log *
+syslog_log_new (int pri)
+{
+ Syslog_Log *l;
+
+ l = xmalloc (sizeof (Syslog_Log));
+
+ l->log = slog_log;
+ l->log_bytes = slog_log_bytes;
+ l->close= slog_close;
+ l->priority = pri;
+ l->ptr=0;
+
+ log_add ((Log *) l);
+
+ return (Log *) l;
+}
+
void
log_f (Log * log, char *fmt, ...)
{