Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

accesslog.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <stdarg.h>
#include <string.h>
#include "gwlib.h"

Include dependency graph for accesslog.c:

Include dependency graph

Go to the source code of this file.

Defines

#define FORMAT_SIZE   (10*1024)

Functions

void alog_reopen (void)
void alog_close (void)
void alog_open (char *fname, int use_localtm, int use_markers)
void alog_use_localtime (void)
void alog_use_gmtime (void)
void format (char *buf, const char *fmt)
void alog (const char *fmt,...)

Variables

FILE * file = NULL
char filename [FILENAME_MAX+1]
int use_localtime
int markers = 1
Listwriters = NULL


Define Documentation

#define FORMAT_SIZE   (10*1024)
 

Definition at line 173 of file accesslog.c.

Referenced by alog(), and format().


Function Documentation

void alog const char *  fmt,
  ...
 

Definition at line 206 of file accesslog.c.

References file, format(), FORMAT_SIZE, gwlist_add_producer(), gwlist_lock(), gwlist_remove_producer(), gwlist_unlock(), and writers.

00207 {
00208     char buf[FORMAT_SIZE + 1];
00209     va_list args;
00210 
00211     if (file == NULL)
00212         return;
00213 
00214     format(buf, fmt);
00215     va_start(args, fmt);
00216 
00217     gwlist_lock(writers);
00218     gwlist_add_producer(writers);
00219     gwlist_unlock(writers);
00220 
00221     vfprintf(file, buf, args);
00222     fflush(file);
00223 
00224     gwlist_remove_producer(writers);
00225 
00226     va_end(args);
00227 }

Here is the call graph for this function:

void alog_close void   ) 
 

Definition at line 111 of file accesslog.c.

References alog(), file, gwlist_consume(), gwlist_destroy(), gwlist_lock(), gwlist_unlock(), and writers.

Referenced by alog_open(), and main().

00112 {
00113 
00114     if (file != NULL) {
00115         if (markers)
00116             alog("Log ends");
00117         gwlist_lock(writers);
00118         /* wait for writers to complete */
00119         gwlist_consume(writers);
00120         fclose(file);
00121         file = NULL;
00122         gwlist_unlock(writers);
00123         gwlist_destroy(writers, NULL);
00124         writers = NULL;
00125     }
00126 }

Here is the call graph for this function:

void alog_open char *  fname,
int  use_localtm,
int  use_markers
 

Definition at line 129 of file accesslog.c.

References alog(), alog_close(), error(), file, filename, gwlist_create, info(), markers, use_localtime, warning(), and writers.

Referenced by init_bearerbox(), init_smsbox(), and init_wapbox().

00130 {
00131     FILE *f;
00132     
00133     use_localtime = use_localtm;
00134     markers = use_markers;
00135 
00136     if (file != NULL) {
00137         warning(0, "Opening an already opened access log");
00138         alog_close();
00139     }
00140     if (strlen(fname) > FILENAME_MAX) {
00141         error(0, "Access Log filename too long: `%s', cannot open.", fname);
00142         return;
00143     }
00144 
00145     if (writers == NULL)
00146         writers = gwlist_create();
00147 
00148     f = fopen(fname, "a");
00149     if (f == NULL) {
00150         error(errno, "Couldn't open logfile `%s'.", fname);
00151         return;
00152     }
00153     file = f;
00154     strcpy(filename, fname);
00155     info(0, "Started access logfile `%s'.", filename);
00156     if (markers)
00157         alog("Log begins");
00158 }

Here is the call graph for this function:

void alog_reopen void   ) 
 

Definition at line 85 of file accesslog.c.

References alog(), error(), file, filename, gwlist_consume(), gwlist_lock(), gwlist_unlock(), and writers.

Referenced by main(), and signal_handler().

00086 {
00087     if (file == NULL)
00088     return;
00089 
00090     if (markers)
00091         alog("Log ends");
00092 
00093     gwlist_lock(writers);
00094     /* wait for writers to complete */
00095     gwlist_consume(writers);
00096 
00097     fclose(file);
00098     file = fopen(filename, "a");
00099 
00100     gwlist_unlock(writers);
00101 
00102     if (file == NULL) {
00103         error(errno, "Couldn't re-open access logfile `%s'.", filename);
00104     } 
00105     else if (markers) {
00106         alog("Log begins");
00107     }
00108 }

Here is the call graph for this function:

void alog_use_gmtime void   ) 
 

Definition at line 167 of file accesslog.c.

References use_localtime.

00168 {
00169     use_localtime = 0;
00170 }

void alog_use_localtime void   ) 
 

Definition at line 161 of file accesslog.c.

References use_localtime.

00162 {
00163     use_localtime = 1;
00164 }

void format char *  buf,
const char *  fmt
[static]
 

Definition at line 174 of file accesslog.c.

References FORMAT_SIZE, gw_gmtime(), and gw_localtime().

00175 {
00176     time_t t;
00177     struct tm tm;
00178     char *p, prefix[1024];
00179     
00180     p = prefix;
00181 
00182     if (markers) {
00183         time(&t);
00184         if (use_localtime)
00185             tm = gw_localtime(t);
00186         else
00187             tm = gw_gmtime(t);
00188 
00189         sprintf(p, "%04d-%02d-%02d %02d:%02d:%02d ",
00190                 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
00191                 tm.tm_hour, tm.tm_min, tm.tm_sec);
00192     } else {
00193         *p = '\0';
00194     }
00195 
00196     if (strlen(prefix) + strlen(fmt) > FORMAT_SIZE / 2) {
00197         sprintf(buf, "%s <OUTPUT message too long>\n", prefix);
00198         return;
00199     }
00200     sprintf(buf, "%s%s\n", prefix, fmt);
00201 }

Here is the call graph for this function:


Variable Documentation

FILE* file = NULL [static]
 

Definition at line 75 of file accesslog.c.

Referenced by alog(), alog_close(), alog_open(), and alog_reopen().

char filename[FILENAME_MAX+1] [static]
 

Definition at line 76 of file accesslog.c.

Referenced by alog_open(), and alog_reopen().

int markers = 1 [static]
 

Definition at line 78 of file accesslog.c.

Referenced by alog_open().

int use_localtime [static]
 

Definition at line 77 of file accesslog.c.

Referenced by alog_open(), alog_use_gmtime(), and alog_use_localtime().

List* writers = NULL [static]
 

Definition at line 83 of file accesslog.c.

Referenced by alog(), alog_close(), alog_open(), and alog_reopen().

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.