From cf388bd5725f0e5090266620f5758434c590cb79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20N=C3=BC=C3=9Flein?= Date: Tue, 15 Aug 2017 20:51:48 +0200 Subject: [PATCH] FQDN() now gives fqdn, was only hostname before os.Hostname() does not return FQDN (at least not on Linux) --- format/format.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/format/format.go b/format/format.go index 44063e6..363a081 100644 --- a/format/format.go +++ b/format/format.go @@ -21,16 +21,18 @@ package format import ( + "bytes" "encoding/json" "fmt" "github.com/bobziuchkovski/cue" "os" + "os/exec" "reflect" "sort" "strconv" "strings" "time" - "unicode" + "unicode" ) // Color codes for use with Colorize. @@ -278,11 +280,12 @@ func Hostname(buffer Buffer, event *cue.Event) { // FQDN writes the host's fully-qualified domain name (FQDN) to the buffer. // If the FQDN cannot be determined, "unknown" is written instead. func FQDN(buffer Buffer, event *cue.Event) { - name, err := os.Hostname() - if err != nil { - name = "unknown" + out, err := exec.Command("/bin/hostname", "-f").Output() + if err == nil { + buffer.Append(bytes.TrimSpace(out)) + } else { + buffer.AppendString("unknown") } - buffer.AppendString(name) } // Level writes event.Level.String() to the buffer. Hence, it writes "INFO"