/* accessLogMerge - Merge multiple time sorted apache access logs into a single time sorted log.. */ #include "common.h" #include "linefile.h" #include "hash.h" #include "options.h" void usage() /* Explain usage and exit. */ { errAbort( "accessLogMerge - Merge multiple time sorted apache access logs into a single time sorted log.\n" "usage:\n" " accessLogMerge log1 log2 ... logN\n" "Output goes to stdout.\n" "options:\n" " -xxx=XXX\n" ); } boolean addSource = FALSE; static struct optionSpec options[] = { {"addSource", OPTION_BOOLEAN}, {NULL, 0}, }; time_t stampFromLine(struct lineFile *lf, char *line) /* Figure out time stamp corresponding to apache log line. */ { char *s = strchr(line, '['); if (s == NULL) { warn("Couldn't find time stamp in %s\nline %d of %s", line, lf->lineIx, lf->fileName); return 0; } struct tm tm; char *res = strptime(s+1, "%d/%b/%Y:%T", &tm); if (res == NULL) { warn("Badly formatted time stamp in %s\nline %d of %s", line, lf->lineIx, lf->fileName); return 0; } return mktime(&tm); } void accessLogMerge(int logCount, char *logNames[], char *outFile) /* accessLogMerge - Merge multiple time sorted apache access logs into a single time sorted log.. */ { FILE *out = mustOpen(outFile, "w"); struct lineFile *lfs[logCount]; char *lines[logCount]; time_t stamps[logCount]; int i; for (i=0; i