I needed to turn use_syslog on but I found out that it wasn't actually
implemented, so I wrote a simple implementation for syslogging. It
sends log to syslog facility 2 (LOG_LOCAL2). Simply set use_syslog = 1
to get syslogging on.
Patch file begins:
diff --git a/src/log.c b/src/log.c
index 451d78a..8208d4a 100755
--- a/src/log.c
+++ b/src/log.c
@@ -42,26 +42,54 @@ void ape_log_init(acetables *g_ape)
if ((g_ape->logs.fd = open(CONFIG_VAL(Log, logfile, g_ape->srv),
O_APPEND | O_WRONLY | O_CREAT, 0644)) == -1) {
g_ape->logs.fd = STDERR_FILENO;
}
+ } else {
+ openlog("APE", LOG_CONS, LOG_LOCAL2);
}
}
void ape_log(ape_log_lvl_t lvl, const char *file, unsigned long int
line, acetables *g_ape, char *buf, ...)
{
+
if (lvl == APE_DEBUG && !g_ape->logs.lvl&APE_DEBUG) {
return;
+ }
+
+ char *buff;
+ int len;
+ va_list val;
+
+ va_start(val, buf);
+ len = vasprintf(&buff, buf, val);
+ va_end(val);
+
+ if (g_ape->logs.use_syslog) {
+ int level = 0;
+ switch (lvl) {
+ case APE_DEBUG:
+ level = LOG_DEBUG;
+ break;
+ case APE_WARN:
+ level = LOG_WARNING;
+ break;
+ case APE_ERR:
+ level = LOG_ERR;
+ break;
+ case APE_INFO:
+ level = LOG_INFO;
+ break;
+ }
+
+ syslog(level, "%s:%li - %s", file, line, buff);
+
+
} else {
time_t log_ts;
- char *buff;
- char date[32];
- int len, datelen;
- va_list val;
- log_ts = time(NULL);
+ char date[32];
- va_start(val, buf);
- len = vasprintf(&buff, buf, val);
- va_end(val);
+ int datelen;
+ log_ts = time(NULL);
datelen = strftime(date, 32, "%Y-%m-%d %H:%M:%S - ",
localtime(&log_ts));
write(g_ape->logs.fd, date, datelen);
@@ -75,6 +103,8 @@ void ape_log(ape_log_lvl_t lvl, const char *file,
unsigned long int line, acetab
write(g_ape->logs.fd, buff, len);
write(g_ape->logs.fd, "\n", 1);
- free(buff);
+
}
+
+ free(buff);
}
--
You received this message because you are subscribed to the Google
Groups "APE Project" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/ape-project?hl=en
---
APE Project (Ajax Push Engine)
Official website : http://www.ape-project.org/
Git Hub : http://github.com/APE-Project/
To unsubscribe, reply using "remove me" as the subject.