chiark / gitweb /
journalctl: add ”short-iso” output format with verbose ISO8601 timestamps
authorTomasz Torcz <tomek@pipebreaker.pl>
Thu, 18 Jul 2013 08:21:45 +0000 (10:21 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 18 Jul 2013 13:58:49 +0000 (15:58 +0200)
Example:
2013-07-18T10:10:01+0200 sandworm CROND[20957]: (root) CMD (/usr/lib64/sa/sa1 1 1)

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

index 65a59ea4e73b8b62bb7bb453e0dde5374165f3af..da43bf28796e6515516ece9c60947c32ec1c941d 100644 (file)
                                                 </listitem>
                                         </varlistentry>
 
+                                        <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>
index 2f043a48d544f25af757e87e511c0d6caeccec52..083a5971160c75910724a8274f84510492df164e 100644 (file)
@@ -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"
index ea4746879bf3d43b925a4832b115d91e4508c91b..bd7363aa82a2888f6efa183f4423ac3fbe454fb4 100644 (file)
@@ -273,9 +273,14 @@ static int output_short(
                 }
 
                 t = (time_t) (x / USEC_PER_SEC);
-                if (strftime(buf, sizeof(buf), "%b %d %H:%M:%S", localtime_r(&t, &tm)) <= 0) {
+                if (mode == OUTPUT_SHORT_ISO)
+                        r = strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S%z", localtime_r(&t, &tm));
+                else
+                        r = strftime(buf, sizeof(buf), "%b %d %H:%M:%S", localtime_r(&t, &tm));
+
+                if (r <= 0) {
                         log_error("Failed to format time.");
-                        return r;
+                        return -EINVAL;
                 }
 
                 fputs(buf, f);
@@ -798,6 +803,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 +1082,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",
index 0efd430c5d71203d9109469e6c977e7c42215dbe..4012889b656318d7b8985acfd65e683c736e3743 100644 (file)
@@ -24,6 +24,7 @@
 typedef enum OutputMode {
         OUTPUT_SHORT,
         OUTPUT_SHORT_MONOTONIC,
+        OUTPUT_SHORT_ISO,
         OUTPUT_VERBOSE,
         OUTPUT_EXPORT,
         OUTPUT_JSON,