mirror of
https://github.com/systemd/systemd.git
synced 2025-05-29 01:05:59 +03:00
logs-show: show seqnum info in export+json output mode
This commit is contained in:
parent
b1712fabd1
commit
2bc70e2e9d
@ -14,6 +14,7 @@
|
|||||||
#include "journal-util.h"
|
#include "journal-util.h"
|
||||||
#include "parse-util.h"
|
#include "parse-util.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
|
#include "strv.h"
|
||||||
#include "unaligned.h"
|
#include "unaligned.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -217,9 +218,8 @@ static int process_special_field(JournalImporter *imp, char *line) {
|
|||||||
|
|
||||||
assert(line);
|
assert(line);
|
||||||
|
|
||||||
value = startswith(line, "__CURSOR=");
|
if (STARTSWITH_SET(line, "__CURSOR=", "__SEQNUM=", "__SEQNUM_ID="))
|
||||||
if (value)
|
/* ignore __CURSOR=, __SEQNUM=, __SEQNUM_ID= which we cannot replicate */
|
||||||
/* ignore __CURSOR */
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
value = startswith(line, "__REALTIME_TIMESTAMP=");
|
value = startswith(line, "__REALTIME_TIMESTAMP=");
|
||||||
|
@ -791,11 +791,12 @@ static int output_export(
|
|||||||
const dual_timestamp *previous_display_ts,
|
const dual_timestamp *previous_display_ts,
|
||||||
const sd_id128_t *previous_boot_id) {
|
const sd_id128_t *previous_boot_id) {
|
||||||
|
|
||||||
|
sd_id128_t journal_boot_id, seqnum_id;
|
||||||
_cleanup_free_ char *cursor = NULL;
|
_cleanup_free_ char *cursor = NULL;
|
||||||
const void *data;
|
|
||||||
size_t length;
|
|
||||||
usec_t monotonic, realtime;
|
usec_t monotonic, realtime;
|
||||||
sd_id128_t journal_boot_id;
|
const void *data;
|
||||||
|
uint64_t seqnum;
|
||||||
|
size_t length;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(j);
|
assert(j);
|
||||||
@ -818,14 +819,22 @@ static int output_export(
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to get monotonic timestamp: %m");
|
return log_error_errno(r, "Failed to get monotonic timestamp: %m");
|
||||||
|
|
||||||
|
r = sd_journal_get_seqnum(j, &seqnum, &seqnum_id);
|
||||||
|
if (r < 0)
|
||||||
|
return log_error_errno(r, "Failed to get seqnum: %m");
|
||||||
|
|
||||||
fprintf(f,
|
fprintf(f,
|
||||||
"__CURSOR=%s\n"
|
"__CURSOR=%s\n"
|
||||||
"__REALTIME_TIMESTAMP="USEC_FMT"\n"
|
"__REALTIME_TIMESTAMP=" USEC_FMT "\n"
|
||||||
"__MONOTONIC_TIMESTAMP="USEC_FMT"\n"
|
"__MONOTONIC_TIMESTAMP=" USEC_FMT "\n"
|
||||||
|
"__SEQNUM=%" PRIu64 "\n"
|
||||||
|
"__SEQNUM_ID=%s\n"
|
||||||
"_BOOT_ID=%s\n",
|
"_BOOT_ID=%s\n",
|
||||||
cursor,
|
cursor,
|
||||||
realtime,
|
realtime,
|
||||||
monotonic,
|
monotonic,
|
||||||
|
seqnum,
|
||||||
|
SD_ID128_TO_STRING(seqnum_id),
|
||||||
SD_ID128_TO_STRING(journal_boot_id));
|
SD_ID128_TO_STRING(journal_boot_id));
|
||||||
|
|
||||||
JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
|
JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
|
||||||
@ -1040,15 +1049,16 @@ static int output_json(
|
|||||||
const dual_timestamp *previous_display_ts,
|
const dual_timestamp *previous_display_ts,
|
||||||
const sd_id128_t *previous_boot_id) {
|
const sd_id128_t *previous_boot_id) {
|
||||||
|
|
||||||
char usecbuf[DECIMAL_STR_MAX(usec_t)];
|
char usecbuf[CONST_MAX(DECIMAL_STR_MAX(usec_t), DECIMAL_STR_MAX(uint64_t))];
|
||||||
_cleanup_(json_variant_unrefp) JsonVariant *object = NULL;
|
_cleanup_(json_variant_unrefp) JsonVariant *object = NULL;
|
||||||
|
sd_id128_t journal_boot_id, seqnum_id;
|
||||||
_cleanup_free_ char *cursor = NULL;
|
_cleanup_free_ char *cursor = NULL;
|
||||||
|
usec_t realtime, monotonic;
|
||||||
JsonVariant **array = NULL;
|
JsonVariant **array = NULL;
|
||||||
struct json_data *d;
|
struct json_data *d;
|
||||||
Hashmap *h = NULL;
|
Hashmap *h = NULL;
|
||||||
|
uint64_t seqnum;
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
usec_t realtime, monotonic;
|
|
||||||
sd_id128_t journal_boot_id;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(j);
|
assert(j);
|
||||||
@ -1071,6 +1081,10 @@ static int output_json(
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to get monotonic timestamp: %m");
|
return log_error_errno(r, "Failed to get monotonic timestamp: %m");
|
||||||
|
|
||||||
|
r = sd_journal_get_seqnum(j, &seqnum, &seqnum_id);
|
||||||
|
if (r < 0)
|
||||||
|
return log_error_errno(r, "Failed to get seqnum: %m");
|
||||||
|
|
||||||
h = hashmap_new(&string_hash_ops);
|
h = hashmap_new(&string_hash_ops);
|
||||||
if (!h)
|
if (!h)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
@ -1093,6 +1107,15 @@ static int output_json(
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
|
xsprintf(usecbuf, USEC_FMT, seqnum);
|
||||||
|
r = update_json_data(h, flags, "__SEQNUM", usecbuf, SIZE_MAX);
|
||||||
|
if (r < 0)
|
||||||
|
goto finish;
|
||||||
|
|
||||||
|
r = update_json_data(h, flags, "__SEQNUM_ID", SD_ID128_TO_STRING(seqnum_id), SIZE_MAX);
|
||||||
|
if (r < 0)
|
||||||
|
goto finish;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const void *data;
|
const void *data;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
@ -70,7 +70,7 @@ ID=$(journalctl --new-id128 | sed -n 2p)
|
|||||||
printf $'foo' | systemd-cat -t "$ID" --level-prefix false
|
printf $'foo' | systemd-cat -t "$ID" --level-prefix false
|
||||||
journalctl --sync
|
journalctl --sync
|
||||||
journalctl -b -o export --output-fields=MESSAGE,FOO --output-fields=PRIORITY,MESSAGE -t "$ID" >/output
|
journalctl -b -o export --output-fields=MESSAGE,FOO --output-fields=PRIORITY,MESSAGE -t "$ID" >/output
|
||||||
[[ $(grep -c . /output) -eq 6 ]]
|
[[ $(grep -c . /output) -eq 8 ]]
|
||||||
grep -q '^__CURSOR=' /output
|
grep -q '^__CURSOR=' /output
|
||||||
grep -q '^MESSAGE=foo$' /output
|
grep -q '^MESSAGE=foo$' /output
|
||||||
grep -q '^PRIORITY=6$' /output
|
grep -q '^PRIORITY=6$' /output
|
||||||
|
Loading…
x
Reference in New Issue
Block a user