mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
journalctl: make --utc work everywhere
The --utc option was introduced by commit
9fd290443f
.
Howerver, the implementation was incomplete.
This commit is contained in:
parent
1c92ff85b7
commit
a62e83b48c
@ -890,8 +890,8 @@ static int list_boots(sd_journal *j) {
|
|||||||
printf("% *i " SD_ID128_FORMAT_STR " %s—%s\n",
|
printf("% *i " SD_ID128_FORMAT_STR " %s—%s\n",
|
||||||
w, i - count + 1,
|
w, i - count + 1,
|
||||||
SD_ID128_FORMAT_VAL(id->id),
|
SD_ID128_FORMAT_VAL(id->id),
|
||||||
format_timestamp(a, sizeof(a), id->first),
|
format_timestamp_internal(a, sizeof(a), id->first, arg_utc),
|
||||||
format_timestamp(b, sizeof(b), id->last));
|
format_timestamp_internal(b, sizeof(b), id->last, arg_utc));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1502,8 +1502,8 @@ static int verify(sd_journal *j) {
|
|||||||
if (arg_verify_key && JOURNAL_HEADER_SEALED(f->header)) {
|
if (arg_verify_key && JOURNAL_HEADER_SEALED(f->header)) {
|
||||||
if (validated > 0) {
|
if (validated > 0) {
|
||||||
log_info("=> Validated from %s to %s, final %s entries not sealed.",
|
log_info("=> Validated from %s to %s, final %s entries not sealed.",
|
||||||
format_timestamp(a, sizeof(a), first),
|
format_timestamp_internal(a, sizeof(a), first, arg_utc),
|
||||||
format_timestamp(b, sizeof(b), validated),
|
format_timestamp_internal(b, sizeof(b), validated, arg_utc),
|
||||||
format_timespan(c, sizeof(c), last > validated ? last - validated : 0, 0));
|
format_timespan(c, sizeof(c), last > validated ? last - validated : 0, 0));
|
||||||
} else if (last > 0)
|
} else if (last > 0)
|
||||||
log_info("=> No sealing yet, %s of entries not sealed.",
|
log_info("=> No sealing yet, %s of entries not sealed.",
|
||||||
@ -1898,11 +1898,11 @@ int main(int argc, char *argv[]) {
|
|||||||
if (r > 0) {
|
if (r > 0) {
|
||||||
if (arg_follow)
|
if (arg_follow)
|
||||||
printf("-- Logs begin at %s. --\n",
|
printf("-- Logs begin at %s. --\n",
|
||||||
format_timestamp(start_buf, sizeof(start_buf), start));
|
format_timestamp_internal(start_buf, sizeof(start_buf), start, arg_utc));
|
||||||
else
|
else
|
||||||
printf("-- Logs begin at %s, end at %s. --\n",
|
printf("-- Logs begin at %s, end at %s. --\n",
|
||||||
format_timestamp(start_buf, sizeof(start_buf), start),
|
format_timestamp_internal(start_buf, sizeof(start_buf), start, arg_utc),
|
||||||
format_timestamp(end_buf, sizeof(end_buf), end));
|
format_timestamp_internal(end_buf, sizeof(end_buf), end, arg_utc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,7 +447,7 @@ static int output_verbose(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fprintf(f, "%s [%s]\n",
|
fprintf(f, "%s [%s]\n",
|
||||||
format_timestamp_us(ts, sizeof(ts), realtime),
|
format_timestamp_us(ts, sizeof(ts), realtime, flags & OUTPUT_UTC),
|
||||||
cursor);
|
cursor);
|
||||||
|
|
||||||
JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
|
JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
|
||||||
|
@ -152,7 +152,7 @@ struct timeval *timeval_store(struct timeval *tv, usec_t u) {
|
|||||||
return tv;
|
return tv;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *format_timestamp(char *buf, size_t l, usec_t t) {
|
char *format_timestamp_internal(char *buf, size_t l, usec_t t, bool utc) {
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
time_t sec;
|
time_t sec;
|
||||||
|
|
||||||
@ -164,13 +164,21 @@ char *format_timestamp(char *buf, size_t l, usec_t t) {
|
|||||||
|
|
||||||
sec = (time_t) (t / USEC_PER_SEC);
|
sec = (time_t) (t / USEC_PER_SEC);
|
||||||
|
|
||||||
if (strftime(buf, l, "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&sec, &tm)) <= 0)
|
if (utc)
|
||||||
|
gmtime_r(&sec, &tm);
|
||||||
|
else
|
||||||
|
localtime_r(&sec, &tm);
|
||||||
|
if (strftime(buf, l, "%a %Y-%m-%d %H:%M:%S %Z", &tm) <= 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *format_timestamp_us(char *buf, size_t l, usec_t t) {
|
char *format_timestamp(char *buf, size_t l, usec_t t) {
|
||||||
|
return format_timestamp_internal(buf, l, t, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *format_timestamp_us(char *buf, size_t l, usec_t t, bool utc) {
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
time_t sec;
|
time_t sec;
|
||||||
|
|
||||||
@ -181,6 +189,9 @@ char *format_timestamp_us(char *buf, size_t l, usec_t t) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
sec = (time_t) (t / USEC_PER_SEC);
|
sec = (time_t) (t / USEC_PER_SEC);
|
||||||
|
if (utc)
|
||||||
|
gmtime_r(&sec, &tm);
|
||||||
|
else
|
||||||
localtime_r(&sec, &tm);
|
localtime_r(&sec, &tm);
|
||||||
|
|
||||||
if (strftime(buf, l, "%a %Y-%m-%d %H:%M:%S", &tm) <= 0)
|
if (strftime(buf, l, "%a %Y-%m-%d %H:%M:%S", &tm) <= 0)
|
||||||
|
@ -84,8 +84,9 @@ struct timespec *timespec_store(struct timespec *ts, usec_t u);
|
|||||||
usec_t timeval_load(const struct timeval *tv) _pure_;
|
usec_t timeval_load(const struct timeval *tv) _pure_;
|
||||||
struct timeval *timeval_store(struct timeval *tv, usec_t u);
|
struct timeval *timeval_store(struct timeval *tv, usec_t u);
|
||||||
|
|
||||||
|
char *format_timestamp_internal(char *buf, size_t l, usec_t t, bool utc);
|
||||||
char *format_timestamp(char *buf, size_t l, usec_t t);
|
char *format_timestamp(char *buf, size_t l, usec_t t);
|
||||||
char *format_timestamp_us(char *buf, size_t l, usec_t t);
|
char *format_timestamp_us(char *buf, size_t l, usec_t t, bool utc);
|
||||||
char *format_timestamp_relative(char *buf, size_t l, usec_t t);
|
char *format_timestamp_relative(char *buf, size_t l, usec_t t);
|
||||||
char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy);
|
char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user