aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2008-04-02 20:51:03 -0400
committerBrian Cully <github.20.shmit@spamgourmet.com>2008-04-02 20:51:03 -0400
commit4a4cdd2e67c1b46402e27377877c54c018c1650f (patch)
treee84f8dba0d761c672ee1a929664b6f3e99ac2e78 /src
parentbbe49436eee7b739826b303c5f920edec238fddb (diff)
downloadmysqlerl-4a4cdd2e67c1b46402e27377877c54c018c1650f.tar.gz
mysqlerl-4a4cdd2e67c1b46402e27377877c54c018c1650f.zip
Add time logging.
Diffstat (limited to 'src')
-rw-r--r--src/log.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/log.c b/src/log.c
index d03d86e..c1d4a98 100644
--- a/src/log.c
+++ b/src/log.c
@@ -6,6 +6,8 @@
#include <stdio.h>
#include <stdarg.h>
+#include <time.h>
+#include <unistd.h>
const char *LOGPATH = "/tmp/mysqlerl.log";
static FILE *logfile = NULL;
@@ -26,16 +28,33 @@ void
logmsg(const char *format, ...)
{
FILE *out = logfile;
+ char timebuf[32] = "\0";
+ struct tm now_tm;
+ time_t now_time;
va_list args;
+ va_start(args, format);
+
if (logfile == NULL)
out = stderr;
- va_start(args, format);
+ if (time(&now_time) == (time_t)-1) {
+ (void)fprintf(out, "LOGERROR - Failed to fetch time: ");
+ } else {
+ (void)localtime_r(&now_time, &now_tm);
+ if (strftime(timebuf, sizeof(timebuf), "%Y%m%d %H:%M:%S ", &now_tm) == 0) {
+ (void)fprintf(out, "LOGERROR - Failed to parse time (now: %d): ",
+ (int)now_time);
+ } else {
+ (void)fprintf(out, timebuf);
+ }
+ }
+ (void)fprintf(out, "[%d]: ", getpid());
(void)vfprintf(out, format, args);
(void)fprintf(out, "\n");
- va_end(args);
fflush(out);
+
+ va_end(args);
}