chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
33316db
)
journal: support epxorting the journal in a format suitable for text/event-stream
author
Lennart Poettering
<lennart@poettering.net>
Thu, 11 Oct 2012 00:37:10 +0000
(
02:37
+0200)
committer
Lennart Poettering
<lennart@poettering.net>
Thu, 11 Oct 2012 00:37:10 +0000
(
02:37
+0200)
man/journalctl.xml
patch
|
blob
|
history
src/journal/journal-gatewayd.c
patch
|
blob
|
history
src/journal/journalctl.c
patch
|
blob
|
history
src/shared/logs-show.c
patch
|
blob
|
history
src/shared/logs-show.h
patch
|
blob
|
history
src/systemctl/systemctl.c
patch
|
blob
|
history
diff --git
a/man/journalctl.xml
b/man/journalctl.xml
index 651a8a56ad99bc6c9c9ad07ae86f230ebb416579..62373d88aba1486c2293990053d384c1f39c64d1 100644
(file)
--- a/
man/journalctl.xml
+++ b/
man/journalctl.xml
@@
-193,6
+193,7
@@
<literal>export</literal>,
<literal>json</literal>,
<literal>json-pretty</literal>,
<literal>export</literal>,
<literal>json</literal>,
<literal>json-pretty</literal>,
+ <literal>json-sse</literal>,
<literal>cat</literal>. <literal>short</literal>
is the default and generates an output
that is mostly identical to the
<literal>cat</literal>. <literal>short</literal>
is the default and generates an output
that is mostly identical to the
@@
-219,7
+220,12
@@
structures, but formats them in
multiple lines in order to make them
more readable for
structures, but formats them in
multiple lines in order to make them
more readable for
- humans. <literal>cat</literal>
+ humans. <literal>json-sse</literal>
+ also formats entries as JSON data
+ structures, but wraps them in a format
+ suitable for <ulink
+ url="https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events">Server-Sent
+ Events</ulink>. <literal>cat</literal>
generates a very terse output only
showing the actual message of each
journal entry with no meta data, not
generates a very terse output only
showing the actual message of each
journal entry with no meta data, not
diff --git
a/src/journal/journal-gatewayd.c
b/src/journal/journal-gatewayd.c
index 33dda266b6a31f049a1e286889fc64db5e427126..b2d4abf4fee705a2757fbc7611ff6c17ccfe63e1 100644
(file)
--- a/
src/journal/journal-gatewayd.c
+++ b/
src/journal/journal-gatewayd.c
@@
-55,7
+55,8
@@
typedef struct RequestMeta {
static const char* const mime_types[_OUTPUT_MODE_MAX] = {
[OUTPUT_SHORT] = "text/plain",
[OUTPUT_JSON] = "application/json",
static const char* const mime_types[_OUTPUT_MODE_MAX] = {
[OUTPUT_SHORT] = "text/plain",
[OUTPUT_JSON] = "application/json",
- [OUTPUT_EXPORT] = "application/vnd.fdo.journal"
+ [OUTPUT_JSON_SSE] = "text/event-stream",
+ [OUTPUT_EXPORT] = "application/vnd.fdo.journal",
};
static RequestMeta *request_meta(void **connection_cls) {
};
static RequestMeta *request_meta(void **connection_cls) {
@@
-286,6
+287,8
@@
static int request_parse_accept(
if (streq(accept, mime_types[OUTPUT_JSON]))
m->mode = OUTPUT_JSON;
if (streq(accept, mime_types[OUTPUT_JSON]))
m->mode = OUTPUT_JSON;
+ else if (streq(accept, mime_types[OUTPUT_JSON_SSE]))
+ m->mode = OUTPUT_JSON_SSE;
else if (streq(accept, mime_types[OUTPUT_EXPORT]))
m->mode = OUTPUT_EXPORT;
else
else if (streq(accept, mime_types[OUTPUT_EXPORT]))
m->mode = OUTPUT_EXPORT;
else
diff --git
a/src/journal/journalctl.c
b/src/journal/journalctl.c
index ec05c160be5523bc37756606710c4b701178f90f..04cebff547e4164ec4b3b2c8dbc9fedb2e2034c8 100644
(file)
--- a/
src/journal/journalctl.c
+++ b/
src/journal/journalctl.c
@@
-93,7
+93,7
@@
static int help(void) {
" -n --lines[=INTEGER] Number of journal entries to show\n"
" --no-tail Show all lines, even in follow mode\n"
" -o --output=STRING Change journal output mode (short, short-monotonic,\n"
" -n --lines[=INTEGER] Number of journal entries to show\n"
" --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, cat)\n"
+ " verbose, export, json, json-pretty,
json-sse,
cat)\n"
" -q --quiet Don't show privilege warning\n"
" -m --merge Show entries from all available journals\n"
" -b --this-boot Show data only from current boot\n"
" -q --quiet Don't show privilege warning\n"
" -m --merge Show entries from all available journals\n"
" -b --this-boot Show data only from current boot\n"
diff --git
a/src/shared/logs-show.c
b/src/shared/logs-show.c
index 725adb6451542cb00a188be78a58d3d841e84375..28d12d3d4a6798b4b4b6e86b7cecc7edac47d8ec 100644
(file)
--- a/
src/shared/logs-show.c
+++ b/
src/shared/logs-show.c
@@
-502,7
+502,10
@@
static int output_json(
(unsigned long long) realtime,
(unsigned long long) monotonic,
sd_id128_to_string(boot_id, sid));
(unsigned long long) realtime,
(unsigned long long) monotonic,
sd_id128_to_string(boot_id, sid));
- else
+ else {
+ if (mode == OUTPUT_JSON_SSE)
+ fputs("data: ", f);
+
fprintf(f,
"{ \"__CURSOR\" : \"%s\", "
"\"__REALTIME_TIMESTAMP\" : \"%llu\", "
fprintf(f,
"{ \"__CURSOR\" : \"%s\", "
"\"__REALTIME_TIMESTAMP\" : \"%llu\", "
@@
-512,6
+515,7
@@
static int output_json(
(unsigned long long) realtime,
(unsigned long long) monotonic,
sd_id128_to_string(boot_id, sid));
(unsigned long long) realtime,
(unsigned long long) monotonic,
sd_id128_to_string(boot_id, sid));
+ }
free(cursor);
SD_JOURNAL_FOREACH_DATA(j, data, length) {
free(cursor);
SD_JOURNAL_FOREACH_DATA(j, data, length) {
@@
-541,6
+545,8
@@
static int output_json(
if (mode == OUTPUT_JSON_PRETTY)
fputs("\n}\n", f);
if (mode == OUTPUT_JSON_PRETTY)
fputs("\n}\n", f);
+ else if (mode == OUTPUT_JSON_SSE)
+ fputs("}\n\n", f);
else
fputs(" }\n", f);
else
fputs(" }\n", f);
@@
-592,6
+598,7
@@
static int (*output_funcs[_OUTPUT_MODE_MAX])(
[OUTPUT_EXPORT] = output_export,
[OUTPUT_JSON] = output_json,
[OUTPUT_JSON_PRETTY] = output_json,
[OUTPUT_EXPORT] = output_export,
[OUTPUT_JSON] = output_json,
[OUTPUT_JSON_PRETTY] = output_json,
+ [OUTPUT_JSON_SSE] = output_json,
[OUTPUT_CAT] = output_cat
};
[OUTPUT_CAT] = output_cat
};
@@
-769,6
+776,7
@@
static const char *const output_mode_table[_OUTPUT_MODE_MAX] = {
[OUTPUT_EXPORT] = "export",
[OUTPUT_JSON] = "json",
[OUTPUT_JSON_PRETTY] = "json-pretty",
[OUTPUT_EXPORT] = "export",
[OUTPUT_JSON] = "json",
[OUTPUT_JSON_PRETTY] = "json-pretty",
+ [OUTPUT_JSON_SSE] = "json-sse",
[OUTPUT_CAT] = "cat"
};
[OUTPUT_CAT] = "cat"
};
diff --git
a/src/shared/logs-show.h
b/src/shared/logs-show.h
index ea0f51fbf048c147366fdd3206dfb135f9e31622..1b67876d8f6d58f1861413894a7d8e9f15de3985 100644
(file)
--- a/
src/shared/logs-show.h
+++ b/
src/shared/logs-show.h
@@
-34,6
+34,7
@@
typedef enum OutputMode {
OUTPUT_EXPORT,
OUTPUT_JSON,
OUTPUT_JSON_PRETTY,
OUTPUT_EXPORT,
OUTPUT_JSON,
OUTPUT_JSON_PRETTY,
+ OUTPUT_JSON_SSE,
OUTPUT_CAT,
_OUTPUT_MODE_MAX,
_OUTPUT_MODE_INVALID = -1
OUTPUT_CAT,
_OUTPUT_MODE_MAX,
_OUTPUT_MODE_INVALID = -1
diff --git
a/src/systemctl/systemctl.c
b/src/systemctl/systemctl.c
index a4290c4754939d9f4fa0419b2dad2a847b88c795..d1fbb78e634317bda8c3ee059ebccf529a3243be 100644
(file)
--- a/
src/systemctl/systemctl.c
+++ b/
src/systemctl/systemctl.c
@@
-3939,7
+3939,7
@@
static int systemctl_help(void) {
" -n --lines=INTEGER Journal entries to show\n"
" --follow Follow journal\n"
" -o --output=STRING Change journal output mode (short, short-monotonic,\n"
" -n --lines=INTEGER Journal entries to show\n"
" --follow Follow journal\n"
" -o --output=STRING Change journal output mode (short, short-monotonic,\n"
- " verbose, export, json, json-pretty, cat)\n\n"
+ " verbose, export, json, json-pretty,
json-sse,
cat)\n\n"
"Unit Commands:\n"
" list-units List loaded units\n"
" start [NAME...] Start (activate) one or more units\n"
"Unit Commands:\n"
" list-units List loaded units\n"
" start [NAME...] Start (activate) one or more units\n"