Visual Computing Library
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_MISC_LOGGER_CONSOLE_LOGGER_H
24#define VCL_MISC_LOGGER_CONSOLE_LOGGER_H
25
26#include "logger.h"
27
28#include <vclib/concepts/logger.h>
29
30#include <iomanip>
31
32namespace vcl {
33
34class ConsoleLogger : public Logger<std::ostream>
35{
36 std::ostream& mErrStream = std::cerr;
37 std::ostream& mWarnStream = std::cout;
38 std::ostream& mMsgStream = std::cout;
39 std::ostream& mProgStream = std::cout;
40 std::ostream& mDebugStream = std::cerr;
41
42public:
43 ConsoleLogger() = default;
44
46 std::ostream& errStream,
47 std::ostream& warnStream,
48 std::ostream& msgStream,
49 std::ostream& progStream,
50 std::ostream& debugStream) :
51 mErrStream(errStream), mWarnStream(warnStream),
52 mMsgStream(msgStream), mProgStream(progStream),
53 mDebugStream(debugStream)
54 {
55 }
56
57protected:
58 std::ostream* levelStream(LogLevel lvl) const override
59 {
60 switch (lvl) {
61 case ERROR_LOG: return &mErrStream;
62 case WARNING_LOG: return &mWarnStream;
63 case MESSAGE_LOG: return &mMsgStream;
64 case PROGRESS_LOG: return &mProgStream;
65 case DEBUG_LOG: return &mDebugStream;
66 }
67 return nullptr;
68 }
69
70 void alignLeft(std::ostream& o) const override { o << std::left; }
71
72 void alignRight(std::ostream& o) const override { o << std::right; }
73
74 void setWidth(std::ostream& o, uint w) const override { o << std::setw(w); }
75
76 void flush(std::ostream& o) const override { o.flush(); }
77};
78
79} // namespace vcl
80
81#endif // VCL_MISC_LOGGER_CONSOLE_LOGGER_H
Definition console_logger.h:35
Definition logger.h:40
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43