diff options
author | james <> | 2008-02-14 12:17:42 +0000 |
---|---|---|
committer | james <> | 2008-02-14 12:17:42 +0000 |
commit | e977995b9e97c8f7a795843c753ff59468510c4d (patch) | |
tree | 4e96c6c0cb1cf5eb228839b6f18e53ebfb969378 /src/log.c | |
parent | 5a4c8aa348f78026a568ff684b42ea1a2733aa2a (diff) | |
download | sympathy-e977995b9e97c8f7a795843c753ff59468510c4d.tar.gz sympathy-e977995b9e97c8f7a795843c753ff59468510c4d.tar.bz2 sympathy-e977995b9e97c8f7a795843c753ff59468510c4d.zip |
*** empty log message ***
Diffstat (limited to 'src/log.c')
-rw-r--r-- | src/log.c | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/log.c b/src/log.c new file mode 100644 index 0000000..c5760d2 --- /dev/null +++ b/src/log.c @@ -0,0 +1,82 @@ +/* + * log.c: + * + * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>, + * All rights reserved. + * + */ + +static char rcsid[] = "$Id$"; + +/* + * $Log$ + * Revision 1.1 2008/02/14 12:14:50 james + * *** empty log message *** + * + */ + +#include "project.h" + +typedef struct +{ + LOG_SIGNATURE; + FILE *fp; +} File_Log; + +static void +flog_log (Log * _l, char *buf) +{ + File_Log *l = (File_Log *) _l; + struct timeval tv = { 0 }; + struct tm *tm; + time_t t; + static const char *days[] = { "Sun", "Mon", "Tue", + "Wed", "Thu", "Fri", "Sat" + }; + static const char *months[] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", + "Nov", "Dec" + }; + + if (!l->fp) + return; + + gettimeofday (&tv, NULL); + t = tv.tv_sec; + tm = localtime (&t); + + fprintf (l->fp, "%s %2d %02d:%02d:%02d.%06d ", months[tm->tm_mon], + tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec); + + fputs (buf, l->fp); + fputc ('\n', l->fp); + fflush (l->fp); +} + +static void +flog_close (Log * _l) +{ + File_Log *l = (File_Log *) _l; + if (l->fp) + fclose (l->fp); + free (l); +} + +Log * +file_log_new (char *fn) +{ + File_Log *l; + FILE *f; + + f = fopen (fn, "a+"); + if (!f) + return NULL; + + l = malloc (sizeof (File_Log)); + + l->log = flog_log; + l->close = flog_close; + l->fp = f; + + return (Log *) l; +} |