1 /* Copyright (C) 2007-2012 Vincent Ollivier
3 * Purple Haze is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * Purple Haze is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 class Log
: public std::ostream
35 LogStream(std::streambuf
*sb
) :
39 LogStream(std::string filename
) :
40 stream(filename
, std::ios::app
),
44 LogStream
<std::ostream
> cout
;
45 LogStream
<std::ofstream
> file
;
48 enum Stream
{ COUT
, FILE, BOTH
};
49 enum LogDirection
{ IN
, OUT
, DEBUG
};
52 std::ostream(std::cout
.rdbuf()),
53 cout(std::cout
.rdbuf()),
57 Log(std::string filename
) :
58 std::ostream(std::cout
.rdbuf()),
59 cout(std::cout
.rdbuf()),
63 void open(std::string filename
) {
64 file
.stream
.open(filename
, std::ios::app
);
69 Log
& operator<<(const T
&val
) {
73 if (file
.state
&& file
.stream
.is_open()) {
79 Log
& operator<<(std::ostream
& (*manip
)(std::ostream
&)) {
83 if (file
.state
&& file
.stream
.is_open()) {
89 Log
& operator<<(const LogDirection
&dir
);