diff --git a/cmd/roy/roy.go b/cmd/roy/roy.go index 4f4f692a..191d9046 100644 --- a/cmd/roy/roy.go +++ b/cmd/roy/roy.go @@ -117,18 +117,6 @@ Additional flags: Use a different siegfried home directory. ` -func setLogger(utc bool) { - lw := new(logformatter.LogWriter) - lw.Appname = "roy" - lw.UTC = utc - log.SetOutput(lw) -} - -func init() { - // format the application logger before all other init. - setLogger(true) -} - var ( // BUILD, ADD flag sets build = flag.NewFlagSet("build | add", flag.ExitOnError) @@ -536,11 +524,11 @@ func setSetsOptions() { } func main() { + logformatter.Set("roy", true) var err error if len(os.Args) < 2 { log.Fatal(usage) } - switch os.Args[1] { case "build": err = build.Parse(os.Args[2:]) diff --git a/cmd/sf/sf.go b/cmd/sf/sf.go index b17c4a0f..8229cd10 100644 --- a/cmd/sf/sf.go +++ b/cmd/sf/sf.go @@ -43,18 +43,6 @@ import ( // defaults const maxMulti = 1024 -func setLogger(utc bool) { - lw := new(logformatter.LogWriter) - lw.Appname = "sf" - lw.UTC = utc - log.SetOutput(lw) -} - -func init() { - // format the application logger before all other init. - setLogger(true) -} - // flags var ( updateShort = flag.Bool("u", false, "update or install the default signature file") @@ -323,6 +311,7 @@ func replayFile(path string, ctxts chan *context, w writer.Writer) error { func main() { flag.Parse() + logformatter.Set("sf", true) // configure home if *home != config.Home() { config.SetHome(*home) diff --git a/internal/logformatter/log.go b/internal/logformatter/log.go index 6a2c614d..b2d2919e 100644 --- a/internal/logformatter/log.go +++ b/internal/logformatter/log.go @@ -32,8 +32,10 @@ func (lw *LogWriter) Write(logString []byte) (int, error) { ) } -func init() { - // Configure logging to use a custom log writer with sensible defaults. +func Set(app string, utc bool) { log.SetFlags(0 | log.Lshortfile | log.LUTC) - log.SetOutput(new(LogWriter)) + lw := &LogWriter{} + lw.Appname = app + lw.UTC = utc + log.SetOutput(lw) }