shared/logs-show: urlify CONFIG_FILE in verbose mode

Now all short-*, verbose, with-unit modes are handled. cat, export, json-* are
not, but those are usually used for post-processing, so I don't think it'd be
useful there.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-07-01 20:20:23 +02:00
parent 76f7cc3fe4
commit 79dc477f2f
2 changed files with 15 additions and 8 deletions

3
TODO
View File

@ -134,9 +134,6 @@ Features:
sufficient to build a link by prefixing "http://" and suffixing the
CODE_FILE.
* when outputting log data with journalctl and the log data includes references
to configuration files (CONFIG_FILE=), create a clickable link for it.
* Augment MESSAGE_ID with MESSAGE_BASE, in a similar fashion so that we can
make clickable links from log messages carrying a MESSAGE_ID, that lead to
some explanatory text online.

View File

@ -587,9 +587,11 @@ static int output_verbose(
cursor);
JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
const char *c;
const char *c, *p;
int fieldlen;
const char *on = "", *off = "";
_cleanup_free_ char *urlified = NULL;
size_t valuelen;
c = memchr(data, '=', length);
if (!c)
@ -600,20 +602,28 @@ static int output_verbose(
r = field_set_test(output_fields, data, fieldlen);
if (r < 0)
return r;
if (!r)
if (r == 0)
continue;
if (flags & OUTPUT_COLOR && startswith(data, "MESSAGE=")) {
valuelen = length - 1 - fieldlen;
if ((flags & OUTPUT_COLOR) && (p = startswith(data, "MESSAGE="))) {
on = ANSI_HIGHLIGHT;
off = ANSI_NORMAL;
}
} else if ((p = startswith(data, "CONFIG_FILE="))) {
if (terminal_urlify_path(p, NULL, &urlified) >= 0) {
p = urlified;
valuelen = strlen(urlified);
}
} else
p = c + 1;
if ((flags & OUTPUT_SHOW_ALL) ||
(((length < PRINT_CHAR_THRESHOLD) || flags & OUTPUT_FULL_WIDTH)
&& utf8_is_printable(data, length))) {
fprintf(f, " %s%.*s=", on, fieldlen, (const char*)data);
print_multiline(f, 4 + fieldlen + 1, 0, OUTPUT_FULL_WIDTH, 0, false,
c + 1, length - fieldlen - 1,
p, valuelen,
NULL);
fputs(off, f);
} else {