Visual Computing Library  devel
Loading...
Searching...
No Matches
console_logger.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_BASE_LOGGER_CONSOLE_LOGGER_H
24#define VCL_BASE_LOGGER_CONSOLE_LOGGER_H
25
26#include "logger.h"
27
28#include <iomanip>
29
30namespace vcl {
31
32class ConsoleLogger : public Logger<std::ostream>
33{
34 std::ostream& mErrStream = std::cerr;
35 std::ostream& mWarnStream = std::cout;
36 std::ostream& mMsgStream = std::cout;
37 std::ostream& mProgStream = std::cout;
38 std::ostream& mDebugStream = std::cerr;
39
40public:
41 ConsoleLogger() = default;
42
44 std::ostream& errStream,
45 std::ostream& warnStream,
46 std::ostream& msgStream,
47 std::ostream& progStream,
48 std::ostream& debugStream) :
49 mErrStream(errStream), mWarnStream(warnStream),
50 mMsgStream(msgStream), mProgStream(progStream),
51 mDebugStream(debugStream)
52 {
53 }
54
55protected:
56 std::ostream* levelStream(LogLevel lvl) const override
57 {
58 switch (lvl) {
59 case ERROR_LOG: return &mErrStream;
60 case WARNING_LOG: return &mWarnStream;
61 case MESSAGE_LOG: return &mMsgStream;
62 case PROGRESS_LOG: return &mProgStream;
63 case DEBUG_LOG: return &mDebugStream;
64 }
65 return nullptr;
66 }
67
68 void alignLeft(std::ostream& o) const override { o << std::left; }
69
70 void alignRight(std::ostream& o) const override { o << std::right; }
71
72 void setWidth(std::ostream& o, uint w) const override { o << std::setw(w); }
73
74 void flush(std::ostream& o) const override { o.flush(); }
75};
76
77} // namespace vcl
78
79#endif // VCL_BASE_LOGGER_CONSOLE_LOGGER_H
A class representing a box in N-dimensional space.
Definition box.h:46
Definition console_logger.h:33
Definition logger.h:39