log4tango  5.0.0
LogStreambuf.hh
Go to the documentation of this file.
1 //
2 // LogStreambuf.hh
3 //
4 // Copyright (C) : 2000 - 2002
5 // LifeLine Networks BV (www.lifeline.nl). All rights reserved.
6 // Bastiaan Bakker. All rights reserved.
7 //
8 // 2004,2005,2006,2007,2008,2009,2010,2011,2012
9 // Synchrotron SOLEIL
10 // L'Orme des Merisiers
11 // Saint-Aubin - BP 48 - France
12 //
13 // This file is part of log4tango.
14 //
15 // Log4ango is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU Lesser General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 // Log4tango is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 // GNU Lesser General Public License for more details.
24 //
25 // You should have received a copy of the GNU Lesser General Public License
26 // along with Log4Tango. If not, see <http://www.gnu.org/licenses/>.
27 
28 #ifndef _LOG4TANGO_STREAM_BUFFER_H
29 #define _LOG4TANGO_STREAM_BUFFER_H
30 
31 #include <log4tango/Portability.hh>
32 #include <log4tango/Logger.hh>
33 
34 //-----------------------------------------------------------------------------
35 // #DEFINES
36 //-----------------------------------------------------------------------------
37 #define kDEFAULT_BUFFER_SIZE 512
38 
39 namespace log4tango {
40 
41 //-----------------------------------------------------------------------------
42 // Class : LogStreamBuf
43 //-----------------------------------------------------------------------------
44 class LOG4TANGO_EXPORT LogStreamBuf : public std::streambuf
45 {
46  friend class LogStream;
47 
48 public:
49 
50  LogStreamBuf (Logger* logger,
51  Level::Value level,
52  bool filter = true,
53  size_t bsize = kDEFAULT_BUFFER_SIZE);
54 
55  virtual ~LogStreamBuf();
56 
57 protected:
58 
59  virtual std::streamsize xsputn (const char*, std::streamsize);
60 
61 
62  virtual int sync (void);
63 
64 private:
65 
66  int flush_buffer (void);
67 
68  char *_buffer;
69 
70  Logger* _logger;
71 
72  Level::Value _level;
73 
74  bool _filter;
75 };
76 
77 } // namespace log4tango
78 
79 #endif // _LOG4TANGO_STREAM_BUFFER_H
80 
81