Luiza  v03-01
logbuffer.h
1 // -*- mode: c++;
2 #ifndef logbuffer_h
3 #define logbuffer_h
4 
5 #include <sstream>
6 #include <cstdio>
7 #include "streamlog/logstream.h"
8 
9 namespace streamlog{
10 
11 
18  class logbuffer : public std::streambuf {
19 
20  std::streambuf* _sbuf ;
21  logstream* _ls ;
22 
23  logbuffer();
24 
25 
26  public:
27 
28  logbuffer( std::streambuf* sbuf, logstream* logstream ) : _sbuf( sbuf ), _ls(logstream) {}
29 
30  ~logbuffer() {
31 
32  }
33 
34 
39  inline virtual int overflow( int c = EOF ) {
40 
41  static bool hasNewLine = true ;
42 
43  if ( c == EOF )
44  return EOF ;
45 
46  bool success = true;
47 
48  if ( hasNewLine == true ) {
49 
50  std::string pre = (* _ls->prefix() )() ;
51 
52  success &= ( (unsigned) _sbuf->sputn( pre.c_str() , pre.size() ) == pre.size() ) ;
53 
54  hasNewLine = false;
55  }
56 
57  if ( c == '\n' )
58  hasNewLine = true;
59 
60  if ( success )
61  success &= ( _sbuf->sputc(c) != EOF ) ;
62 
63  if( success )
64  return 0 ;
65 
66  return EOF ;
67  }
68 
69  } ;
70 
71 }
72 #endif
Definition: logbuffer.h:18
Namespace of method for logging messages based on streamlog.
Definition: baselevels.h:20
virtual int overflow(int c=EOF)
Definition: logbuffer.h:39
prefix_base * prefix()
Definition: logstream.h:130
Definition: logstream.h:52