summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/log.c67
-rw-r--r--src/main.c1
2 files changed, 48 insertions, 20 deletions
diff --git a/src/log.c b/src/log.c
index d4de111..0796ba9 100644
--- a/src/log.c
+++ b/src/log.c
@@ -60,41 +60,68 @@ int init_log(void)
return 0;
}
-void dlog(int priority, const char *format, ...)
- {
- FILE *fd = STATE(log);
+static void logline_put(FILE *fd, int priority, const char *format,
+ va_list *args)
+{
time_t t;
char *buf;
const char *prio;
+
+ t = time(NULL);
+ buf = ctime(&t);
+ buf[strlen(buf)-1]='\0';
+
+ switch (priority) {
+ case LOG_INFO:
+ prio = "info";
+ break;
+ case LOG_NOTICE:
+ prio = "notice";
+ break;
+ case LOG_WARNING:
+ prio = "warning";
+ break;
+ case LOG_ERR:
+ prio = "ERROR";
+ break;
+ default:
+ prio = "?";
+ break;
+ }
+
+ fprintf(fd, "[%s] (pid=%d) [%s] ", buf, getpid(), prio);
+ vfprintf(fd, format, *args);
+ fprintf(fd, "\n");
+ fflush(fd);
+}
+
+void dlog(int priority, const char *format, ...)
+{
+ FILE *fd = STATE(log);
+ FILE *console_out;
va_list args;
-
- if (fd) {
- t = time(NULL);
- buf = ctime(&t);
- buf[strlen(buf)-1]='\0';
+
+ if (CONFIG(running_mode) != DAEMON) {
switch (priority) {
case LOG_INFO:
- prio = "info";
- break;
case LOG_NOTICE:
- prio = "notice";
+ console_out = stdout;
break;
case LOG_WARNING:
- prio = "warning";
- break;
case LOG_ERR:
- prio = "ERROR";
- break;
default:
- prio = "?";
+ console_out = stderr;
break;
}
va_start(args, format);
- fprintf(fd, "[%s] (pid=%d) [%s] ", buf, getpid(), prio);
- vfprintf(fd, format, args);
+ logline_put(console_out, priority, format, &args);
+ va_end(args);
+ }
+
+ if (fd) {
+ va_start(args, format);
+ logline_put(fd, priority, format, &args);
va_end(args);
- fprintf(fd, "\n");
- fflush(fd);
}
if (CONFIG(syslog_facility) != -1) {
diff --git a/src/main.c b/src/main.c
index 2be9b2f..0319b5c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -150,6 +150,7 @@ int main(int argc, char *argv[])
switch(argv[i][1]) {
case 'd':
set_operation_mode(&type, DAEMON, argv);
+ CONFIG(running_mode) = DAEMON;
break;
case 'c':
set_operation_mode(&type, REQUEST, argv);