qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
io.h
Go to the documentation of this file.
1
24
25#ifndef QB_TYPES_H
26#define QB_TYPES_H
27
28#include <iostream>
29#include <mutex>
30#include <sstream>
31#include <type_traits>
32#include <utility>
33
34#ifdef QB_LOGGER
35#include <nanolog/nanolog.h>
36#endif
37
38namespace qb {
39#ifdef NDEBUG
40constexpr static bool debug = false;
41#else
42constexpr static bool debug = true;
43#endif
44
45namespace io {
46#ifdef QB_LOGGER
47namespace log {
48using stream = nanolog::NanoLogLine;
49using Level = nanolog::LogLevel;
58void setLevel(Level lvl);
59
80void init(std::string const &file_path, uint32_t roll_MB = 128);
81} // namespace log
82#endif
83
100class cout {
101 static std::mutex io_lock;
102 std::stringstream ss;
103
104public:
108 cout() = default;
109
113 cout(cout const &) = delete;
114
122
133 template <typename T>
134 inline std::stringstream &
135 operator<<(T const &data) {
136 ss << data;
137 return ss;
138 }
139
140 inline std::stringstream &
141 operator<<(std::ostream &(*manip)(std::ostream &)) {
142 ss << manip;
143 return ss;
144 }
145};
146
160class cerr {
161 static std::mutex io_lock;
162 std::stringstream ss;
163public:
164 cerr() = default;
165 cerr(cerr const &) = delete;
166 ~cerr();
167 template <typename T>
168 inline std::stringstream &
169 operator<<(T const &data) {
170 ss << data;
171 return ss;
172 }
173
174 inline std::stringstream &
175 operator<<(std::ostream &(*manip)(std::ostream &)) {
176 ss << manip;
177 return ss;
178 }
179};
180} // namespace io
181} // namespace qb
182
183#ifndef QB_LOGGER
184#ifdef QB_STDOUT_LOG
189#define LOG_DEBUG(X) qb::io::cout() << X << std::endl;
194#define LOG_VERB(X) qb::io::cout() << X << std::endl;
199#define LOG_INFO(X) qb::io::cout() << X << std::endl;
204#define LOG_WARN(X) qb::io::cout() << X << std::endl;
209#define LOG_CRIT(X) qb::io::cout() << X << std::endl;
210#else
215#define LOG_DEBUG(X) \
216 do { \
217 } while (false)
218
222#define LOG_VERB(X) \
223 do { \
224 } while (false)
225
229#define LOG_INFO(X) \
230 do { \
231 } while (false)
232
236#define LOG_WARN(X) \
237 do { \
238 } while (false)
239
243#define LOG_CRIT(X) \
244 do { \
245 } while (false)
246#endif
247#endif
248
249#endif // QB_TYPES_H
cout(cout const &)=delete
Deleted copy constructor.
cout()=default
Default constructor.
~cout()
Destructor that flushes output.
std::stringstream & operator<<(T const &data)
Stream insertion operator.
Definition io.h:135
void init()
Initialize the asynchronous event system for the current thread.
Definition listener.h:294