diff --git a/fs.go b/fs.go index b80bca6..ef83a84 100644 --- a/fs.go +++ b/fs.go @@ -5,10 +5,11 @@ import ( "errors" "fmt" "io/ioutil" - "log" "os" "strings" "time" + + log "github.com/cantara/bragi" ) func stripJar(s string) string { diff --git a/go.mod b/go.mod index ec71608..d23dcbe 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,9 @@ -module github.com/Cantara/vili +module github.com/cantara/vili go 1.16 require ( + github.com/cantara/bragi v0.1.8 // indirect github.com/joho/godotenv v1.4.0 // indirect k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b // indirect ) diff --git a/go.sum b/go.sum index 201302a..98ff737 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,15 @@ +github.com/cantara/bragi v0.1.2 h1:x10uNDDwgxiHn+lLn7iAK5m0uj7QQOuW5k0F7AtK5h0= +github.com/cantara/bragi v0.1.2/go.mod h1:UG6GZBNRGKiMkl2EwlKMQ1tWj2l/9bcXSIzG1b/jVC8= +github.com/cantara/bragi v0.1.3 h1:NNSrgbO74DcvV6zKDfwoiTGqysLsAXd5JdtueNLW6Bc= +github.com/cantara/bragi v0.1.3/go.mod h1:UG6GZBNRGKiMkl2EwlKMQ1tWj2l/9bcXSIzG1b/jVC8= +github.com/cantara/bragi v0.1.5 h1:DKwUXy/vRHGP14cqe5LU1ju9QLLw8md0aB4ufiR/HrI= +github.com/cantara/bragi v0.1.5/go.mod h1:UG6GZBNRGKiMkl2EwlKMQ1tWj2l/9bcXSIzG1b/jVC8= +github.com/cantara/bragi v0.1.6 h1:vz9HK0AtKXcesbL2+wxcZ4leYRyyu7nRUqN2L5WqgvU= +github.com/cantara/bragi v0.1.6/go.mod h1:UG6GZBNRGKiMkl2EwlKMQ1tWj2l/9bcXSIzG1b/jVC8= +github.com/cantara/bragi v0.1.7 h1:jZN+vsOswlKe5BAKqePn0VHtyA7bFXm6IKexaTc80ZA= +github.com/cantara/bragi v0.1.7/go.mod h1:UG6GZBNRGKiMkl2EwlKMQ1tWj2l/9bcXSIzG1b/jVC8= +github.com/cantara/bragi v0.1.8 h1:BVpNnkCT4ePpvnBTGEpg9JdDCFc+kkB/+/+go9ggrqU= +github.com/cantara/bragi v0.1.8/go.mod h1:UG6GZBNRGKiMkl2EwlKMQ1tWj2l/9bcXSIzG1b/jVC8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= diff --git a/main.go b/main.go index 18ed949..ed3fe1f 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "log" "net/http" "os" "strconv" @@ -14,6 +13,7 @@ import ( "sync" "time" + log "github.com/cantara/bragi" "github.com/joho/godotenv" "k8s.io/utils/inotify" ) @@ -54,18 +54,19 @@ func verifyConfig() error { if os.Getenv("port_identifier") == "" { return fmt.Errorf("No port identifier provided") } + return nil } func main() { loadEnv() - logFile := os.Getenv("log_file") - if logFile != "" { - f, err := os.OpenFile(logFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) - if err != nil { - log.Fatal(err) + logDir := os.Getenv("log_dir") + if logDir != "" { + cloaser := log.SetOutputFolder(logDir) + if cloaser != nil { + log.Fatal("Unable to sett logdir") } - defer f.Close() - log.SetOutput(f) + defer cloaser() + log.SetPrefix("vili") } err := verifyConfig() if err != nil { diff --git a/server.go b/server.go index 6bee69a..b85231b 100644 --- a/server.go +++ b/server.go @@ -3,12 +3,13 @@ package main import ( "context" "fmt" - "log" "math" "os" "os/exec" "sync" "time" + + log "github.com/cantara/bragi" ) type serve struct { // TODO rename @@ -73,7 +74,7 @@ func newServer(path, t string, server **serve) (err error) { return } -func startNewServer(serverFolder string) *serve { +func startNewServer(serverFolder, port string) *serve { stdOut, err := os.OpenFile(serverFolder+"/stdOut", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) if err != nil { log.Println(err) diff --git a/tail.go b/tail.go index e0a3df8..879f020 100644 --- a/tail.go +++ b/tail.go @@ -3,10 +3,11 @@ package main import ( "bufio" "context" - "log" "os" "strings" + log "github.com/cantara/bragi" + "k8s.io/utils/inotify" ) diff --git a/zip.go b/zip.go index 80d64a0..121f0ce 100644 --- a/zip.go +++ b/zip.go @@ -6,8 +6,9 @@ import ( "fmt" "io" "io/ioutil" - "log" "os" + + log "github.com/cantara/bragi" ) type zipper struct {