mirror of
https://github.com/systemd/systemd.git
synced 2024-12-01 06:13:38 +08:00
journalctl: add output mode where time is shown in seconds since 1st Jan 1970 UTC
aka "UNIX time". Fixes: #2120
This commit is contained in:
parent
766cd08152
commit
bb321ed9a3
@ -270,6 +270,16 @@
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>
|
||||
<option>short-unix</option>
|
||||
</term>
|
||||
<listitem>
|
||||
<para>is very similar, but shows seconds passed since January 1st 1970 UTC instead of wallclock
|
||||
timestamps ("UNIX time"). The time is shown with microsecond accuracy.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>
|
||||
<option>verbose</option>
|
||||
|
@ -344,16 +344,22 @@ static int output_short(
|
||||
|
||||
t = (time_t) (x / USEC_PER_SEC);
|
||||
|
||||
switch(mode) {
|
||||
switch (mode) {
|
||||
|
||||
case OUTPUT_SHORT_UNIX:
|
||||
r = snprintf(buf, sizeof(buf), "%10llu.%06llu", (unsigned long long) t, (unsigned long long) (x % USEC_PER_SEC));
|
||||
break;
|
||||
|
||||
case OUTPUT_SHORT_ISO:
|
||||
r = strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S%z", gettime_r(&t, &tm));
|
||||
break;
|
||||
|
||||
case OUTPUT_SHORT_PRECISE:
|
||||
r = strftime(buf, sizeof(buf), "%b %d %H:%M:%S", gettime_r(&t, &tm));
|
||||
if (r > 0)
|
||||
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
|
||||
".%06llu", (unsigned long long) (x % USEC_PER_SEC));
|
||||
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ".%06llu", (unsigned long long) (x % USEC_PER_SEC));
|
||||
break;
|
||||
|
||||
default:
|
||||
r = strftime(buf, sizeof(buf), "%b %d %H:%M:%S", gettime_r(&t, &tm));
|
||||
}
|
||||
@ -894,6 +900,7 @@ static int (*output_funcs[_OUTPUT_MODE_MAX])(
|
||||
[OUTPUT_SHORT_ISO] = output_short,
|
||||
[OUTPUT_SHORT_PRECISE] = output_short,
|
||||
[OUTPUT_SHORT_MONOTONIC] = output_short,
|
||||
[OUTPUT_SHORT_UNIX] = output_short,
|
||||
[OUTPUT_VERBOSE] = output_verbose,
|
||||
[OUTPUT_EXPORT] = output_export,
|
||||
[OUTPUT_JSON] = output_json,
|
||||
|
@ -25,6 +25,7 @@ static const char *const output_mode_table[_OUTPUT_MODE_MAX] = {
|
||||
[OUTPUT_SHORT_ISO] = "short-iso",
|
||||
[OUTPUT_SHORT_PRECISE] = "short-precise",
|
||||
[OUTPUT_SHORT_MONOTONIC] = "short-monotonic",
|
||||
[OUTPUT_SHORT_UNIX] = "short-unix",
|
||||
[OUTPUT_VERBOSE] = "verbose",
|
||||
[OUTPUT_EXPORT] = "export",
|
||||
[OUTPUT_JSON] = "json",
|
||||
|
@ -26,6 +26,7 @@ typedef enum OutputMode {
|
||||
OUTPUT_SHORT_ISO,
|
||||
OUTPUT_SHORT_PRECISE,
|
||||
OUTPUT_SHORT_MONOTONIC,
|
||||
OUTPUT_SHORT_UNIX,
|
||||
OUTPUT_VERBOSE,
|
||||
OUTPUT_EXPORT,
|
||||
OUTPUT_JSON,
|
||||
|
Loading…
Reference in New Issue
Block a user