MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
logging.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Simon Fuhrmann
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 */
9
10#ifndef UTIL_LOGGING_HEADER
11#define UTIL_LOGGING_HEADER
12
13#include <iostream>
14#include <ostream>
15
16#include "util/defines.h"
17
19
21{
22public:
31
32 struct NullStream : public std::ostream
33 {
34 NullStream (void) : std::ostream(nullptr) {}
35 NullStream (NullStream const&) =delete;
36 template <typename T>
37 NullStream& operator<< (T const& arg);
38 };
39
40public:
41 Logging (void);
42 Logging (LogLevel max_level);
43 void set_max_level (LogLevel max_level);
44
45 std::ostream& log (LogLevel log_level) const;
46 std::ostream& error (void) const;
47 std::ostream& warning (void) const;
48 std::ostream& info (void) const;
49 std::ostream& verbose (void) const;
50 std::ostream& debug (void) const;
51
52private:
53 LogLevel max_level;
54 NullStream nullstream;
55};
56
57/* ------------------------ Implementation ------------------------ */
58
59template <typename T>
61Logging::NullStream::operator<< (T const& /*arg*/)
62{
63 return *this;
64}
65
66inline
67Logging::Logging (void)
68 : max_level(LOG_INFO)
69{
70}
71
72inline
74 : max_level(max_level)
75{
76}
77
78inline void
80{
81 this->max_level = max_level;
82}
83
84inline std::ostream&
85Logging::log (LogLevel log_level) const
86{
87 if (log_level > this->max_level)
88 return const_cast<NullStream&>(this->nullstream);
89 return (log_level == LOG_ERROR) ? std::cerr : std::cout;
90}
91
92inline std::ostream&
93Logging::error (void) const
94{
95 return this->log(LOG_ERROR);
96}
97
98inline std::ostream&
99Logging::warning (void) const
100{
101 return this->log(LOG_WARNING);
102}
103
104inline std::ostream&
105Logging::info (void) const
106{
107 return this->log(LOG_INFO);
108}
109
110inline std::ostream&
112{
113 return this->log(LOG_VERBOSE);
114}
115
116inline std::ostream&
117Logging::debug (void) const
118{
119 return this->log(LOG_DEBUG);
120}
121
123
124#endif /* UTIL_LOGGING_HEADER */
125
std::ostream & info(void) const
Definition logging.h:105
std::ostream & debug(void) const
Definition logging.h:117
std::ostream & warning(void) const
Definition logging.h:99
std::ostream & error(void) const
Definition logging.h:93
Logging(void)
Definition logging.h:67
std::ostream & verbose(void) const
Definition logging.h:111
std::ostream & log(LogLevel log_level) const
Definition logging.h:85
void set_max_level(LogLevel max_level)
Definition logging.h:79
STL namespace.
NullStream(NullStream const &)=delete
#define UTIL_NAMESPACE_BEGIN
Definition defines.h:13
#define UTIL_NAMESPACE_END
Definition defines.h:14