~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to libaqsistypes/logging_streambufs.h

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
Import upstream version 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright � 2003, Timothy M. Shead
 
2
//
 
3
// Contact: tshead@k-3d.com
 
4
//
 
5
// This program is free software; you can redistribute it and/or
 
6
// modify it under the terms of the GNU General Public
 
7
// License as published by the Free Software Foundation; either
 
8
// version 2 of the License, or (at your option) any later version.
 
9
//
 
10
// This program is distributed in the hope that it will be useful,
 
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
// General Public License for more details.
 
14
//
 
15
// You should have received a copy of the GNU General Public
 
16
// License along with this program; if not, write to the Free Software
 
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 
 
19
 
 
20
#ifndef ___logging_streambufs_Loaded___
 
21
#define ___logging_streambufs_Loaded___
 
22
 
 
23
#include <iostream>
 
24
#include <string>
 
25
 
 
26
#include "aqsis.h"
 
27
 
 
28
START_NAMESPACE( Aqsis )
 
29
 
 
30
///////////////////////////////////////////////////////////
 
31
// timestamp_buf
 
32
 
 
33
/// When attached to an output stream, prefixes every line of output with a timestamp
 
34
class timestamp_buf :
 
35
            public std::streambuf
 
36
{
 
37
public:
 
38
    timestamp_buf(std::ostream& Stream);
 
39
    ~timestamp_buf();
 
40
 
 
41
protected:
 
42
    int overflow(int);
 
43
    int sync();
 
44
 
 
45
private:
 
46
    std::ostream& m_stream;
 
47
    std::streambuf* const m_streambuf;
 
48
    bool m_start_new_line;
 
49
};
 
50
 
 
51
///////////////////////////////////////////////////////////
 
52
// show_level_buf
 
53
 
 
54
/// When attached to an output stream, prefixes every line of output with its log-level (if any)
 
55
class show_level_buf :
 
56
            public std::streambuf
 
57
{
 
58
public:
 
59
    show_level_buf(std::ostream& Stream);
 
60
    ~show_level_buf();
 
61
 
 
62
protected:
 
63
    int overflow(int);
 
64
    int sync();
 
65
 
 
66
private:
 
67
    std::ostream& m_stream;
 
68
    std::streambuf* const m_streambuf;
 
69
    bool m_start_new_line;
 
70
};
 
71
 
 
72
///////////////////////////////////////////////////////////
 
73
// fold_duplicates_buf
 
74
 
 
75
/// When attached to an output stream, replaces duplicate lines of output with a message indicating the number of duplicates
 
76
class fold_duplicates_buf :
 
77
            public std::streambuf
 
78
{
 
79
public:
 
80
    fold_duplicates_buf(std::ostream& Stream);
 
81
    ~fold_duplicates_buf();
 
82
 
 
83
protected:
 
84
    int overflow(int);
 
85
    int sync();
 
86
 
 
87
private:
 
88
    bool print_duplicates();
 
89
 
 
90
    std::ostream& m_stream;
 
91
    std::streambuf* const m_streambuf;
 
92
    std::string m_buffer;
 
93
    std::string m_last_buffer;
 
94
    unsigned long m_duplicate_count;
 
95
};
 
96
 
 
97
///////////////////////////////////////////////////////////
 
98
// reset_level_buf
 
99
 
 
100
/// When attached to an output stream, resets the log level to "unknown" after every line of output
 
101
class reset_level_buf :
 
102
            public std::streambuf
 
103
{
 
104
public:
 
105
    reset_level_buf(std::ostream& Stream);
 
106
    ~reset_level_buf();
 
107
 
 
108
protected:
 
109
    int overflow(int);
 
110
    int sync();
 
111
 
 
112
private:
 
113
    std::ostream& m_stream;
 
114
    std::streambuf* const m_streambuf;
 
115
};
 
116
 
 
117
///////////////////////////////////////////////////////////
 
118
// filter_by_level_buf
 
119
 
 
120
/// Enumerates available log levels
 
121
typedef enum
 
122
{
 
123
    CRITICAL = 1,
 
124
    ERROR = 2,
 
125
    WARNING = 3,
 
126
    INFO = 4,
 
127
    DEBUG = 5
 
128
} log_level_t;
 
129
 
 
130
/// When attached to an output stream, filters-out messages below the given level
 
131
class filter_by_level_buf :
 
132
            public std::streambuf
 
133
{
 
134
public:
 
135
    filter_by_level_buf(const log_level_t MinimumLevel, std::ostream& Stream);
 
136
    ~filter_by_level_buf();
 
137
 
 
138
protected:
 
139
    int overflow(int);
 
140
    int sync();
 
141
 
 
142
private:
 
143
    std::ostream& m_stream;
 
144
    std::streambuf* const m_streambuf;
 
145
    const log_level_t m_minimum_level;
 
146
};
 
147
 
 
148
///////////////////////////////////////////////////////////
 
149
// syslog_buf
 
150
 
 
151
/// When attached to an output stream, copies output to the system log
 
152
class syslog_buf :
 
153
            public std::streambuf
 
154
{
 
155
public:
 
156
    syslog_buf(std::ostream& Stream);
 
157
    ~syslog_buf();
 
158
 
 
159
protected:
 
160
    int overflow(int);
 
161
    int sync();
 
162
 
 
163
private:
 
164
    void write_to_system_log(const std::string& Message);
 
165
 
 
166
    std::ostream& m_stream;
 
167
    std::streambuf* const m_streambuf;
 
168
    std::string m_buffer;
 
169
};
 
170
 
 
171
//-----------------------------------------------------------------------
 
172
 
 
173
END_NAMESPACE( Aqsis )
 
174
 
 
175
#endif  // ___logging_streambufs_Loaded___
 
176