| 109 | } |
| 110 | |
| 111 | DebugCategory::ostream_proxy_prefix::ostream_proxy_prefix( |
| 112 | const DebugCategory& cat, |
| 113 | color_ostream& target, |
| 114 | const DebugCategory::level msgLevel) : |
| 115 | color_ostream_proxy(target) |
| 116 | { |
| 117 | DebugManager &dm = DebugManager::getInstance(); |
| 118 | const DebugManager::HeaderConfig &config = dm.getHeaderConfig(); |
| 119 | |
| 120 | color(selectColor(msgLevel)); |
| 121 | |
| 122 | bool has_header = false; |
| 123 | if (config.timestamp) { |
| 124 | has_header = true; |
| 125 | auto now = std::chrono::system_clock::now(); |
| 126 | tm local{}; |
| 127 | //! \todo c++ 2020 will have std::chrono::to_stream(fmt, system_clock::now()) |
| 128 | //! but none implements it yet. |
| 129 | std::time_t now_c = std::chrono::system_clock::to_time_t(now); |
| 130 | // Output time in format %02H:%02M:%02S.%03ms |
| 131 | #if __GNUC__ < 5 |
| 132 | // Fallback for gcc 4 |
| 133 | char buffer[32]; |
| 134 | size_t sz = strftime(buffer, sizeof(buffer)/sizeof(buffer[0]), |
| 135 | "%T", localtime_r(&now_c, &local)); |
| 136 | *this << (sz > 0 ? buffer : "HH:MM:SS"); |
| 137 | #else |
| 138 | *this << std::put_time(localtime_r(&now_c, &local),"%T"); |
| 139 | #endif |
| 140 | if (config.timestamp_ms) { |
| 141 | auto ms = std::chrono::duration_cast<std::chrono::milliseconds>( |
| 142 | now.time_since_epoch()) % 1000; |
| 143 | *this << '.' << std::setfill('0') << std::setw(3) << ms.count(); |
| 144 | } |
| 145 | *this << ':'; |
| 146 | } |
| 147 | if (config.thread_id) { |
| 148 | has_header = true; |
| 149 | // Thread id is allocated in the thread creation order to a thread_local |
| 150 | // variable |
| 151 | *this << 't' << thread_id << ':'; |
| 152 | } |
| 153 | if (config.plugin) { |
| 154 | has_header = true; |
| 155 | *this << cat.plugin() << ':'; |
| 156 | } |
| 157 | if (config.category) { |
| 158 | has_header = true; |
| 159 | *this << cat.category() << ':'; |
| 160 | } |
| 161 | // It would be easy to pass __FILE__ and __LINE__ from the logging macros |
| 162 | // and include that information as well, if we want to. |
| 163 | |
| 164 | if (has_header) { |
| 165 | *this << ' '; |
| 166 | } |
| 167 | } |
| 168 |
nothing calls this directly
no test coverage detected