Skip to content

Commit

Permalink
drop init funcs, move log init to main
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlehane committed Jan 17, 2025
1 parent aa0697b commit 443505b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 28 deletions.
14 changes: 1 addition & 13 deletions cmd/roy/roy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:])
Expand Down
13 changes: 1 addition & 12 deletions cmd/sf/sf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions internal/logformatter/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 443505b

Please sign in to comment.