source: XMLIO_V2/external/src/POCO/Foundation.save/LogStream.cpp @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 4.4 KB
Line 
1//
2// LogStream.cpp
3//
4// $Id: //poco/1.3/Foundation/src/LogStream.cpp#2 $
5//
6// Library: Foundation
7// Package: Logging
8// Module:  LogStream
9//
10// Copyright (c) 2006-2007, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// Permission is hereby granted, free of charge, to any person or organization
14// obtaining a copy of the software and accompanying documentation covered by
15// this license (the "Software") to use, reproduce, display, distribute,
16// execute, and transmit the Software, and to prepare derivative works of the
17// Software, and to permit third-parties to whom the Software is furnished to
18// do so, all subject to the following:
19//
20// The copyright notices in the Software and this entire statement, including
21// the above license grant, this restriction and the following disclaimer,
22// must be included in all copies of the Software, in whole or in part, and
23// all derivative works of the Software, unless such copies or derivative
24// works are solely in the form of machine-executable object code generated by
25// a source language processor.
26//
27// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
30// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
31// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
32// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
33// DEALINGS IN THE SOFTWARE.
34//
35
36
37#include "Poco/LogStream.h"
38
39
40namespace Poco {
41
42
43//
44// LogStreamBuf
45//
46
47
48LogStreamBuf::LogStreamBuf(Logger& logger, Message::Priority priority):
49        _logger(logger),
50        _priority(priority)
51{
52}
53
54
55LogStreamBuf::~LogStreamBuf()
56{
57}
58
59
60void LogStreamBuf::setPriority(Message::Priority priority)
61{
62        _priority = priority;
63}
64
65
66int LogStreamBuf::writeToDevice(char c)
67{
68        if (c == '\n' || c == '\r')
69        {
70                Message msg(_logger.name(), _message, _priority);
71                _message.clear();
72                _logger.log(msg);
73        }
74        else _message += c;
75        return c;
76}
77
78
79//
80// LogIOS
81//
82
83
84LogIOS::LogIOS(Logger& logger, Message::Priority priority):
85        _buf(logger, priority)
86{
87        poco_ios_init(&_buf);
88}
89
90
91LogIOS::~LogIOS()
92{
93}
94
95
96LogStreamBuf* LogIOS::rdbuf()
97{
98        return &_buf;
99}
100
101
102//
103// LogStream
104//
105
106
107LogStream::LogStream(Logger& logger, Message::Priority priority):
108        LogIOS(logger, priority),
109        std::ostream(&_buf)
110{
111}
112
113
114LogStream::LogStream(const std::string& loggerName, Message::Priority priority):
115        LogIOS(Logger::get(loggerName), priority),
116        std::ostream(&_buf)
117{
118}
119
120       
121LogStream::~LogStream()
122{
123}
124
125       
126LogStream& LogStream::fatal()
127{
128        return priority(Message::PRIO_FATAL);
129}
130
131
132LogStream& LogStream::fatal(const std::string& message)
133{
134        _buf.logger().fatal(message);
135        return priority(Message::PRIO_FATAL);
136}
137
138       
139LogStream& LogStream::critical()
140{
141        return priority(Message::PRIO_CRITICAL);
142}
143
144
145LogStream& LogStream::critical(const std::string& message)
146{
147        _buf.logger().critical(message);
148        return priority(Message::PRIO_CRITICAL);
149}
150
151
152LogStream& LogStream::error()
153{
154        return priority(Message::PRIO_ERROR);
155}
156
157
158LogStream& LogStream::error(const std::string& message)
159{
160        _buf.logger().error(message);
161        return priority(Message::PRIO_ERROR);
162}
163
164
165LogStream& LogStream::warning()
166{
167        return priority(Message::PRIO_WARNING);
168}
169
170
171LogStream& LogStream::warning(const std::string& message)
172{
173        _buf.logger().warning(message);
174        return priority(Message::PRIO_WARNING);
175}
176
177
178LogStream& LogStream::notice()
179{
180        return priority(Message::PRIO_NOTICE);
181}
182
183
184LogStream& LogStream::notice(const std::string& message)
185{
186        _buf.logger().notice(message);
187        return priority(Message::PRIO_NOTICE);
188}
189
190
191LogStream& LogStream::information()
192{
193        return priority(Message::PRIO_INFORMATION);
194}
195
196
197LogStream& LogStream::information(const std::string& message)
198{
199        _buf.logger().information(message);
200        return priority(Message::PRIO_INFORMATION);
201}
202
203
204LogStream& LogStream::debug()
205{
206        return priority(Message::PRIO_DEBUG);
207}
208
209
210LogStream& LogStream::debug(const std::string& message)
211{
212        _buf.logger().debug(message);
213        return priority(Message::PRIO_DEBUG);
214}
215
216
217LogStream& LogStream::trace()
218{
219        return priority(Message::PRIO_TRACE);
220}
221
222
223LogStream& LogStream::trace(const std::string& message)
224{
225        _buf.logger().trace(message);
226        return priority(Message::PRIO_TRACE);
227}
228
229
230LogStream& LogStream::priority(Message::Priority priority)
231{
232        _buf.setPriority(priority);
233        return *this;
234}
235
236
237} // namespace Poco
Note: See TracBrowser for help on using the repository browser.