Merge pull request #12926 from keszybz/urlify-logs
Urlify CONFIG_FILE and improve SYSTEMD_LOG_LOCATION
This commit is contained in:
@@ -788,14 +788,14 @@ bool condition_test_list(Condition *first, const char *(*to_string)(ConditionTyp
|
||||
assert(p);
|
||||
|
||||
if (r < 0)
|
||||
logger(userdata, LOG_WARNING, r, __FILE__, __LINE__, __func__,
|
||||
logger(userdata, LOG_WARNING, r, PROJECT_FILE, __LINE__, __func__,
|
||||
"Couldn't determine result for %s=%s%s%s, assuming failed: %m",
|
||||
to_string(c->type),
|
||||
c->trigger ? "|" : "",
|
||||
c->negate ? "!" : "",
|
||||
p);
|
||||
else
|
||||
logger(userdata, LOG_DEBUG, 0, __FILE__, __LINE__, __func__,
|
||||
logger(userdata, LOG_DEBUG, 0, PROJECT_FILE, __LINE__, __func__,
|
||||
"%s=%s%s%s %s.",
|
||||
to_string(c->type),
|
||||
c->trigger ? "|" : "",
|
||||
|
||||
+1
-1
@@ -271,7 +271,7 @@ int json_log_internal(JsonVariant *variant, int level, int error, const char *fi
|
||||
({ \
|
||||
int _level = json_dispatch_level(flags), _e = (error); \
|
||||
(log_get_max_level() >= LOG_PRI(_level)) \
|
||||
? json_log_internal(variant, _level, _e, __FILE__, __LINE__, __func__, __VA_ARGS__) \
|
||||
? json_log_internal(variant, _level, _e, PROJECT_FILE, __LINE__, __func__, __VA_ARGS__) \
|
||||
: -ERRNO_VALUE(_e); \
|
||||
})
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
#define log_link_full(link, level, error, ...) \
|
||||
({ \
|
||||
const Link *_l = (link); \
|
||||
(_l && _l->ifname) ? log_object_internal(level, error, __FILE__, __LINE__, __func__, "INTERFACE=", _l->ifname, NULL, NULL, ##__VA_ARGS__) : \
|
||||
log_internal(level, error, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
|
||||
(_l && _l->ifname) ? log_object_internal(level, error, PROJECT_FILE, __LINE__, __func__, "INTERFACE=", _l->ifname, NULL, NULL, ##__VA_ARGS__) : \
|
||||
log_internal(level, error, PROJECT_FILE, __LINE__, __func__, ##__VA_ARGS__); \
|
||||
}) \
|
||||
|
||||
#define log_link_debug(link, ...) log_link_full(link, LOG_DEBUG, 0, ##__VA_ARGS__)
|
||||
|
||||
+63
-22
@@ -29,6 +29,7 @@
|
||||
#include "output-mode.h"
|
||||
#include "parse-util.h"
|
||||
#include "process-util.h"
|
||||
#include "pretty-print.h"
|
||||
#include "sparse-endian.h"
|
||||
#include "stdio-util.h"
|
||||
#include "string-table.h"
|
||||
@@ -375,8 +376,8 @@ static int output_short(
|
||||
const void *data;
|
||||
size_t length;
|
||||
size_t n = 0;
|
||||
_cleanup_free_ char *hostname = NULL, *identifier = NULL, *comm = NULL, *pid = NULL, *fake_pid = NULL, *message = NULL, *realtime = NULL, *monotonic = NULL, *priority = NULL, *transport = NULL, *unit = NULL, *user_unit = NULL;
|
||||
size_t hostname_len = 0, identifier_len = 0, comm_len = 0, pid_len = 0, fake_pid_len = 0, message_len = 0, realtime_len = 0, monotonic_len = 0, priority_len = 0, transport_len = 0, unit_len = 0, user_unit_len = 0;
|
||||
_cleanup_free_ char *hostname = NULL, *identifier = NULL, *comm = NULL, *pid = NULL, *fake_pid = NULL, *message = NULL, *realtime = NULL, *monotonic = NULL, *priority = NULL, *transport = NULL, *config_file = NULL, *unit = NULL, *user_unit = NULL;
|
||||
size_t hostname_len = 0, identifier_len = 0, comm_len = 0, pid_len = 0, fake_pid_len = 0, message_len = 0, realtime_len = 0, monotonic_len = 0, priority_len = 0, transport_len = 0, config_file_len = 0, unit_len = 0, user_unit_len = 0;
|
||||
int p = LOG_INFO;
|
||||
bool ellipsized = false, audit;
|
||||
const ParseFieldVec fields[] = {
|
||||
@@ -390,6 +391,7 @@ static int output_short(
|
||||
PARSE_FIELD_VEC_ENTRY("SYSLOG_IDENTIFIER=", &identifier, &identifier_len),
|
||||
PARSE_FIELD_VEC_ENTRY("_SOURCE_REALTIME_TIMESTAMP=", &realtime, &realtime_len),
|
||||
PARSE_FIELD_VEC_ENTRY("_SOURCE_MONOTONIC_TIMESTAMP=", &monotonic, &monotonic_len),
|
||||
PARSE_FIELD_VEC_ENTRY("CONFIG_FILE=", &config_file, &config_file_len),
|
||||
PARSE_FIELD_VEC_ENTRY("_SYSTEMD_UNIT=", &unit, &unit_len),
|
||||
PARSE_FIELD_VEC_ENTRY("_SYSTEMD_USER_UNIT=", &user_unit, &user_unit_len),
|
||||
};
|
||||
@@ -451,7 +453,8 @@ static int output_short(
|
||||
n += hostname_len + 1;
|
||||
}
|
||||
|
||||
if (mode == OUTPUT_WITH_UNIT && ((unit && shall_print(unit, unit_len, flags)) || (user_unit && shall_print(user_unit, user_unit_len, flags)))) {
|
||||
if (mode == OUTPUT_WITH_UNIT && ((unit && shall_print(unit, unit_len, flags)) ||
|
||||
(user_unit && shall_print(user_unit, user_unit_len, flags)))) {
|
||||
if (unit) {
|
||||
fprintf(f, " %.*s", (int) unit_len, unit);
|
||||
n += unit_len + 1;
|
||||
@@ -485,6 +488,34 @@ static int output_short(
|
||||
fprintf(f, ": [%s blob data]\n", format_bytes(bytes, sizeof(bytes), message_len));
|
||||
} else {
|
||||
fputs(": ", f);
|
||||
|
||||
/* URLify config_file string in message, if the message starts with it.
|
||||
* Skip URLification if the highlighted pattern overlaps. */
|
||||
if (config_file &&
|
||||
message_len >= config_file_len &&
|
||||
memcmp(message, config_file, config_file_len) == 0 &&
|
||||
IN_SET(message[config_file_len], ':', ' ', '\0') &&
|
||||
(!highlight || highlight_shifted[0] == 0 || highlight_shifted[0] > config_file_len)) {
|
||||
|
||||
_cleanup_free_ char *t = NULL, *urlified = NULL;
|
||||
|
||||
t = strndup(config_file, config_file_len);
|
||||
if (t && terminal_urlify_path(t, NULL, &urlified) >= 0) {
|
||||
size_t shift = strlen(urlified) - config_file_len;
|
||||
char *joined;
|
||||
|
||||
joined = strjoin(urlified, message + config_file_len);
|
||||
if (joined) {
|
||||
free_and_replace(message, joined);
|
||||
message_len += shift;
|
||||
if (highlight) {
|
||||
highlight_shifted[0] += shift;
|
||||
highlight_shifted[1] += shift;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ellipsized |=
|
||||
print_multiline(f, n + 2, n_columns, flags, p, audit,
|
||||
message, message_len,
|
||||
@@ -556,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)
|
||||
@@ -569,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 {
|
||||
@@ -1040,21 +1081,21 @@ static int (*output_funcs[_OUTPUT_MODE_MAX])(
|
||||
Set *output_fields,
|
||||
const size_t highlight[2]) = {
|
||||
|
||||
[OUTPUT_SHORT] = output_short,
|
||||
[OUTPUT_SHORT_ISO] = output_short,
|
||||
[OUTPUT_SHORT] = output_short,
|
||||
[OUTPUT_SHORT_ISO] = output_short,
|
||||
[OUTPUT_SHORT_ISO_PRECISE] = output_short,
|
||||
[OUTPUT_SHORT_PRECISE] = output_short,
|
||||
[OUTPUT_SHORT_MONOTONIC] = output_short,
|
||||
[OUTPUT_SHORT_UNIX] = output_short,
|
||||
[OUTPUT_SHORT_FULL] = output_short,
|
||||
[OUTPUT_VERBOSE] = output_verbose,
|
||||
[OUTPUT_EXPORT] = output_export,
|
||||
[OUTPUT_JSON] = output_json,
|
||||
[OUTPUT_JSON_PRETTY] = output_json,
|
||||
[OUTPUT_JSON_SSE] = output_json,
|
||||
[OUTPUT_JSON_SEQ] = output_json,
|
||||
[OUTPUT_CAT] = output_cat,
|
||||
[OUTPUT_WITH_UNIT] = output_short,
|
||||
[OUTPUT_SHORT_PRECISE] = output_short,
|
||||
[OUTPUT_SHORT_MONOTONIC] = output_short,
|
||||
[OUTPUT_SHORT_UNIX] = output_short,
|
||||
[OUTPUT_SHORT_FULL] = output_short,
|
||||
[OUTPUT_VERBOSE] = output_verbose,
|
||||
[OUTPUT_EXPORT] = output_export,
|
||||
[OUTPUT_JSON] = output_json,
|
||||
[OUTPUT_JSON_PRETTY] = output_json,
|
||||
[OUTPUT_JSON_SSE] = output_json,
|
||||
[OUTPUT_JSON_SEQ] = output_json,
|
||||
[OUTPUT_CAT] = output_cat,
|
||||
[OUTPUT_WITH_UNIT] = output_short,
|
||||
};
|
||||
|
||||
int show_journal_entry(
|
||||
|
||||
+10
-5
@@ -57,25 +57,29 @@ int udev_parse_config_full(
|
||||
* to regulate the code in libudev/ and udev/. */
|
||||
r = log_set_max_level_from_string_realm(LOG_REALM_UDEV, log);
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "/etc/udev/udev.conf: failed to set udev log level '%s', ignoring: %m", log);
|
||||
log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
|
||||
"failed to set udev log level '%s', ignoring: %m", log);
|
||||
}
|
||||
|
||||
if (ret_children_max && children_max) {
|
||||
r = safe_atou(children_max, ret_children_max);
|
||||
if (r < 0)
|
||||
log_notice_errno(r, "/etc/udev/udev.conf: failed to set parse children_max=%s, ignoring: %m", children_max);
|
||||
log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
|
||||
"failed to set parse children_max=%s, ignoring: %m", children_max);
|
||||
}
|
||||
|
||||
if (ret_exec_delay_usec && exec_delay) {
|
||||
r = parse_sec(exec_delay, ret_exec_delay_usec);
|
||||
if (r < 0)
|
||||
log_notice_errno(r, "/etc/udev/udev.conf: failed to set parse exec_delay=%s, ignoring: %m", exec_delay);
|
||||
log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
|
||||
"failed to set parse exec_delay=%s, ignoring: %m", exec_delay);
|
||||
}
|
||||
|
||||
if (ret_event_timeout_usec && event_timeout) {
|
||||
r = parse_sec(event_timeout, ret_event_timeout_usec);
|
||||
if (r < 0)
|
||||
log_notice_errno(r, "/etc/udev/udev.conf: failed to set parse event_timeout=%s, ignoring: %m", event_timeout);
|
||||
log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
|
||||
"failed to set parse event_timeout=%s, ignoring: %m", event_timeout);
|
||||
}
|
||||
|
||||
if (ret_resolve_name_timing && resolve_names) {
|
||||
@@ -83,7 +87,8 @@ int udev_parse_config_full(
|
||||
|
||||
t = resolve_name_timing_from_string(resolve_names);
|
||||
if (t < 0)
|
||||
log_notice("/etc/udev/udev.conf: failed to set parse resolve_names=%s, ignoring.", resolve_names);
|
||||
log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
|
||||
"failed to set parse resolve_names=%s, ignoring.", resolve_names);
|
||||
else
|
||||
*ret_resolve_name_timing = t;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user