From b9e853dbdbdcdafe95403f85654c25f138c8f48c Mon Sep 17 00:00:00 2001 From: Alan Bernstein Date: Fri, 23 Jun 2017 18:08:30 -0500 Subject: [PATCH] Deduplicate logfile opening code --- cmd/server.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/cmd/server.go b/cmd/server.go index 9ef9aa1a8..2cd2aa5a1 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -45,20 +45,12 @@ It will load existing data from the configured directory, and start listening client connections on the configured port.`, RunE: func(cmd *cobra.Command, args []string) error { - // TODO this code is duplicated from server/server.go:Server.Run() because it hasnt run yet - var logOutput io.Writer - if Server.Config.LogPath == "" { - logOutput = stderr - } else { - var err error - logOutput, err = os.OpenFile(Server.Config.LogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600) - if err != nil { - return err - } + logOutput, err := server.GetLogWriter(Server.Config.LogPath, stderr) + if err != nil { + return err } logger := log.New(logOutput, "", log.LstdFlags) logger.Printf("Pilosa %s, build time %s\n", pilosa.Version, pilosa.BuildTime) - // fmt.Fprintf(Server.Stderr, "Pilosa %s, build time %s\n", pilosa.Version, pilosa.BuildTime) // Start CPU profiling. if Server.CPUProfile != "" {