chiark / gitweb /
journalctl: add --utc option
authorJan Synacek <jsynacek@redhat.com>
Thu, 2 Oct 2014 12:39:29 +0000 (14:39 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 2 Oct 2014 12:52:32 +0000 (14:52 +0200)
Introduce option to display time in UTC.

man/journalctl.xml
src/journal/journalctl.c
src/shared/logs-show.c
src/shared/output-mode.h

index acd75a6370d2ac129c6f207c5f5ab82f8fd6ff6c..7fb6afc8f67a578f4e14e5c7c855b932baed64c2 100644 (file)
                                 </listitem>
                         </varlistentry>
 
+                        <varlistentry>
+                                <term><option>--utc</option></term>
+
+                                <listitem><para>Express time in Coordinated Universal
+                                Time (UTC).</para></listitem>
+                        </varlistentry>
+
                         <varlistentry>
                                 <term><option>-x</option></term>
                                 <term><option>--catalog</option></term>
index 89a922c067290a65e79cf42b1f8b191b74faa866..395f85c9aea0cf5e0265a68c5c672856f3754321 100644 (file)
@@ -63,6 +63,7 @@
 #define DEFAULT_FSS_INTERVAL_USEC (15*USEC_PER_MINUTE)
 
 static OutputMode arg_output = OUTPUT_SHORT;
+static bool arg_utc = false;
 static bool arg_pager_end = false;
 static bool arg_follow = false;
 static bool arg_full = true;
@@ -191,6 +192,7 @@ static void help(void) {
                "  -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"
+               "     --utc                 Express time in Coordinated Universal Time (UTC)\n"
                "  -x --catalog             Add message explanations where available\n"
                "     --no-full             Ellipsize fields\n"
                "  -a --all                 Show all fields, including long and unprintable\n"
@@ -250,6 +252,7 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_DUMP_CATALOG,
                 ARG_UPDATE_CATALOG,
                 ARG_FORCE,
+                ARG_UTC,
         };
 
         static const struct option options[] = {
@@ -299,6 +302,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "update-catalog", no_argument,       NULL, ARG_UPDATE_CATALOG },
                 { "reverse",        no_argument,       NULL, 'r'                },
                 { "machine",        required_argument, NULL, 'M'                },
+                { "utc",            no_argument,       NULL, ARG_UTC            },
                 {}
         };
 
@@ -639,6 +643,10 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_reverse = true;
                         break;
 
+                case ARG_UTC:
+                        arg_utc = true;
+                        break;
+
                 case '?':
                         return -EINVAL;
 
@@ -1958,7 +1966,8 @@ int main(int argc, char *argv[]) {
                                 arg_all * OUTPUT_SHOW_ALL |
                                 arg_full * OUTPUT_FULL_WIDTH |
                                 on_tty() * OUTPUT_COLOR |
-                                arg_catalog * OUTPUT_CATALOG;
+                                arg_catalog * OUTPUT_CATALOG |
+                                arg_utc * OUTPUT_UTC;
 
                         r = output_journal(stdout, j, arg_output, 0, flags, &ellipsized);
                         need_seek = true;
index 5a7bbaf03a92fa08dea2310a406f48ba8cf657b4..d5d9d090b5c41a30a943af1b2c8c18034c1ec06c 100644 (file)
@@ -311,8 +311,10 @@ static int output_short(
                 uint64_t x;
                 time_t t;
                 struct tm tm;
+                struct tm *(*gettime_r)(const time_t *, struct tm *);
 
                 r = -ENOENT;
+                gettime_r = (flags & OUTPUT_UTC) ? gmtime_r : localtime_r;
 
                 if (realtime)
                         r = safe_atou64(realtime, &x);
@@ -329,17 +331,17 @@ static int output_short(
 
                 switch(mode) {
                 case OUTPUT_SHORT_ISO:
-                        r = strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S%z", localtime_r(&t, &tm));
+                        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", localtime_r(&t, &tm));
+                        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));
                         }
                         break;
                 default:
-                        r = strftime(buf, sizeof(buf), "%b %d %H:%M:%S", localtime_r(&t, &tm));
+                        r = strftime(buf, sizeof(buf), "%b %d %H:%M:%S", gettime_r(&t, &tm));
                 }
 
                 if (r <= 0) {
index ac1bb0123b5fbcff4845b46211387c0307dc3e1c..81d7f05d91e2aaebdac5251ab2af7fcc036afe82 100644 (file)
@@ -44,4 +44,5 @@ typedef enum OutputFlags {
         OUTPUT_COLOR          = 1 << 4,
         OUTPUT_CATALOG        = 1 << 5,
         OUTPUT_BEGIN_NEWLINE  = 1 << 6,
+        OUTPUT_UTC            = 1 << 7,
 } OutputFlags;