MCPcopy Create free account
hub / github.com/LAStools/LAStools / LASMessageExt

Function LASMessageExt

LASzip/src/lasmessage.cpp:132–185  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

to_stringFunction · 0.85
buildMessageFunction · 0.85

Tested by

no test coverage detected