Skip to content

Commit 1976829

Browse files
committed
yanglint UPDATE improve logging
1 parent 3af2b93 commit 1976829

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

tools/lint/main_ni.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ help(int shortout)
228228
static void
229229
libyang_verbclb(LY_LOG_LEVEL level, const char *msg, const char *data_path, const char *schema_path, uint64_t line)
230230
{
231-
char *levstr;
231+
const char *levstr;
232+
char *full_msg, *aux;
232233

233234
switch (level) {
234235
case LY_LLERR:
@@ -244,15 +245,23 @@ libyang_verbclb(LY_LOG_LEVEL level, const char *msg, const char *data_path, cons
244245
levstr = "dbg :";
245246
break;
246247
}
247-
if (data_path) {
248-
fprintf(stderr, "libyang %s %s (%s)\n", levstr, msg, data_path);
249-
} else if (schema_path) {
250-
fprintf(stderr, "libyang %s %s (%s)\n", levstr, msg, schema_path);
251-
} else if (line) {
252-
fprintf(stderr, "libyang %s %s (line %" PRIu64 ")\n", levstr, msg, line);
253-
} else {
254-
fprintf(stderr, "libyang %s %s\n", levstr, msg);
248+
249+
asprintf(&full_msg, "libyang %s %s", levstr, msg);
250+
251+
if (data_path || schema_path) {
252+
asprintf(&aux, "%s (%s)", full_msg, data_path ? data_path : schema_path);
253+
free(full_msg);
254+
full_msg = aux;
255255
}
256+
257+
if (line) {
258+
asprintf(&aux, "%s (line %" PRIu64 ")", full_msg, line);
259+
free(full_msg);
260+
full_msg = aux;
261+
}
262+
263+
fprintf(stderr, "%s\n", full_msg);
264+
free(full_msg);
256265
}
257266

258267
static struct yl_schema_features *

0 commit comments

Comments
 (0)