Commit d4205751 authored by Lennart Poettering's avatar Lennart Poettering

journal: implement message catalog

The message catalog can be used to attach short help texts to log lines,
keyed by their MESSAGE_ID= fields. This is useful to help the
administrator understand the context and cause of a message, find
possible solutions and find further related documentation.

Since this is keyed off MESSAGE_ID= this will only work for native
journal messages.

The message catalog supports i18n, and is useful to augment english
language system messages with explanations in the local language.

This commit only includes short explanatory messages for a few example
message IDs, we'll add more complete documentation for the relevant
systemd messages later on.
parent 59f432ea
/test-catalog
/test-replace-var
/test-journal-enum
/test-sleep
......
......@@ -78,9 +78,10 @@ systemsleepdir=$(rootlibexecdir)/system-sleep
systemunitdir=$(rootprefix)/lib/systemd/system
systempresetdir=$(rootprefix)/lib/systemd/system-preset
udevlibexecdir=$(rootprefix)/lib/udev
udevhomedir = $(udevlibexecdir)
udevrulesdir = $(udevlibexecdir)/rules.d
udevhwdbdir = $(udevlibexecdir)/hwdb.d
udevhomedir=$(udevlibexecdir)
udevrulesdir=$(udevlibexecdir)/rules.d
udevhwdbdir=$(udevlibexecdir)/hwdb.d
catalogdir=$(prefix)/lib/systemd/catalog
# And these are the special ones for /
rootprefix=@rootprefix@
......@@ -2565,6 +2566,15 @@ test_mmap_cache_LDADD = \
libsystemd-shared.la \
libsystemd-journal-internal.la
test_catalog_SOURCES = \
src/journal/test-catalog.c
test_catalog_LDADD = \
libsystemd-shared.la \
libsystemd-label.la \
libsystemd-journal-internal.la \
libsystemd-id128-internal.la
libsystemd_journal_la_SOURCES = \
src/journal/sd-journal.c \
src/systemd/sd-journal.h \
......@@ -2579,6 +2589,8 @@ libsystemd_journal_la_SOURCES = \
src/journal/journal-send.c \
src/journal/journal-def.h \
src/journal/compress.h \
src/journal/catalog.c \
src/journal/catalog.h \
src/journal/mmap-cache.c \
src/journal/mmap-cache.h
......@@ -2594,6 +2606,7 @@ libsystemd_journal_la_LDFLAGS = \
libsystemd_journal_la_LIBADD = \
libsystemd-shared.la \
libsystemd-label.la \
libsystemd-id128-internal.la
libsystemd_journal_internal_la_SOURCES = \
......@@ -2621,7 +2634,9 @@ libsystemd_journal_internal_la_LIBADD = \
libsystemd-label.la \
libsystemd-audit.la \
libsystemd-daemon.la \
libudev.la
libudev.la \
libsystemd-shared.la \
libsystemd-label.la
nodist_libsystemd_journal_internal_la_SOURCES = \
src/journal/journald-gperf.c
......@@ -2703,7 +2718,8 @@ noinst_PROGRAMS += \
test-journal-enum \
test-journal-stream \
test-journal-verify \
test-mmap-cache
test-mmap-cache \
test-catalog
TESTS += \
test-journal \
......@@ -2747,6 +2763,9 @@ dist_pkgsysconf_DATA += \
pkgconfiglib_DATA += \
src/journal/libsystemd-journal.pc
dist_catalog_DATA = \
catalog/systemd.catalog
journal-install-data-hook:
$(MKDIR_P) -m 0755 \
$(DESTDIR)$(systemunitdir)/sockets.target.wants \
......
-- fc2e22bc6ee647b6b90729ab34a250b1
Subject: Process @COREDUMP_PID@ (@COREDUMP_COMM@) dumped core
Defined-By: systemd
Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Developer-Description: http://www.freedesktop.org/wiki/Software/systemd/catalog/@MESSAGE_ID@
Process @COREDUMP_PID@ (@COREDUMP_COMM@) crashed and dumped core.
This usually indicates a programming error in the crashing program and
should be reported to the vendor as a bug.
-- fc2e22bc6ee647b6b90729ab34a250b1 de
Subject: Speicherabbild für Prozess @COREDUMP_PID@ (@COREDUMP_COMM) generiert
Defined-By: systemd
Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Developer-Description: http://www.freedesktop.org/wiki/Software/systemd/catalog/@MESSAGE_ID@
Prozess @COREDUMP_PID@ (@COREDUMP_COMM@) ist abgebrochen worden und
ein Speicherabbild wurde generiert.
Üblicherweise ist dies ein Hinweis auf einen Programmfehler und sollte
als Fehler dem Hersteller gemeldet werden.
-- c7a787079b354eaaa9e77b371893cd27
Subject: Time change
Defined-By: systemd
Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Developer-Description: http://www.freedesktop.org/wiki/Software/systemd/catalog/@MESSAGE_ID@
The system clock has been changed.
-- c7a787079b354eaaa9e77b371893cd27 de
Subject: Zeitänderung
Defined-By: systemd
Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Developer-Description: http://www.freedesktop.org/wiki/Software/systemd/catalog/@MESSAGE_ID@
Die System-Zeit wurde geändert.
-- 45f82f4aef7a4bbf942ce861d1f20990
Subject: Time zone change
Defined-By: systemd
Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Developer-Description: http://www.freedesktop.org/wiki/Software/systemd/catalog/@MESSAGE_ID@
The system time zone has been changed.
-- f77379a8490b408bbe5f6940505a777b
Subject: The Journal has been started
Defined-By: systemd
Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Developer-Description: http://www.freedesktop.org/wiki/Software/systemd/catalog/@MESSAGE_ID@
The system journal process has been starting up, opened the journal
files for writing and is now ready to process requests.
-- d93fb3c9c24d451a97cea615ce59c00b
Subject: The Journal has been stopped
Defined-By: systemd
Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Developer-Description: http://www.freedesktop.org/wiki/Software/systemd/catalog/@MESSAGE_ID@
The system journal process has shut down and closed all currently
active journal files.
-- fcbefc5da23d428093f97c82a9290f7b
Subject: A new seat @SEAT_ID@ is now available
Defined-By: systemd
Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Developer-Description: http://www.freedesktop.org/wiki/Software/systemd/catalog/@MESSAGE_ID@
A new seat @SEAT_ID@ has been configured and is now available.
-- 8d45620c1a4348dbb17410da57c60c66
Subject: A new session @SESSION_ID@ has been created for user @USER_ID@
Defined-By: systemd
Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Developer-Description: http://www.freedesktop.org/wiki/Software/systemd/catalog/@MESSAGE_ID@
A new session with the ID @SESSION_ID@ has been created for the user @USER_ID@.
The leading process of the session is @LEADER@.
-- a596d6fe7bfa4994828e72309e95d61e
Subject: Messages from a service have been suppressed
Defined-By: systemd
Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Developer-Description: http://www.freedesktop.org/wiki/Software/systemd/catalog/@MESSAGE_ID@
See: man:journald.conf(5)
A service has logged too many messages within a time period. Messages
from the service have been dropped.
Note that only messages from the service in question have been
dropped, other services' messages are unaffected.
The limits when messages are dropped may be configured with
RateLimitInterval= and RateLimitBurst= in
/etc/systemd/journald.conf. See journald.conf(5) for details.
......@@ -232,6 +232,25 @@
even a timestamp.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--catalog</option></term>
<term><option>-x</option></term>
<listitem><para>Augment log lines with
explanation texts from the message
catalog. This will add explanatory
help texts to log messages in the
output where this is available. These
short help texts will explain the
context of an error or log event,
possible solutions, as well as
pointers to support forums, developer
documentation and any other relevant
manuals. Note that help texts are not
available for all messages but only
for selected ones.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--quiet</option></term>
<term><option>-q</option></term>
......@@ -404,6 +423,26 @@
journal files.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--list-catalog</option></term>
<listitem><para>List the contents of
the message catalog, as table of
message IDs plus their short
description strings.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--update-catalog</option></term>
<listitem><para>Update the message
catalog index. This command needs to
be executed each time new catalog
files are installed, removed or
updated to rebuild the binary catalog
index.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--setup-keys</option></term>
......
This diff is collapsed.
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
#pragma once
/***
This file is part of systemd.
Copyright 2012 Lennart Poettering
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "sd-id128.h"
int catalog_update(void);
int catalog_get(sd_id128_t id, char **data);
int catalog_list(FILE *f);
......@@ -51,6 +51,7 @@
#include "journal-qrcode.h"
#include "fsprg.h"
#include "unit-name.h"
#include "catalog.h"
#define DEFAULT_FSS_INTERVAL_USEC (15*USEC_PER_MINUTE)
......@@ -74,6 +75,7 @@ static usec_t arg_since, arg_until;
static bool arg_since_set = false, arg_until_set = false;
static const char *arg_unit = NULL;
static const char *arg_field = NULL;
static bool arg_catalog = false;
static enum {
ACTION_SHOW,
......@@ -82,6 +84,8 @@ static enum {
ACTION_SETUP_KEYS,
ACTION_VERIFY,
ACTION_DISK_USAGE,
ACTION_LIST_CATALOG,
ACTION_UPDATE_CATALOG
} arg_action = ACTION_SHOW;
static int help(void) {
......@@ -100,6 +104,7 @@ static int help(void) {
" --no-tail Show all lines, even in follow mode\n"
" -o --output=STRING Change journal output mode (short, short-monotonic,\n"
" verbose, export, json, json-pretty, json-sse, cat)\n"
" -x --catalog Add message explanations where available\n"
" -a --all Show all fields, including long and unprintable\n"
" -q --quiet Don't show privilege warning\n"
" --no-pager Do not pipe output into a pager\n"
......@@ -116,6 +121,8 @@ static int help(void) {
" --header Show journal header information\n"
" --disk-usage Show total disk usage\n"
" -F --field=FIELD List all values a certain field takes\n"
" --list-catalog Show message IDs of all entries in the message catalog\n"
" --update-catalog Update the message catalog database\n"
#ifdef HAVE_GCRYPT
" --setup-keys Generate new FSS key pair\n"
" --verify Verify journal file consistency\n"
......@@ -139,7 +146,9 @@ static int parse_argv(int argc, char *argv[]) {
ARG_VERIFY_KEY,
ARG_DISK_USAGE,
ARG_SINCE,
ARG_UNTIL
ARG_UNTIL,
ARG_LIST_CATALOG,
ARG_UPDATE_CATALOG
};
static const struct option options[] = {
......@@ -168,6 +177,9 @@ static int parse_argv(int argc, char *argv[]) {
{ "until", required_argument, NULL, ARG_UNTIL },
{ "unit", required_argument, NULL, 'u' },
{ "field", required_argument, NULL, 'F' },
{ "catalog", no_argument, NULL, 'x' },
{ "list-catalog", no_argument, NULL, ARG_LIST_CATALOG },
{ "update-catalog",no_argument, NULL, ARG_UPDATE_CATALOG },
{ NULL, 0, NULL, 0 }
};
......@@ -176,7 +188,7 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
while ((c = getopt_long(argc, argv, "hfo:an::qmbD:p:c:u:F:", options, NULL)) >= 0) {
while ((c = getopt_long(argc, argv, "hfo:an::qmbD:p:c:u:F:x", options, NULL)) >= 0) {
switch (c) {
......@@ -376,6 +388,18 @@ static int parse_argv(int argc, char *argv[]) {
arg_field = optarg;
break;
case 'x':
arg_catalog = true;
break;
case ARG_LIST_CATALOG:
arg_action = ACTION_LIST_CATALOG;
break;
case ARG_UPDATE_CATALOG:
arg_action = ACTION_UPDATE_CATALOG;
break;
default:
log_error("Unknown option code %c", c);
return -EINVAL;
......@@ -841,6 +865,16 @@ int main(int argc, char *argv[]) {
goto finish;
}
if (arg_action == ACTION_LIST_CATALOG) {
r = catalog_list(stdout);
goto finish;
}
if (arg_action == ACTION_UPDATE_CATALOG) {
r = catalog_update();
goto finish;
}
r = access_check();
if (r < 0)
goto finish;
......@@ -1030,7 +1064,8 @@ int main(int argc, char *argv[]) {
flags =
arg_all * OUTPUT_SHOW_ALL |
(!on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
on_tty() * OUTPUT_COLOR;
on_tty() * OUTPUT_COLOR |
arg_catalog * OUTPUT_CATALOG;
r = output_journal(stdout, j, arg_output, 0, flags);
if (r < 0)
......
......@@ -84,4 +84,5 @@ global:
LIBSYSTEMD_JOURNAL_196 {
global:
sd_journal_fd_reliable;
sd_journal_get_catalog;
} LIBSYSTEMD_JOURNAL_195;
......@@ -38,11 +38,15 @@
#include "compress.h"
#include "journal-internal.h"
#include "missing.h"
#include "catalog.h"
#include "replace-var.h"
#define JOURNAL_FILES_MAX 1024
#define JOURNAL_FILES_RECHECK_USEC (2 * USEC_PER_SEC)
#define REPLACE_VAR_MAX 256
static void detach_location(sd_journal *j) {
Iterator i;
JournalFile *f;
......@@ -2389,3 +2393,59 @@ _public_ int sd_journal_reliable_fd(sd_journal *j) {
return !j->on_network;
}
static char *lookup_field(const char *field, void *userdata) {
sd_journal *j = userdata;
const void *data;
size_t size, d;
int r;
assert(field);
assert(j);
r = sd_journal_get_data(j, field, &data, &size);
if (r < 0 ||
size > REPLACE_VAR_MAX)
return strdup(field);
d = strlen(field) + 1;
return strndup((const char*) data + d, size - d);
}
_public_ int sd_journal_get_catalog(sd_journal *j, char **ret) {
const void *data;
size_t size;
sd_id128_t id;
_cleanup_free_ char *text = NULL, *cid = NULL;
char *t;
int r;
if (!j)
return -EINVAL;
if (!ret)
return -EINVAL;
r = sd_journal_get_data(j, "MESSAGE_ID", &data, &size);
if (r < 0)
return r;
cid = strndup((const char*) data + 11, size - 11);
if (!cid)
return -ENOMEM;
r = sd_id128_from_string(cid, &id);
if (r < 0)
return r;
r = catalog_get(id, &text);
if (r < 0)
return r;
t = replace_var(text, lookup_field, j);
if (!t)
return -ENOMEM;
*ret = t;
return 0;
}
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2012 Lennart Poettering
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <locale.h>
#include "util.h"
#include "log.h"
#include "catalog.h"
#include "sd-messages.h"
int main(int argc, char *argv[]) {
_cleanup_free_ char *text = NULL;
setlocale(LC_ALL, "de_DE.UTF-8");
log_set_max_level(LOG_DEBUG);
assert_se(catalog_update() >= 0);
assert_se(catalog_list(stdout) >= 0);
assert_se(catalog_get(SD_MESSAGE_COREDUMP, &text) >= 0);
printf(">>>%s<<<\n", text);
fflush(stdout);
return 0;
}
......@@ -34,6 +34,26 @@
#define PRINT_THRESHOLD 128
#define JSON_THRESHOLD 4096
static int print_catalog(FILE *f, sd_journal *j) {
int r;
_cleanup_free_ char *t = NULL, *z = NULL;
r = sd_journal_get_catalog(j, &t);
if (r < 0)
return r;
z = strreplace(strstrip(t), "\n", "\n-- ");
if (!z)
return log_oom();
fputs("-- ", f);
fputs(z, f);
fputc('\n', f);
return 0;
}
static int parse_field(const void *data, size_t length, const char *field, char **target, size_t *target_size) {
size_t fl, nl;
void *buf;
......@@ -265,6 +285,9 @@ static int output_short(
} else
fputs("\n", f);
if (flags & OUTPUT_CATALOG)
print_catalog(f, j);
return 0;
}
......@@ -322,6 +345,9 @@ static int output_verbose(
fprintf(f, "\t%.*s\n", (int) length, (const char*) data);
}
if (flags & OUTPUT_CATALOG)
print_catalog(f, j);
return 0;
}
......
......@@ -45,7 +45,8 @@ typedef enum OutputFlags {
OUTPUT_FOLLOW = 1 << 1,
OUTPUT_WARN_CUTOFF = 1 << 2,
OUTPUT_FULL_WIDTH = 1 << 3,
OUTPUT_COLOR = 1 << 4
OUTPUT_COLOR = 1 << 4,
OUTPUT_CATALOG = 1 << 5
} OutputFlags;
int output_journal(
......
......@@ -128,6 +128,8 @@ int sd_journal_reliable_fd(sd_journal *j);
int sd_journal_process(sd_journal *j);
int sd_journal_wait(sd_journal *j, uint64_t timeout_usec);
int sd_journal_get_catalog(sd_journal *j, char **text);
#define SD_JOURNAL_FOREACH(j) \
if (sd_journal_seek_head(j) >= 0) \
while (sd_journal_next(j) > 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment