claw
1.9.0
Loading...
Searching...
No Matches
log_stream_uniq.cpp
Go to the documentation of this file.
1
/*
2
CLAW - a C++ Library Absolutely Wonderful
3
4
CLAW is a free library without any particular aim but being useful to
5
anyone.
6
7
Copyright (C) 2005-2011 Julien Jorge
8
9
This library is free software; you can redistribute it and/or
10
modify it under the terms of the GNU Lesser General Public
11
License as published by the Free Software Foundation; either
12
version 2.1 of the License, or (at your option) any later version.
13
14
This library is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
Lesser General Public License for more details.
18
19
You should have received a copy of the GNU Lesser General Public
20
License along with this library; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
23
contact: julien.jorge@stuff-o-matic.com
24
*/
30
#include <
claw/logger/log_stream_uniq.hpp
>
31
32
#include <
claw/claw_gettext.hpp
>
33
34
#include <sstream>
35
41
claw::log_stream_uniq::log_stream_uniq
(
log_stream
* s)
42
: m_stream(s)
43
, m_repetition_count(0)
44
{}
45
49
claw::log_stream_uniq::~log_stream_uniq
()
50
{
51
delete
m_stream;
52
}
53
58
void
claw::log_stream_uniq::write
(
const
std::string& str)
59
{
60
std::string::size_type p = str.find_first_of(
'\n'
);
61
62
if
(p == std::string::npos)
63
m_current_line += str;
64
else
65
{
66
++p;
// includes the '\n'
67
m_current_line += str.substr(0, p);
68
69
output_current_line();
70
71
if
(p != str.length())
72
write
(str.substr(p));
73
}
74
}
75
79
void
claw::log_stream_uniq::flush
()
80
{
81
m_stream->flush();
82
}
83
87
void
claw::log_stream_uniq::output_current_line()
88
{
89
if
(m_current_line == m_previous_line)
90
++m_repetition_count;
91
else
92
{
93
if
(m_repetition_count > 0)
94
{
95
std::ostringstream oss;
96
oss <<
claw_gettext
(
"(Previous line repeated "
) << m_repetition_count
97
<<
claw_ngettext
(
" time)"
,
" times)"
, m_repetition_count)
98
<<
'\n'
;
99
100
m_stream->write(oss.str());
101
}
102
103
m_repetition_count = 0;
104
105
m_previous_line = m_current_line;
106
m_stream->write(m_current_line);
107
}
108
109
m_current_line.clear();
110
}
claw::log_stream_uniq::write
virtual void write(const std::string &str)
Write a string in the stream.
Definition
log_stream_uniq.cpp:58
claw::log_stream_uniq::~log_stream_uniq
virtual ~log_stream_uniq()
Destructor.
Definition
log_stream_uniq.cpp:49
claw::log_stream_uniq::log_stream_uniq
log_stream_uniq(log_stream *s)
Constructor.
Definition
log_stream_uniq.cpp:41
claw::log_stream_uniq::flush
virtual void flush()
Flush the stream.
Definition
log_stream_uniq.cpp:79
claw::log_stream
Base class for streams accepting log output.
Definition
log_stream.hpp:61
claw_gettext.hpp
Macros to call gettext on the libclaw textdomain.
claw_ngettext
#define claw_ngettext(s, p, n)
Call ngettext on the default text domain used by Claw.
Definition
claw_gettext.hpp:47
claw_gettext
#define claw_gettext(s)
Call gettext on the default text domain used by Claw.
Definition
claw_gettext.hpp:39
log_stream_uniq.hpp
A log stream that does not output successively the same message.
lib
logger
src
claw
logger
log_stream_uniq.cpp
Generated by
1.13.2