From 216ca2cd134529a5410f210495926337492fe26b Mon Sep 17 00:00:00 2001 From: James Shubin Date: Fri, 21 Sep 2018 15:00:08 +0800 Subject: [PATCH] Add logging workaround when embedding etcd This was discussed in: https://github.com/coreos/etcd/issues/4115 --- main.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 1cf35bf..dd613ee 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,7 @@ package main import ( "github.com/codegangsta/cli" + "github.com/coreos/pkg/capnslog" "log" "os" "os/signal" @@ -205,10 +206,18 @@ func run(c *cli.Context) error { } func main() { - //if DEBUG { - log.SetFlags(log.LstdFlags | log.Lshortfile) - //} - log.SetFlags(log.Flags() - log.Ldate) // remove the date for now + var flags int + if DEBUG || true { // TODO: remove || true + flags = log.LstdFlags | log.Lshortfile + } + flags = (flags - log.Ldate) // remove the date for now + log.SetFlags(flags) + + // un-hijack from capnslog... + log.SetOutput(os.Stderr) + capnslog.SetFormatter(capnslog.NewLogFormatter(os.Stderr, "(etcd) ", flags)) + + // test for sanity if program == "" || version == "" { log.Fatal("Program was not compiled correctly. Please see Makefile.") }