]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journalctl: add --no-hostname switch
authorLennart Poettering <lennart@poettering.net>
Wed, 20 Apr 2016 18:09:57 +0000 (20:09 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 22 Apr 2016 14:16:59 +0000 (16:16 +0200)
This suppresses output of the hostname for messages from the local system.

Fixes: #2342
man/journalctl.xml
src/journal/journalctl.c
src/shared/logs-show.c
src/shared/output-mode.h

index c448e0771bcc980c2d6882e82a3a28aa3d2b58c8..3efe6ef62aacf0e34c0db7a619be5016c655a15f 100644 (file)
         (UTC).</para></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><option>--no-hostname</option></term>
+
+        <listitem><para>Don't show the hostname field of log messages originating from the local host. This switch only
+        has an effect on the <option>short</option> family of output modes (see above).</para></listitem>
+      </varlistentry>
+
       <varlistentry>
         <term><option>-x</option></term>
         <term><option>--catalog</option></term>
index fd2cb99410b43492e06dfbf85526697f4da12319..c9a2c3812dcfe8d69862c23ead24a887d22e5488 100644 (file)
@@ -95,6 +95,7 @@ static bool arg_boot = false;
 static sd_id128_t arg_boot_id = {};
 static int arg_boot_offset = 0;
 static bool arg_dmesg = false;
+static bool arg_no_hostname = false;
 static const char *arg_cursor = NULL;
 static const char *arg_after_cursor = NULL;
 static bool arg_show_cursor = false;
@@ -304,6 +305,7 @@ static void help(void) {
                "  -a --all                 Show all fields, including long and unprintable\n"
                "  -q --quiet               Do not show info messages and privilege warning\n"
                "     --no-pager            Do not pipe output into a pager\n"
+               "     --no-hostname         Suppress output of hostname field\n"
                "  -m --merge               Show entries from all available journals\n"
                "  -D --directory=PATH      Show journal files from directory\n"
                "     --file=PATH           Show journal file\n"
@@ -370,6 +372,7 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_VACUUM_SIZE,
                 ARG_VACUUM_FILES,
                 ARG_VACUUM_TIME,
+                ARG_NO_HOSTNAME,
         };
 
         static const struct option options[] = {
@@ -427,6 +430,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "vacuum-size",    required_argument, NULL, ARG_VACUUM_SIZE    },
                 { "vacuum-files",   required_argument, NULL, ARG_VACUUM_FILES   },
                 { "vacuum-time",    required_argument, NULL, ARG_VACUUM_TIME    },
+                { "no-hostname",    no_argument,       NULL, ARG_NO_HOSTNAME    },
                 {}
         };
 
@@ -780,6 +784,10 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_action = ACTION_LIST_FIELD_NAMES;
                         break;
 
+                case ARG_NO_HOSTNAME:
+                        arg_no_hostname = true;
+                        break;
+
                 case 'x':
                         arg_catalog = true;
                         break;
@@ -2444,7 +2452,8 @@ int main(int argc, char *argv[]) {
                                 arg_full * OUTPUT_FULL_WIDTH |
                                 colors_enabled() * OUTPUT_COLOR |
                                 arg_catalog * OUTPUT_CATALOG |
-                                arg_utc * OUTPUT_UTC;
+                                arg_utc * OUTPUT_UTC |
+                                arg_no_hostname * OUTPUT_NO_HOSTNAME;
 
                         r = output_journal(stdout, j, arg_output, 0, flags, &ellipsized);
                         need_seek = true;
index 5cfa455e058ff490d51fa7a7fb5f1a4f693d9955..cd3d53669ca8b6412443f05d67af2aa34dac4824 100644 (file)
@@ -373,6 +373,12 @@ static int output_short(
                 n += strlen(buf);
         }
 
+        if (hostname && (flags & OUTPUT_NO_HOSTNAME)) {
+                /* Suppress display of the hostname if this is requested. */
+                hostname = NULL;
+                hostname_len = 0;
+        }
+
         if (hostname && shall_print(hostname, hostname_len, flags)) {
                 fprintf(f, " %.*s", (int) hostname_len, hostname);
                 n += hostname_len + 1;
index 56fd3ba8e342facfd6f11b9e9fa642b8c092729e..f37189e57fff9389808391e55a93fa4305879a80 100644 (file)
@@ -50,6 +50,7 @@ typedef enum OutputFlags {
         OUTPUT_BEGIN_NEWLINE  = 1 << 6,
         OUTPUT_UTC            = 1 << 7,
         OUTPUT_KERNEL_THREADS = 1 << 8,
+        OUTPUT_NO_HOSTNAME    = 1 << 9,
 } OutputFlags;
 
 const char* output_mode_to_string(OutputMode m) _const_;