[systemd-devel] [PATCH] journalctl: add ”short-iso” output format with verbose ISO8601 timestamps
Tomasz Torcz
tomek at pipebreaker.pl
Thu Jul 18 01:21:45 PDT 2013
Example:
2013-07-18T10:10:01+0200 sandworm CROND[20957]: (root) CMD (/usr/lib64/sa/sa1 1 1)
---
man/journalctl.xml | 12 ++++++++++++
src/journal/journalctl.c | 2 +-
src/shared/logs-show.c | 10 +++++++++-
src/shared/output-mode.h | 1 +
4 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/man/journalctl.xml b/man/journalctl.xml
index 65a59ea..da43bf2 100644
--- a/man/journalctl.xml
+++ b/man/journalctl.xml
@@ -266,6 +266,18 @@
<varlistentry>
<term>
+ <option>short-iso</option>
+ </term>
+ <listitem>
+ <para>is very similar
+ but shows ISO 8601
+ wallclock timestamps.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
<option>verbose</option>
</term>
<listitem>
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 9a40d69..9dbe15a 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -133,7 +133,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"
" -r --reverse Show the newest entries first\n"
- " -o --output=STRING Change journal output mode (short, short-monotonic,\n"
+ " -o --output=STRING Change journal output mode (short, short-monotonic, short-iso\n"
" verbose, export, json, json-pretty, json-sse, cat)\n"
" -x --catalog Add message explanations where available\n"
" -l --full Do not ellipsize fields\n"
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index ea47468..353fd2b 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -258,6 +258,7 @@ static int output_short(
uint64_t x;
time_t t;
struct tm tm;
+ const char *timestamp_format;
r = -ENOENT;
@@ -272,8 +273,13 @@ static int output_short(
return r;
}
+ if (mode == OUTPUT_SHORT_ISO)
+ timestamp_format = "%Y-%m-%dT%H:%M:%S%z";
+ else
+ timestamp_format = "%b %d %H:%M:%S";
+
t = (time_t) (x / USEC_PER_SEC);
- if (strftime(buf, sizeof(buf), "%b %d %H:%M:%S", localtime_r(&t, &tm)) <= 0) {
+ if (strftime(buf, sizeof(buf), timestamp_format, localtime_r(&t, &tm)) <= 0) {
log_error("Failed to format time.");
return r;
}
@@ -798,6 +804,7 @@ static int (*output_funcs[_OUTPUT_MODE_MAX])(
[OUTPUT_SHORT] = output_short,
[OUTPUT_SHORT_MONOTONIC] = output_short,
+ [OUTPUT_SHORT_ISO] = output_short,
[OUTPUT_VERBOSE] = output_verbose,
[OUTPUT_EXPORT] = output_export,
[OUTPUT_JSON] = output_json,
@@ -1076,6 +1083,7 @@ int show_journal_by_unit(
static const char *const output_mode_table[_OUTPUT_MODE_MAX] = {
[OUTPUT_SHORT] = "short",
[OUTPUT_SHORT_MONOTONIC] = "short-monotonic",
+ [OUTPUT_SHORT_ISO] = "short-iso",
[OUTPUT_VERBOSE] = "verbose",
[OUTPUT_EXPORT] = "export",
[OUTPUT_JSON] = "json",
diff --git a/src/shared/output-mode.h b/src/shared/output-mode.h
index 0efd430..4012889 100644
--- a/src/shared/output-mode.h
+++ b/src/shared/output-mode.h
@@ -24,6 +24,7 @@
typedef enum OutputMode {
OUTPUT_SHORT,
OUTPUT_SHORT_MONOTONIC,
+ OUTPUT_SHORT_ISO,
OUTPUT_VERBOSE,
OUTPUT_EXPORT,
OUTPUT_JSON,
--
1.8.3.1
More information about the systemd-devel
mailing list