diff --git a/cmd/cli.go b/cmd/cli.go index 57d9dc23..a798992f 100644 --- a/cmd/cli.go +++ b/cmd/cli.go @@ -34,10 +34,8 @@ import ( // catchCLI will run functions based on the commands sent to Statping func catchCLI(args []string) error { dir := utils.Directory - if err := utils.InitLogs(); err != nil { - return err - } - source.Assets() + runLogs := utils.InitLogs + runAssets := source.Assets loadDotEnvs() switch args[0] { @@ -50,11 +48,23 @@ func catchCLI(args []string) error { return errors.New("end") case "assets": var err error + if err = runLogs(); err != nil { + return err + } + if err = runAssets(); err != nil { + return err + } if err = source.CreateAllAssets(dir); err != nil { return err } return errors.New("end") case "sass": + if err := runLogs(); err != nil { + return err + } + if err := runAssets(); err != nil { + return err + } if err := source.CompileSASS(dir); err != nil { return err } @@ -71,8 +81,13 @@ func catchCLI(args []string) error { return errors.New("end") case "static": var err error + if err = runLogs(); err != nil { + return err + } + if err = runAssets(); err != nil { + return err + } fmt.Printf("Statping v%v Exporting Static 'index.html' page...\n", VERSION) - utils.InitLogs() if core.Configs, err = core.LoadConfigFile(dir); err != nil { utils.Log.Errorln("config.yml file not found") return err @@ -90,7 +105,10 @@ func catchCLI(args []string) error { case "export": var err error var data []byte - if err := utils.InitLogs(); err != nil { + if err = runLogs(); err != nil { + return err + } + if err = runAssets(); err != nil { return err } if core.Configs, err = core.LoadConfigFile(dir); err != nil { @@ -123,6 +141,12 @@ func catchCLI(args []string) error { } return errors.New("end") case "run": + if err := runLogs(); err != nil { + return err + } + if err := runAssets(); err != nil { + return err + } utils.Log.Infoln("Running 1 time and saving to database...") runOnce() //core.CloseDB() @@ -130,6 +154,12 @@ func catchCLI(args []string) error { return errors.New("end") case "env": fmt.Println("Statping Environment Variable") + if err := runLogs(); err != nil { + return err + } + if err := runAssets(); err != nil { + return err + } envs, err := godotenv.Read(".env") if err != nil { utils.Log.Errorln("No .env file found in current directory.") diff --git a/core/checker.go b/core/checker.go index d1e4a87a..176a413b 100644 --- a/core/checker.go +++ b/core/checker.go @@ -275,7 +275,8 @@ func recordFailure(s *Service, issue string) { CreatedAt: time.Now(), ErrorCode: s.LastStatusCode, } - log.WithFields(utils.ToFields(fail, s.Select())).Warnln(fmt.Sprintf("Service %v Failing: %v | Lookup in: %0.2f ms", s.Name, issue, fail.PingTime*1000)) + log.WithFields(utils.ToFields(fail, s.Select())). + Warnln(fmt.Sprintf("Service %v Failing: %v | Lookup in: %0.2f ms", s.Name, issue, fail.PingTime*1000)) s.CreateFailure(fail) s.Online = false s.SuccessNotified = false diff --git a/source/source.go b/source/source.go index 3e1278fa..2f2e82a4 100644 --- a/source/source.go +++ b/source/source.go @@ -37,12 +37,13 @@ var ( ) // Assets will load the Rice boxes containing the CSS, SCSS, JS, and HTML files. -func Assets() { +func Assets() error { CssBox = rice.MustFindBox("css") ScssBox = rice.MustFindBox("scss") JsBox = rice.MustFindBox("js") TmplBox = rice.MustFindBox("tmpl") FontBox = rice.MustFindBox("font") + return nil } // HelpMarkdown will return the Markdown of help.md into HTML diff --git a/source/wiki.go b/source/wiki.go index 60d29b77..94090672 100644 --- a/source/wiki.go +++ b/source/wiki.go @@ -1,6 +1,6 @@ // Code generated by go generate; DO NOT EDIT. // This file was generated by robots at -// 2019-12-28 12:28:40.714078 +0000 UTC +// 2019-12-30 04:41:26.419204 +0000 UTC // // This contains the most recently Markdown source for the Statping Wiki. package source diff --git a/utils/log.go b/utils/log.go index 2be555c1..baf7d756 100644 --- a/utils/log.go +++ b/utils/log.go @@ -59,7 +59,7 @@ func (t *hook) Levels() []Logger.Level { // type "*types.Service", on string field "Name" converts to "service_name=value". There is also an // additional field called "_pointer" that will return the pointer hex value. func ToFields(d ...interface{}) map[string]interface{} { - if VerboseMode <= 1 { + if !Log.IsLevelEnabled(Logger.DebugLevel) { return nil } fieldKey := make(map[string]interface{}) @@ -108,9 +108,7 @@ func replaceVal(d interface{}) interface{} { // createLog will create the '/logs' directory based on a directory func createLog(dir string) error { if !FolderExists(dir + "/logs") { - if err := CreateDirectory(dir + "/logs"); err != nil { - return err - } + CreateDirectory(dir + "/logs") } return nil } diff --git a/utils/utils.go b/utils/utils.go index ebef85ea..dd4e01cf 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -184,21 +184,21 @@ func FileExists(name string) bool { // DeleteFile will attempt to delete a file // DeleteFile("newfile.json") func DeleteFile(file string) error { - Log.Infoln("deleting file: " + file) + Log.Debugln("deleting file: " + file) return os.Remove(file) } // DeleteDirectory will attempt to delete a directory and all contents inside // DeleteDirectory("assets") func DeleteDirectory(directory string) error { - Log.Infoln("removing directory: " + directory) + Log.Debugln("removing directory: " + directory) return os.RemoveAll(directory) } // CreateDirectory will attempt to create a directory // CreateDirectory("assets") func CreateDirectory(directory string) error { - Log.Infoln("creating directory: " + directory) + Log.Debugln("creating directory: " + directory) if err := os.Mkdir(directory, os.ModePerm); err != os.ErrExist { return err } @@ -216,7 +216,7 @@ func FolderExists(folder string) bool { // CopyFile will copy a file to a new directory // CopyFile("source.jpg", "/tmp/source.jpg") func CopyFile(src, dst string) error { - Log.Infoln(fmt.Sprintf("copying file: %v to %v", src, dst)) + Log.Debugln(fmt.Sprintf("copying file: %v to %v", src, dst)) in, err := os.Open(src) if err != nil { return err @@ -239,7 +239,7 @@ func CopyFile(src, dst string) error { // Command will run a terminal command with 'sh -c COMMAND' and return stdout and errOut as strings // in, out, err := Command("sass assets/scss assets/css/base.css") func Command(cmd string) (string, string, error) { - Log.Infoln("running command: " + cmd) + Log.Debugln("running command: " + cmd) testCmd := exec.Command("sh", "-c", cmd) var stdout, stderr []byte var errStdout, errStderr error