Reduces repetitive log messages and summarises them. On the one hand, both formatted and unformatted messages (arguments inserted and not) are collected. ext_cnt specifies whether the summary should be displayed at the end of the log. rep_times specifies how often the message should be repeated in the log before it is summarised
| 131 | /// ext_cnt specifies whether the summary should be displayed at the end of the log. |
| 132 | /// rep_times specifies how often the message should be repeated in the log before it is summarised |
| 133 | void LASMessageExt(LAS_MESSAGE_TYPE type, unsigned int rep_times, LAS_FORMAT_STRING(const char*) fmt, ...) { |
| 134 | assert(type <= LAS_FATAL_ERROR); // message type must be less than or equal to LAS_FATAL_ERROR (LAS_QUIET must not be used in LASMessage calls) |
| 135 | |
| 136 | lasmessage_cnt[type]++; |
| 137 | |
| 138 | if (type < las_message_level) return; |
| 139 | |
| 140 | // Check whether summarisation is still required for normal logging. |
| 141 | if (current_msg != fmt) { |
| 142 | if (rep_log_msg > max_rep_log_msg) { |
| 143 | std::string rep_msg = "(log message repeated " + std::to_string(rep_log_msg) + " times)"; |
| 144 | (*message_handler)(LAS_INFO, rep_msg.c_str(), message_user_data); |
| 145 | } |
| 146 | rep_log_msg = 0; |
| 147 | } |
| 148 | |
| 149 | va_list args; |
| 150 | va_start(args, fmt); |
| 151 | char buffer[LAS_MAX_MESSAGE_LENGTH]; |
| 152 | buildMessage(buffer, type, fmt, args); |
| 153 | va_end(args); |
| 154 | |
| 155 | // formatted message only fetch if fmt == buffer |
| 156 | LogData& data = ext_log_entrys[buffer]; |
| 157 | // message template (unformatted message) |
| 158 | LogData& data_unform = ext_log_entrys[fmt]; |
| 159 | |
| 160 | if (data.count < rep_times && data_unform.count < rep_times) { |
| 161 | std::string msg = buffer; |
| 162 | |
| 163 | if (data.count == 0) { |
| 164 | data.type = type; |
| 165 | data.rep_times = rep_times; |
| 166 | } |
| 167 | (*message_handler)(type, msg.c_str(), message_user_data); |
| 168 | if ((data.count == rep_times - 1 || data_unform.count == rep_times - 1)) { |
| 169 | const char *rep_msg = "(This message hit the repetition limit - summary provided at the end of the log)"; |
| 170 | (*message_handler)(LAS_INFO, rep_msg, message_user_data); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | if (strcmp(fmt, buffer) != 0) { |
| 175 | if (data_unform.count == 0) { |
| 176 | data_unform.type = type; |
| 177 | data_unform.rep_times = rep_times; |
| 178 | } else if (data.count == rep_times && data_unform.count >= rep_times) { |
| 179 | ++data_unform.count; |
| 180 | // formatted log 'data.count' DO NOT increase |
| 181 | return; |
| 182 | } |
| 183 | ++data_unform.count; |
| 184 | } |
| 185 | ++data.count; |
| 186 | } |
| 187 | |
| 188 | /// Writes the summarised repeated messages at the end of the log. |
| 189 | /// Replaces the placeholders in unformatted messages '%...' with # using a regex. |
nothing calls this directly
no test coverage detected