Loading...
Searching...
No Matches
Logging.hpp
Go to the documentation of this file.
1// This code is based on Jet framework.
2// Copyright (c) 2018 Doyub Kim
3// CubbyFlow is voxel-based fluid simulation engine for computer games.
4// Copyright (c) 2020 CubbyFlow Team
5// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6// AI Part: Dongheon Cho, Minseo Kim
7// We are making my contributions/submissions to this project solely in our
8// personal capacity and are not conveying any rights to any intellectual
9// property of any third parties.
10
11#ifndef CUBBYFLOW_LOGGER_HPP
12#define CUBBYFLOW_LOGGER_HPP
13
14#include <cstdint>
15#include <sstream>
16
17namespace CubbyFlow
18{
21enum class LogLevel : uint8_t
22{
23 All = 0,
24 Debug = 1,
25 Info = 2,
26 Warn = 3,
27 Error = 4,
28 Off = 5
29};
30
38{
39 public:
42
44 Logger(const Logger&) = delete;
45
48
51
54
57
61 {
62 m_buffer << x;
63 return *this;
64 }
65
66 private:
67 LogLevel m_level;
68 mutable std::stringstream m_buffer{};
69};
70
73{
74 public:
76 static void SetInfoStream(std::ostream* stream);
77
79 static void SetWarnStream(std::ostream* stream);
80
82 static void SetErrorStream(std::ostream* stream);
83
85 static void SetDebugStream(std::ostream* stream);
86
88 static void SetAllStream(std::ostream* stream);
89
91 static std::string GetHeader(LogLevel level);
92
94 static void SetLevel(LogLevel level);
95
97 static void Mute();
98
100 static void Unmute();
101};
102
104extern Logger infoLogger;
105
107extern Logger warnLogger;
108
110extern Logger errorLogger;
111
113extern Logger debugLogger;
114
115#define CUBBYFLOW_INFO \
116 (Logger(LogLevel::Info) \
117 << Logging::GetHeader(LogLevel::Info) << "[" << __FILE__ << ":" \
118 << __LINE__ << " (" << __func__ << ")] ")
119#define CUBBYFLOW_WARN \
120 (Logger(LogLevel::Warn) \
121 << Logging::GetHeader(LogLevel::Warn) << "[" << __FILE__ << ":" \
122 << __LINE__ << " (" << __func__ << ")] ")
123#define CUBBYFLOW_ERROR \
124 (Logger(LogLevel::Error) \
125 << Logging::GetHeader(LogLevel::Error) << "[" << __FILE__ << ":" \
126 << __LINE__ << " (" << __func__ << ")] ")
127#define CUBBYFLOW_DEBUG \
128 (Logger(LogLevel::Debug) \
129 << Logging::GetHeader(LogLevel::Debug) << "[" << __FILE__ << ":" \
130 << __LINE__ << " (" << __func__ << ")] ")
131} // namespace CubbyFlow
132
133#endif
Super simple logger implementation.
Definition Logging.hpp:38
Logger(Logger &&) noexcept=delete
Deleted move constructor.
Logger(const Logger &)=delete
Deleted copy constructor.
Logger(LogLevel level)
Constructs a logger with logging level.
Helper class for logging.
Definition Logging.hpp:73
static void Mute()
Mutes the logger.
static void SetInfoStream(std::ostream *stream)
Sets the output stream for the info level logs.
static void SetErrorStream(std::ostream *stream)
Sets the output stream for the error level logs.
static void SetDebugStream(std::ostream *stream)
Sets the output stream for the debug level logs.
static void SetAllStream(std::ostream *stream)
Sets the output stream for all the log levels.
static std::string GetHeader(LogLevel level)
Returns the header string.
static void Unmute()
Un-mutes the logger.
static void SetLevel(LogLevel level)
Sets the log level.
static void SetWarnStream(std::ostream *stream)
Sets the output stream for the warning level logs.
Definition Matrix.hpp:30
Definition pybind11Utils.hpp:21
LogLevel
Definition Logging.hpp:22
Logger errorLogger
Error-level logger.
Logger infoLogger
Info-level logger.
Logger debugLogger
Debug-level logger.
Logger warnLogger
Warn-level logger.