" -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, short-iso\n"
- " verbose, export, json, json-pretty, json-sse, cat)\n"
+ " -o --output=STRING Change journal output mode (short, short-iso,\n"
+ " short-precise, short-monotonic, verbose,\n"
+ " export, json, json-pretty, json-sse, cat)\n"
" -x --catalog Add message explanations where available\n"
" -l --full Do not ellipsize fields\n"
" -a --all Show all fields, including long and unprintable\n"
}
t = (time_t) (x / USEC_PER_SEC);
- if (mode == OUTPUT_SHORT_ISO)
+
+ switch(mode) {
+ case OUTPUT_SHORT_ISO:
r = strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S%z", localtime_r(&t, &tm));
- else
+ break;
+ case OUTPUT_SHORT_PRECISE:
+ r = strftime(buf, sizeof(buf), "%b %d %H:%M:%S", localtime_r(&t, &tm));
+ if (r > 0) {
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
+ ".%06llu", x % USEC_PER_SEC);
+ }
+ break;
+ default:
r = strftime(buf, sizeof(buf), "%b %d %H:%M:%S", localtime_r(&t, &tm));
+ }
if (r <= 0) {
log_error("Failed to format time.");
size_t length;
_cleanup_free_ char *cursor = NULL;
uint64_t realtime;
- char ts[FORMAT_TIMESTAMP_MAX];
+ char ts[FORMAT_TIMESTAMP_MAX + 7];
int r;
assert(f);
}
fprintf(f, "%s [%s]\n",
- format_timestamp(ts, sizeof(ts), realtime),
+ format_timestamp_us(ts, sizeof(ts), realtime),
cursor);
JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
OutputFlags flags) = {
[OUTPUT_SHORT] = output_short,
- [OUTPUT_SHORT_MONOTONIC] = output_short,
[OUTPUT_SHORT_ISO] = output_short,
+ [OUTPUT_SHORT_PRECISE] = output_short,
+ [OUTPUT_SHORT_MONOTONIC] = output_short,
[OUTPUT_VERBOSE] = output_verbose,
[OUTPUT_EXPORT] = output_export,
[OUTPUT_JSON] = output_json,
static const char *const output_mode_table[_OUTPUT_MODE_MAX] = {
[OUTPUT_SHORT] = "short",
- [OUTPUT_SHORT_MONOTONIC] = "short-monotonic",
[OUTPUT_SHORT_ISO] = "short-iso",
+ [OUTPUT_SHORT_PRECISE] = "short-precise",
+ [OUTPUT_SHORT_MONOTONIC] = "short-monotonic",
[OUTPUT_VERBOSE] = "verbose",
[OUTPUT_EXPORT] = "export",
[OUTPUT_JSON] = "json",
return buf;
}
+char *format_timestamp_us(char *buf, size_t l, usec_t t) {
+ struct tm tm;
+ time_t sec;
+
+ assert(buf);
+ assert(l > 0);
+
+ if (t <= 0)
+ return NULL;
+
+ sec = (time_t) (t / USEC_PER_SEC);
+ localtime_r(&sec, &tm);
+
+ if (strftime(buf, l, "%a %Y-%m-%d %H:%M:%S", &tm) <= 0)
+ return NULL;
+ snprintf(buf + strlen(buf), l - strlen(buf), ".%06llu", t % USEC_PER_SEC);
+ if (strftime(buf + strlen(buf), l - strlen(buf), " %Z", &tm) <= 0)
+ return NULL;
+
+ return buf;
+}
+
char *format_timestamp_relative(char *buf, size_t l, usec_t t) {
usec_t n, d;
struct timeval *timeval_store(struct timeval *tv, usec_t u);
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_relative(char *buf, size_t l, usec_t t);
char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy);