source: subversion/applications/utils/mod_mapnik_wms/logbuffer.cpp @ 28748

Last change on this file since 28748 was 22430, checked in by frederik, 9 years ago

initial release of mod_mapnik_wms, an apache2 module for running a mapnik-based wms. documentation & mailing list announcement to follow in a few days

File size: 1.1 KB
Line 
1/**
2 * logbuffer
3 *
4 * subclass of stream buffer class that
5 * collects output and writes it to a log file, with time stamps.
6 *
7 * used to direct Mapnik console messages to a log file.
8 *
9 * part of the Mapnik WMS server module for Apache
10 */
11
12#include <sys/time.h>
13#include <time.h>
14
15#include "logbuffer.h"
16
17logbuffer::logbuffer(FILE* f)
18   : std::streambuf(), fptr(f) 
19{
20}
21
22void logbuffer::dump_buffer()
23{
24    if (buffer.empty()) return;
25    struct timeval tv;
26    gettimeofday(&tv,NULL);
27    time_t now = (time_t)tv.tv_sec;
28    struct tm *mtim = localtime(&now);
29
30    mtim = localtime(&now);
31    fprintf(fptr, "%04d%02d%02d %02d:%02d:%02d.%06d %s\n",
32       mtim->tm_year+1900, mtim->tm_mon+1,
33       mtim->tm_mday, mtim->tm_hour, mtim->tm_min, mtim->tm_sec,
34       (int)(tv.tv_usec), buffer.c_str());
35    buffer.clear();
36}
37
38logbuffer::~logbuffer()
39{
40   //dump_buffer();
41}
42
43int logbuffer::overflow(int c) 
44{
45   switch (c) {
46      case EOF: return EOF;
47      case 10: dump_buffer(); return 10;
48      default: buffer.append(1, c); return c;
49   }
50}
51
52int logbuffer::sync() 
53{
54   return fflush(fptr);
55}
56
Note: See TracBrowser for help on using the repository browser.