io.h
1 /*
2  * qb - C++ Actor Framework
3  * Copyright (C) 2011-2019 isndev (www.qbaf.io). All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef QB_TYPES_H
19 # define QB_TYPES_H
20 
21 # include <iostream>
22 # include <sstream>
23 # include <mutex>
24 # include <utility>
25 # include <type_traits>
26 # include <nanolog/nanolog.h>
27 
28 namespace qb {
29 #ifdef NDEBUG
30  constexpr static bool debug = false;
31 #else
32  constexpr static bool debug = true;
33 #endif
34 
35  namespace io {
36  using stream = nanolog::NanoLogLine;
37 
38  namespace log {
39  using Level = nanolog::LogLevel;
44  void setLevel(Level lvl);
60  void init(std::string const &file_path, uint32_t const roll_MB = 128);
61  }
62 
73  class cout {
74  static std::mutex io_lock;
75  std::stringstream ss;
76  public:
77  cout() = default;
78  cout(cout const &) = delete;
79  ~cout();
80 
81  template<typename T>
82  inline std::stringstream &operator<<(T const &data) {
83  ss << data;
84  return ss;
85  }
86  };
87  }
88 }
89 
90 #endif //QB_TYPES_H
thread safe print in std::cout
Definition: io.h:73