From 33aedd9d8fbc79226040bc0eecceda0e7de74a53 Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Thu, 14 Dec 2017 21:32:11 -0500 Subject: [PATCH 1/9] moving fmt.PrintX to be logrus --- app.go | 19 ++++++++++--------- buffalo/cmd/build.go | 7 +++---- buffalo/cmd/build/apkg.go | 4 ++-- buffalo/cmd/build/archived_assets.go | 2 +- buffalo/cmd/build/builder.go | 2 +- buffalo/cmd/build/exec.go | 2 +- buffalo/cmd/build/target.go | 2 +- buffalo/cmd/build/transform.go | 2 +- buffalo/cmd/build/transform_main.go | 2 +- buffalo/cmd/destroy/resource.go | 19 ++++++++++--------- buffalo/cmd/dev.go | 4 ++-- buffalo/cmd/new.go | 12 ++++++------ buffalo/cmd/plugins.go | 4 ++-- buffalo/cmd/root.go | 4 ++-- buffalo/cmd/setup.go | 4 ++-- buffalo/cmd/test.go | 6 +++--- buffalo/cmd/version.go | 5 ++--- generators/action/action.go | 7 ++++--- generators/assets/webpack/webpack.go | 4 ++-- grifts.go | 8 ++++---- grifts/shoulders.go | 4 ++-- logger.go | 2 +- logger_formatter.go | 4 ++-- options.go | 5 +++-- plugins/plugins.go | 6 +++--- render/template.go | 4 ++-- request_logger.go | 2 +- worker/simple.go | 2 +- 28 files changed, 75 insertions(+), 73 deletions(-) diff --git a/app.go b/app.go index 57fad0f10..0d325636c 100644 --- a/app.go +++ b/app.go @@ -3,7 +3,6 @@ package buffalo import ( "context" "fmt" - "log" "net" "net/http" "os" @@ -12,6 +11,8 @@ import ( "sync" "syscall" + "github.com/Sirupsen/logrus" + "github.com/gobuffalo/envy" "github.com/gorilla/mux" "github.com/markbates/going/defaults" @@ -43,7 +44,7 @@ func (a *App) Start(port string) error { warningMsg = fmt.Sprintf("%s Called from %s:%d", warningMsg, file, no) } - log.Println(warningMsg) + logrus.Info(warningMsg) a.Addr = defaults.String(a.Addr, fmt.Sprintf("%s:%s", envy.Get("ADDR", "127.0.0.1"), port)) return a.Serve() @@ -53,7 +54,7 @@ func (a *App) Start(port string) error { // interrupt and kill signals and will attempt to stop the application // gracefully. This will also start the Worker process, unless WorkerOff is enabled. func (a *App) Serve() error { - fmt.Printf("Starting application at %s\n", a.Options.Addr) + logrus.Infof("Starting application at %s", a.Options.Addr) server := http.Server{ Handler: a, } @@ -63,25 +64,25 @@ func (a *App) Serve() error { go func() { // gracefully shut down the application when the context is cancelled <-ctx.Done() - fmt.Println("Shutting down application") + logrus.Info("Shutting down application") err := a.Stop(ctx.Err()) if err != nil { - fmt.Println(err) + logrus.Debug(err) } if !a.WorkerOff { // stop the workers - fmt.Println("Shutting down worker") + logrus.Info("Shutting down worker") err = a.Worker.Stop() if err != nil { - fmt.Println(err) + logrus.Debug(err) } } err = server.Shutdown(ctx) if err != nil { - fmt.Println(err) + logrus.Debug(err) } }() @@ -125,7 +126,7 @@ func (a *App) Serve() error { func (a *App) Stop(err error) error { a.cancel() if err != nil && errors.Cause(err) != context.Canceled { - fmt.Println(err) + logrus.Debug(err) return err } return nil diff --git a/buffalo/cmd/build.go b/buffalo/cmd/build.go index 6c637eb27..4ba481fda 100644 --- a/buffalo/cmd/build.go +++ b/buffalo/cmd/build.go @@ -2,15 +2,14 @@ package cmd import ( "context" - "fmt" "os" "path/filepath" + "github.com/Sirupsen/logrus" "github.com/gobuffalo/buffalo/buffalo/cmd/build" "github.com/gobuffalo/buffalo/meta" "github.com/markbates/sigtx" "github.com/pkg/errors" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -44,7 +43,7 @@ var xbuildCmd = &cobra.Command{ go func() { <-ctx.Done() if ctx.Err() == context.Canceled { - fmt.Println("~~~ BUILD CANCELLED ~~~") + logrus.Info("~~~ BUILD CANCELLED ~~~") err := b.Cleanup() if err != nil { logrus.Fatal(err) @@ -57,7 +56,7 @@ var xbuildCmd = &cobra.Command{ return errors.WithStack(err) } - fmt.Printf("\nYou application was successfully built at %s\n", filepath.Join(b.Root, b.Bin)) + logrus.Info("\nYou application was successfully built at %s\n", filepath.Join(b.Root, b.Bin)) return nil }, diff --git a/buffalo/cmd/build/apkg.go b/buffalo/cmd/build/apkg.go index b8eafd0cc..61e70b932 100644 --- a/buffalo/cmd/build/apkg.go +++ b/buffalo/cmd/build/apkg.go @@ -7,8 +7,8 @@ import ( "os" "path/filepath" + "github.com/Sirupsen/logrus" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) func (b *Builder) prepAPackage() error { @@ -91,7 +91,7 @@ func (b *Builder) buildADatabase() error { logrus.Debugf("no sqlite usage in database.yml detected, applying the nosqlite tag") b.Tags = append(b.Tags, "nosqlite") } else if !b.Static { - fmt.Println("you are building a SQLite application, please consider using the `--static` flag to compile a static binary") + logrus.Debugf("you are building a SQLite application, please consider using the `--static` flag to compile a static binary") } } else { logrus.Debugf("no database.yml detected, applying the nosqlite tag") diff --git a/buffalo/cmd/build/archived_assets.go b/buffalo/cmd/build/archived_assets.go index 1951c4cba..9dce6439c 100644 --- a/buffalo/cmd/build/archived_assets.go +++ b/buffalo/cmd/build/archived_assets.go @@ -8,8 +8,8 @@ import ( "path/filepath" "strings" + "github.com/Sirupsen/logrus" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) func (b *Builder) buildExtractedAssets() error { diff --git a/buffalo/cmd/build/builder.go b/buffalo/cmd/build/builder.go index 00d280028..7588b156e 100644 --- a/buffalo/cmd/build/builder.go +++ b/buffalo/cmd/build/builder.go @@ -4,9 +4,9 @@ import ( "context" "os" + "github.com/Sirupsen/logrus" "github.com/gobuffalo/packr/builder" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) // Builder builds a Buffalo binary diff --git a/buffalo/cmd/build/exec.go b/buffalo/cmd/build/exec.go index 446532c98..883041ad9 100644 --- a/buffalo/cmd/build/exec.go +++ b/buffalo/cmd/build/exec.go @@ -6,8 +6,8 @@ import ( "os/exec" "strings" + "github.com/Sirupsen/logrus" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) type debugWriter int diff --git a/buffalo/cmd/build/target.go b/buffalo/cmd/build/target.go index b1d8ef3cf..3e87fe1e3 100644 --- a/buffalo/cmd/build/target.go +++ b/buffalo/cmd/build/target.go @@ -4,7 +4,7 @@ import ( "os" "path/filepath" - "github.com/sirupsen/logrus" + "github.com/Sirupsen/logrus" ) func (b *Builder) prepTarget() error { diff --git a/buffalo/cmd/build/transform.go b/buffalo/cmd/build/transform.go index 6b485b20f..c6cbdb82a 100644 --- a/buffalo/cmd/build/transform.go +++ b/buffalo/cmd/build/transform.go @@ -6,8 +6,8 @@ import ( "os" "path/filepath" + "github.com/Sirupsen/logrus" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) func (b *Builder) transform(path string, fn func([]byte, io.Writer) error) error { diff --git a/buffalo/cmd/build/transform_main.go b/buffalo/cmd/build/transform_main.go index 056a702b6..cf6aedf76 100644 --- a/buffalo/cmd/build/transform_main.go +++ b/buffalo/cmd/build/transform_main.go @@ -6,9 +6,9 @@ import ( "os" "path/filepath" + "github.com/Sirupsen/logrus" "github.com/gobuffalo/plush" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) func (b *Builder) transformMain() error { diff --git a/buffalo/cmd/destroy/resource.go b/buffalo/cmd/destroy/resource.go index 26fa7c048..ffc27f42e 100644 --- a/buffalo/cmd/destroy/resource.go +++ b/buffalo/cmd/destroy/resource.go @@ -9,6 +9,7 @@ import ( "path/filepath" "strings" + "github.com/Sirupsen/logrus" "github.com/markbates/inflect" "github.com/spf13/cobra" ) @@ -51,22 +52,22 @@ func confirm(msg string) bool { func removeTemplates(fileName string) { if YesToAll || confirm("Want to remove templates? (Y/n)") { templatesFolder := fmt.Sprintf(filepath.Join("templates", fileName)) - fmt.Printf("- Deleted %v folder\n", templatesFolder) + logrus.Info("- Deleted %v folder\n", templatesFolder) os.RemoveAll(templatesFolder) } } func removeActions(fileName string) { if YesToAll || confirm("Want to remove actions? (Y/n)") { - fmt.Printf("- Deleted %v\n", fmt.Sprintf("actions/%v.go", fileName)) + logrus.Infof("- Deleted %v\n", fmt.Sprintf("actions/%v.go", fileName)) os.Remove(filepath.Join("actions", fmt.Sprintf("%v.go", fileName))) - fmt.Printf("- Deleted %v\n", fmt.Sprintf("actions/%v_test.go", fileName)) + logrus.Infof("- Deleted %v\n", fmt.Sprintf("actions/%v_test.go", fileName)) os.Remove(filepath.Join("actions", fmt.Sprintf("%v_test.go", fileName))) content, err := ioutil.ReadFile(filepath.Join("actions", "app.go")) if err != nil { - fmt.Println("[WARNING] error reading app.go content") + logrus.Info("[WARNING] error reading app.go content") return } @@ -75,11 +76,11 @@ func removeActions(fileName string) { err = ioutil.WriteFile(filepath.Join("actions", "app.go"), []byte(newContents), 0) if err != nil { - fmt.Println("[WARNING] error writing new app.go content") + logrus.Info("[WARNING] error writing new app.go content") return } - fmt.Printf("- Deleted References for %v in actions/app.go\n", fileName) + logrus.Infof("- Deleted References for %v in actions/app.go\n", fileName) } } @@ -96,8 +97,8 @@ func removeModel(name string) { os.Remove(filepath.Join("models", fmt.Sprintf("%v.go", modelFileName))) os.Remove(filepath.Join("models", fmt.Sprintf("%v_test.go", modelFileName))) - fmt.Printf("- Deleted %v\n", fmt.Sprintf("models/%v.go", modelFileName)) - fmt.Printf("- Deleted %v\n", fmt.Sprintf("models/%v_test.go", modelFileName)) + logrus.Infof("- Deleted %v\n", fmt.Sprintf("models/%v.go", modelFileName)) + logrus.Infof("- Deleted %v\n", fmt.Sprintf("models/%v_test.go", modelFileName)) } } @@ -116,7 +117,7 @@ func removeMatch(folder, pattern string) { if !f.IsDir() && matches { path := filepath.Join(folder, f.Name()) os.Remove(path) - fmt.Printf("- Deleted %v\n", path) + logrus.Infof("- Deleted %v\n", path) } } } diff --git a/buffalo/cmd/dev.go b/buffalo/cmd/dev.go index 716e0dadb..39bcdf561 100644 --- a/buffalo/cmd/dev.go +++ b/buffalo/cmd/dev.go @@ -2,11 +2,11 @@ package cmd import ( "context" - "fmt" "os" "os/exec" "runtime" + "github.com/Sirupsen/logrus" "github.com/fatih/color" "github.com/gobuffalo/buffalo/generators/assets/webpack" rg "github.com/gobuffalo/buffalo/generators/refresh" @@ -39,7 +39,7 @@ This behavior can be changed in your .buffalo.dev.yml file.`, cause = err.Error() } } - fmt.Printf(msg, cause) + logrus.Info(msg, cause) }() os.Setenv("GO_ENV", "development") diff --git a/buffalo/cmd/new.go b/buffalo/cmd/new.go index 452e499ff..4602949cf 100644 --- a/buffalo/cmd/new.go +++ b/buffalo/cmd/new.go @@ -1,11 +1,12 @@ package cmd import ( - "fmt" "os" "os/user" "path/filepath" + "github.com/Sirupsen/logrus" + "github.com/pkg/errors" "github.com/gobuffalo/buffalo/generators/newapp" @@ -65,10 +66,9 @@ var newCmd = &cobra.Command{ return errors.WithStack(err) } - fmt.Printf("Congratulations! Your application, %s, has been successfully built!\n\n", app.Name) - fmt.Println("You can find your new application at:") - fmt.Println(app.Root) - fmt.Println("\nPlease read the README.md file in your new application for next steps on running your application.") + logrus.Infof("Congratulations! Your application, %s, has been successfully built!\n\n", app.Name) + logrus.Infof("You can find your new application at:\n%v", app.Root) + logrus.Info("\nPlease read the README.md file in your new application for next steps on running your application.") return nil }, @@ -89,7 +89,7 @@ func notInGoPath(ag newapp.Generator) error { if err != nil { return err } - fmt.Println(t) + logrus.Info(t) os.Exit(-1) return nil } diff --git a/buffalo/cmd/plugins.go b/buffalo/cmd/plugins.go index 66adbec5a..93b9312be 100644 --- a/buffalo/cmd/plugins.go +++ b/buffalo/cmd/plugins.go @@ -2,11 +2,11 @@ package cmd import ( "fmt" - "log" "os" "os/exec" "sync" + "github.com/Sirupsen/logrus" "github.com/gobuffalo/buffalo/plugins" "github.com/gobuffalo/envy" "github.com/spf13/cobra" @@ -23,7 +23,7 @@ func plugs() plugins.List { _plugs, err = plugins.Available() if err != nil { _plugs = plugins.List{} - log.Printf("error loading plugins %s\n", err) + logrus.Info("error loading plugins %s\n", err) } } return _plugs diff --git a/buffalo/cmd/root.go b/buffalo/cmd/root.go index 7c2f926aa..41c4574b4 100644 --- a/buffalo/cmd/root.go +++ b/buffalo/cmd/root.go @@ -2,9 +2,9 @@ package cmd import ( "errors" - "fmt" "os" + "github.com/Sirupsen/logrus" "github.com/spf13/cobra" ) @@ -41,7 +41,7 @@ var RootCmd = &cobra.Command{ // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { if err := RootCmd.Execute(); err != nil { - fmt.Printf("Error: %s\n\n", err) + logrus.Debugf("Error: %s\n\n", err) os.Exit(-1) } } diff --git a/buffalo/cmd/setup.go b/buffalo/cmd/setup.go index 3f2c5d693..0d3f5b7c5 100644 --- a/buffalo/cmd/setup.go +++ b/buffalo/cmd/setup.go @@ -3,13 +3,13 @@ package cmd import ( "bytes" "context" - "fmt" "os" "os/exec" "strings" "golang.org/x/sync/errgroup" + "github.com/Sirupsen/logrus" "github.com/gobuffalo/envy" "github.com/markbates/deplist" "github.com/pkg/errors" @@ -214,7 +214,7 @@ func nodeCheck() error { } func run(cmd *exec.Cmd) error { - fmt.Printf("--> %s\n", strings.Join(cmd.Args, " ")) + logrus.Info("--> %s\n", strings.Join(cmd.Args, " ")) cmd.Stdin = os.Stdin cmd.Stderr = os.Stderr cmd.Stdout = os.Stdout diff --git a/buffalo/cmd/test.go b/buffalo/cmd/test.go index 94bb9fee8..9d6476799 100644 --- a/buffalo/cmd/test.go +++ b/buffalo/cmd/test.go @@ -2,7 +2,6 @@ package cmd import ( "bytes" - "fmt" "io" "os" "os/exec" @@ -10,6 +9,7 @@ import ( "regexp" "strings" + "github.com/Sirupsen/logrus" "github.com/gobuffalo/buffalo/meta" "github.com/gobuffalo/envy" "github.com/pkg/errors" @@ -106,7 +106,7 @@ func testRunner(args []string) error { } cmd.Args = append(cmd.Args, pkgs...) } - fmt.Println(strings.Join(cmd.Args, " ")) + logrus.Info(strings.Join(cmd.Args, " ")) return cmd.Run() } @@ -127,7 +127,7 @@ func mFlagRunner(args []string) error { } cmd := newTestCmd(args) p = strings.TrimPrefix(p, app.PackagePkg+string(filepath.Separator)) - fmt.Println(strings.Join(cmd.Args, " ")) + logrus.Info(strings.Join(cmd.Args, " ")) os.Chdir(p) if err := cmd.Run(); err != nil { errs = true diff --git a/buffalo/cmd/version.go b/buffalo/cmd/version.go index 6f4720fbb..5a1899e75 100644 --- a/buffalo/cmd/version.go +++ b/buffalo/cmd/version.go @@ -1,8 +1,7 @@ package cmd import ( - "fmt" - + "github.com/Sirupsen/logrus" "github.com/spf13/cobra" ) @@ -19,7 +18,7 @@ var versionCmd = &cobra.Command{ Short: "Print the version number of buffalo", Long: `All software has versions. This is buffalo's.`, Run: func(c *cobra.Command, args []string) { - fmt.Printf("Buffalo version is: %s\n", Version) + logrus.Infof("Buffalo version is: %s\n", Version) }, // needed to override the root level pre-run func PersistentPreRunE: func(c *cobra.Command, args []string) error { diff --git a/generators/action/action.go b/generators/action/action.go index 0527707c5..01520550c 100644 --- a/generators/action/action.go +++ b/generators/action/action.go @@ -6,6 +6,7 @@ import ( "path/filepath" "strings" + "github.com/Sirupsen/logrus" "github.com/pkg/errors" "github.com/gobuffalo/buffalo/generators" @@ -100,7 +101,7 @@ func (act Generator) findActionsToAdd(path string) []meta.Name { for _, action := range act.Actions { funcSignature := fmt.Sprintf("func %s%s(c buffalo.Context) error", act.Name.Camel(), action.Camel()) if strings.Contains(string(fileContents), funcSignature) { - fmt.Printf("--> [warning] skipping %v%v since it already exists\n", act.Name.Camel(), action.Camel()) + logrus.Infof("--> [warning] skipping %v%v since it already exists\n", act.Name.Camel(), action.Camel()) continue } @@ -121,7 +122,7 @@ func (act Generator) findHandlersToAdd(path string) []meta.Name { for _, action := range act.Actions { funcSignature := fmt.Sprintf("app.GET(\"/%s/%s\", %s%s)", act.Name.URL(), action.URL(), act.Name.Camel(), action.Camel()) if strings.Contains(string(fileContents), funcSignature) { - fmt.Printf("--> [warning] skipping %s from app.go since it already exists\n", funcSignature) + logrus.Infof("--> [warning] skipping %s from app.go since it already exists\n", funcSignature) continue } @@ -142,7 +143,7 @@ func (act Generator) findTestsToAdd(path string) []meta.Name { for _, action := range act.Actions { funcSignature := fmt.Sprintf("func (as *ActionSuite) Test_%v_%v() {", act.Name.Camel(), action.Camel()) if strings.Contains(string(fileContents), funcSignature) { - fmt.Printf("--> [warning] skipping Test_%v_%v since it already exists\n", act.Name.Camel(), action.Camel()) + logrus.Infof("--> [warning] skipping Test_%v_%v since it already exists\n", act.Name.Camel(), action.Camel()) continue } diff --git a/generators/assets/webpack/webpack.go b/generators/assets/webpack/webpack.go index fedb5c791..64a60f2fe 100644 --- a/generators/assets/webpack/webpack.go +++ b/generators/assets/webpack/webpack.go @@ -1,10 +1,10 @@ package webpack import ( - "fmt" "os/exec" "path/filepath" + "github.com/Sirupsen/logrus" "github.com/gobuffalo/buffalo/generators" "github.com/gobuffalo/buffalo/generators/assets" "github.com/gobuffalo/buffalo/generators/assets/standard" @@ -26,7 +26,7 @@ func (w Generator) Run(root string, data makr.Data) error { // if there's no npm, return! if _, err := exec.LookPath("npm"); err != nil { - fmt.Println("Could not find npm. Skipping webpack generation.") + logrus.Infof("Could not find npm. Skipping webpack generation.") return standard.Run(root, data) } diff --git a/grifts.go b/grifts.go index 2a3cf7070..b208b3285 100644 --- a/grifts.go +++ b/grifts.go @@ -7,6 +7,7 @@ import ( "strings" "text/tabwriter" + "github.com/Sirupsen/logrus" "github.com/markbates/going/randx" "github.com/markbates/grift/grift" "github.com/pkg/errors" @@ -35,7 +36,7 @@ func secretGrift() { rx := regexp.MustCompile(`(\W+)`) bb = rx.ReplaceAll(bb, []byte("")) s := randx.String(6) + string(bb) - fmt.Println(s[:127]) + logrus.Infof(s[:127]) return nil }) } @@ -49,9 +50,8 @@ func middlewareGrift(a *App) { } func printMiddleware(a *App) { - fmt.Println(fmt.Sprintf("-> %s", a.Name)) - fmt.Println(a.Middleware.String()) - fmt.Println() + logrus.Infof(fmt.Sprintf("-> %s", a.Name)) + logrus.Infof("%v\n", a.Middleware.String()) for _, x := range a.children { printMiddleware(x) } diff --git a/grifts/shoulders.go b/grifts/shoulders.go index a2fde8c47..8c6a68101 100755 --- a/grifts/shoulders.go +++ b/grifts/shoulders.go @@ -1,7 +1,6 @@ package grifts import ( - "fmt" "html/template" "os" "os/exec" @@ -9,6 +8,7 @@ import ( "sort" "strings" + "github.com/Sirupsen/logrus" "github.com/gobuffalo/envy" "github.com/markbates/deplist" "github.com/markbates/grift/grift" @@ -31,7 +31,7 @@ var _ = grift.Add("shoulders:list", func(c *grift.Context) error { } } sort.Strings(deps) - fmt.Println(strings.Join(deps, "\n")) + logrus.Infof(strings.Join(deps, "\n")) c.Set("giants", deps) return nil }) diff --git a/logger.go b/logger.go index ea6412cad..395dfde3a 100644 --- a/logger.go +++ b/logger.go @@ -1,8 +1,8 @@ package buffalo import ( + "github.com/Sirupsen/logrus" "github.com/gobuffalo/envy" - "github.com/sirupsen/logrus" ) // Logger interface is used throughout Buffalo diff --git a/logger_formatter.go b/logger_formatter.go index 8a1c76935..585715b46 100644 --- a/logger_formatter.go +++ b/logger_formatter.go @@ -1,6 +1,6 @@ package buffalo -// I really don't want to have this, but until (if) https://github.com/sirupsen/logrus/pull/606 is merged we're stuck with all this code. And yes, this is ALL needed just to remove some blank space in the logs +// I really don't want to have this, but until (if) https://github.com/Sirupsen/logrus/pull/606 is merged we're stuck with all this code. And yes, this is ALL needed just to remove some blank space in the logs import ( "bytes" @@ -12,7 +12,7 @@ import ( "sync" "time" - "github.com/sirupsen/logrus" + "github.com/Sirupsen/logrus" "golang.org/x/crypto/ssh/terminal" ) diff --git a/options.go b/options.go index e70673eed..72297c814 100644 --- a/options.go +++ b/options.go @@ -3,10 +3,11 @@ package buffalo import ( "context" "fmt" - "log" "net/http" "strings" + "github.com/Sirupsen/logrus" + "github.com/fatih/color" "github.com/gobuffalo/buffalo/worker" "github.com/gobuffalo/envy" @@ -121,7 +122,7 @@ func optionsWithDefaults(opts Options) Options { secret := envy.Get("SESSION_SECRET", "") // In production a SESSION_SECRET must be set! if opts.Env == "production" && secret == "" { - log.Println("WARNING! Unless you set SESSION_SECRET env variable, your session storage is not protected!") + logrus.Warn("WARNING! Unless you set SESSION_SECRET env variable, your session storage is not protected!") } opts.SessionStore = sessions.NewCookieStore([]byte(secret)) } diff --git a/plugins/plugins.go b/plugins/plugins.go index c4ab73dff..a896f1a4f 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "encoding/json" - "fmt" "os" "os/exec" "path/filepath" @@ -12,6 +11,7 @@ import ( "strings" "time" + "github.com/Sirupsen/logrus" "github.com/pkg/errors" ) @@ -83,12 +83,12 @@ func askBin(path string) Commands { cmd.Stderr = bb err := cmd.Run() if err != nil { - fmt.Printf("[PLUGIN] error loading plugin %s: %s\n%s\n", path, err, bb.String()) + logrus.Infof("[PLUGIN] error loading plugin %s: %s\n%s\n", path, err, bb.String()) return commands } err = json.NewDecoder(bb).Decode(&commands) if err != nil { - fmt.Printf("[PLUGIN] error loading plugin %s: %s\n", path, err) + logrus.Infof("[PLUGIN] error loading plugin %s: %s\n", path, err) return commands } return commands diff --git a/render/template.go b/render/template.go index 65e88416f..05f03b12a 100644 --- a/render/template.go +++ b/render/template.go @@ -3,12 +3,12 @@ package render import ( "html/template" "io" - "log" "os" "path/filepath" "sort" "strings" + "github.com/Sirupsen/logrus" "github.com/pkg/errors" // this blank import is here because dep doesn't @@ -105,7 +105,7 @@ func (s templateRenderer) exec(name string, data Data) (template.HTML, error) { for _, ext := range s.exts(name) { te, ok := s.TemplateEngines[ext] if !ok { - log.Printf("could not find a template engine for %s\n", ext) + logrus.Warn("could not find a template engine for %s\n", ext) continue } body, err = te(body, data, helpers) diff --git a/request_logger.go b/request_logger.go index 1ea8f24d5..019e5f73c 100644 --- a/request_logger.go +++ b/request_logger.go @@ -3,10 +3,10 @@ package buffalo import ( "time" + "github.com/Sirupsen/logrus" humanize "github.com/dustin/go-humanize" "github.com/gobuffalo/x/httpx" "github.com/markbates/going/randx" - "github.com/sirupsen/logrus" ) // RequestLogger can be be overridden to a user specified diff --git a/worker/simple.go b/worker/simple.go index ac1a62a90..96cb773af 100644 --- a/worker/simple.go +++ b/worker/simple.go @@ -5,8 +5,8 @@ import ( "sync" "time" + "github.com/Sirupsen/logrus" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) var _ Worker = &Simple{} From a3900db2575486075f7e6b87c18fbe71b21c97f2 Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Fri, 15 Dec 2017 16:21:18 -0500 Subject: [PATCH 2/9] moving to lowercase logrus --- app.go | 2 +- buffalo/cmd/build.go | 2 +- buffalo/cmd/build/apkg.go | 2 +- buffalo/cmd/build/archived_assets.go | 2 +- buffalo/cmd/build/builder.go | 2 +- buffalo/cmd/build/exec.go | 2 +- buffalo/cmd/build/target.go | 2 +- buffalo/cmd/build/transform.go | 2 +- buffalo/cmd/build/transform_main.go | 2 +- buffalo/cmd/destroy/resource.go | 2 +- buffalo/cmd/dev.go | 2 +- buffalo/cmd/new.go | 2 +- buffalo/cmd/plugins.go | 2 +- buffalo/cmd/root.go | 2 +- buffalo/cmd/setup.go | 2 +- buffalo/cmd/test.go | 2 +- buffalo/cmd/version.go | 2 +- generators/action/action.go | 2 +- generators/assets/webpack/webpack.go | 2 +- grifts.go | 2 +- grifts/shoulders.go | 2 +- logger.go | 2 +- logger_formatter.go | 4 ++-- options.go | 2 +- plugins/plugins.go | 2 +- render/template.go | 2 +- request_logger.go | 2 +- worker/simple.go | 2 +- 28 files changed, 29 insertions(+), 29 deletions(-) diff --git a/app.go b/app.go index 0d325636c..890a5f5b9 100644 --- a/app.go +++ b/app.go @@ -11,7 +11,7 @@ import ( "sync" "syscall" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/gobuffalo/envy" "github.com/gorilla/mux" diff --git a/buffalo/cmd/build.go b/buffalo/cmd/build.go index 4ba481fda..27698422f 100644 --- a/buffalo/cmd/build.go +++ b/buffalo/cmd/build.go @@ -5,7 +5,7 @@ import ( "os" "path/filepath" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/gobuffalo/buffalo/buffalo/cmd/build" "github.com/gobuffalo/buffalo/meta" "github.com/markbates/sigtx" diff --git a/buffalo/cmd/build/apkg.go b/buffalo/cmd/build/apkg.go index 61e70b932..5efbf431d 100644 --- a/buffalo/cmd/build/apkg.go +++ b/buffalo/cmd/build/apkg.go @@ -7,7 +7,7 @@ import ( "os" "path/filepath" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/pkg/errors" ) diff --git a/buffalo/cmd/build/archived_assets.go b/buffalo/cmd/build/archived_assets.go index 9dce6439c..fe6b8b73c 100644 --- a/buffalo/cmd/build/archived_assets.go +++ b/buffalo/cmd/build/archived_assets.go @@ -8,7 +8,7 @@ import ( "path/filepath" "strings" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/pkg/errors" ) diff --git a/buffalo/cmd/build/builder.go b/buffalo/cmd/build/builder.go index 7588b156e..009c424a7 100644 --- a/buffalo/cmd/build/builder.go +++ b/buffalo/cmd/build/builder.go @@ -4,7 +4,7 @@ import ( "context" "os" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/gobuffalo/packr/builder" "github.com/pkg/errors" ) diff --git a/buffalo/cmd/build/exec.go b/buffalo/cmd/build/exec.go index 883041ad9..7bf0dd686 100644 --- a/buffalo/cmd/build/exec.go +++ b/buffalo/cmd/build/exec.go @@ -6,7 +6,7 @@ import ( "os/exec" "strings" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/pkg/errors" ) diff --git a/buffalo/cmd/build/target.go b/buffalo/cmd/build/target.go index 3e87fe1e3..b1d8ef3cf 100644 --- a/buffalo/cmd/build/target.go +++ b/buffalo/cmd/build/target.go @@ -4,7 +4,7 @@ import ( "os" "path/filepath" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" ) func (b *Builder) prepTarget() error { diff --git a/buffalo/cmd/build/transform.go b/buffalo/cmd/build/transform.go index c6cbdb82a..ac876ef72 100644 --- a/buffalo/cmd/build/transform.go +++ b/buffalo/cmd/build/transform.go @@ -6,7 +6,7 @@ import ( "os" "path/filepath" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/pkg/errors" ) diff --git a/buffalo/cmd/build/transform_main.go b/buffalo/cmd/build/transform_main.go index cf6aedf76..11d691a77 100644 --- a/buffalo/cmd/build/transform_main.go +++ b/buffalo/cmd/build/transform_main.go @@ -6,7 +6,7 @@ import ( "os" "path/filepath" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/gobuffalo/plush" "github.com/pkg/errors" ) diff --git a/buffalo/cmd/destroy/resource.go b/buffalo/cmd/destroy/resource.go index ffc27f42e..af1b51cc2 100644 --- a/buffalo/cmd/destroy/resource.go +++ b/buffalo/cmd/destroy/resource.go @@ -9,7 +9,7 @@ import ( "path/filepath" "strings" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/markbates/inflect" "github.com/spf13/cobra" ) diff --git a/buffalo/cmd/dev.go b/buffalo/cmd/dev.go index 39bcdf561..3b5473e63 100644 --- a/buffalo/cmd/dev.go +++ b/buffalo/cmd/dev.go @@ -6,7 +6,7 @@ import ( "os/exec" "runtime" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/fatih/color" "github.com/gobuffalo/buffalo/generators/assets/webpack" rg "github.com/gobuffalo/buffalo/generators/refresh" diff --git a/buffalo/cmd/new.go b/buffalo/cmd/new.go index 4602949cf..c12cdf965 100644 --- a/buffalo/cmd/new.go +++ b/buffalo/cmd/new.go @@ -5,7 +5,7 @@ import ( "os/user" "path/filepath" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/pkg/errors" diff --git a/buffalo/cmd/plugins.go b/buffalo/cmd/plugins.go index 93b9312be..c52acc0ea 100644 --- a/buffalo/cmd/plugins.go +++ b/buffalo/cmd/plugins.go @@ -6,7 +6,7 @@ import ( "os/exec" "sync" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/gobuffalo/buffalo/plugins" "github.com/gobuffalo/envy" "github.com/spf13/cobra" diff --git a/buffalo/cmd/root.go b/buffalo/cmd/root.go index 41c4574b4..7e57c6ca3 100644 --- a/buffalo/cmd/root.go +++ b/buffalo/cmd/root.go @@ -4,7 +4,7 @@ import ( "errors" "os" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/buffalo/cmd/setup.go b/buffalo/cmd/setup.go index 0d3f5b7c5..acfa47e30 100644 --- a/buffalo/cmd/setup.go +++ b/buffalo/cmd/setup.go @@ -9,7 +9,7 @@ import ( "golang.org/x/sync/errgroup" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/gobuffalo/envy" "github.com/markbates/deplist" "github.com/pkg/errors" diff --git a/buffalo/cmd/test.go b/buffalo/cmd/test.go index 9d6476799..baa9dc88d 100644 --- a/buffalo/cmd/test.go +++ b/buffalo/cmd/test.go @@ -9,7 +9,7 @@ import ( "regexp" "strings" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/gobuffalo/buffalo/meta" "github.com/gobuffalo/envy" "github.com/pkg/errors" diff --git a/buffalo/cmd/version.go b/buffalo/cmd/version.go index 5a1899e75..6a9a133ef 100644 --- a/buffalo/cmd/version.go +++ b/buffalo/cmd/version.go @@ -1,7 +1,7 @@ package cmd import ( - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/generators/action/action.go b/generators/action/action.go index 01520550c..7638a1934 100644 --- a/generators/action/action.go +++ b/generators/action/action.go @@ -6,7 +6,7 @@ import ( "path/filepath" "strings" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/pkg/errors" "github.com/gobuffalo/buffalo/generators" diff --git a/generators/assets/webpack/webpack.go b/generators/assets/webpack/webpack.go index 64a60f2fe..1e0dfc4f2 100644 --- a/generators/assets/webpack/webpack.go +++ b/generators/assets/webpack/webpack.go @@ -4,7 +4,7 @@ import ( "os/exec" "path/filepath" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/gobuffalo/buffalo/generators" "github.com/gobuffalo/buffalo/generators/assets" "github.com/gobuffalo/buffalo/generators/assets/standard" diff --git a/grifts.go b/grifts.go index b208b3285..cc84662b4 100644 --- a/grifts.go +++ b/grifts.go @@ -7,10 +7,10 @@ import ( "strings" "text/tabwriter" - "github.com/Sirupsen/logrus" "github.com/markbates/going/randx" "github.com/markbates/grift/grift" "github.com/pkg/errors" + "github.com/sirupsen/logrus" "golang.org/x/crypto/bcrypt" ) diff --git a/grifts/shoulders.go b/grifts/shoulders.go index 8c6a68101..7a892f6d9 100755 --- a/grifts/shoulders.go +++ b/grifts/shoulders.go @@ -8,7 +8,7 @@ import ( "sort" "strings" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/gobuffalo/envy" "github.com/markbates/deplist" "github.com/markbates/grift/grift" diff --git a/logger.go b/logger.go index 395dfde3a..146d7e7a7 100644 --- a/logger.go +++ b/logger.go @@ -1,7 +1,7 @@ package buffalo import ( - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/gobuffalo/envy" ) diff --git a/logger_formatter.go b/logger_formatter.go index 585715b46..8a1c76935 100644 --- a/logger_formatter.go +++ b/logger_formatter.go @@ -1,6 +1,6 @@ package buffalo -// I really don't want to have this, but until (if) https://github.com/Sirupsen/logrus/pull/606 is merged we're stuck with all this code. And yes, this is ALL needed just to remove some blank space in the logs +// I really don't want to have this, but until (if) https://github.com/sirupsen/logrus/pull/606 is merged we're stuck with all this code. And yes, this is ALL needed just to remove some blank space in the logs import ( "bytes" @@ -12,7 +12,7 @@ import ( "sync" "time" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "golang.org/x/crypto/ssh/terminal" ) diff --git a/options.go b/options.go index 72297c814..5bdebd5a9 100644 --- a/options.go +++ b/options.go @@ -6,7 +6,7 @@ import ( "net/http" "strings" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/fatih/color" "github.com/gobuffalo/buffalo/worker" diff --git a/plugins/plugins.go b/plugins/plugins.go index a896f1a4f..4895faf34 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -11,7 +11,7 @@ import ( "strings" "time" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/pkg/errors" ) diff --git a/render/template.go b/render/template.go index 05f03b12a..49f145987 100644 --- a/render/template.go +++ b/render/template.go @@ -8,7 +8,7 @@ import ( "sort" "strings" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/pkg/errors" // this blank import is here because dep doesn't diff --git a/request_logger.go b/request_logger.go index 019e5f73c..1ea8f24d5 100644 --- a/request_logger.go +++ b/request_logger.go @@ -3,10 +3,10 @@ package buffalo import ( "time" - "github.com/Sirupsen/logrus" humanize "github.com/dustin/go-humanize" "github.com/gobuffalo/x/httpx" "github.com/markbates/going/randx" + "github.com/sirupsen/logrus" ) // RequestLogger can be be overridden to a user specified diff --git a/worker/simple.go b/worker/simple.go index 96cb773af..ef09baf11 100644 --- a/worker/simple.go +++ b/worker/simple.go @@ -5,7 +5,7 @@ import ( "sync" "time" - "github.com/Sirupsen/logrus" + "github.com/sirupsen/logrus" "github.com/pkg/errors" ) From b7495f757d9dee68944894204db55f3e1f2e5152 Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Fri, 15 Dec 2017 16:27:34 -0500 Subject: [PATCH 3/9] changing some log types based in @markbates feedback --- grifts.go | 4 ++-- plugins/plugins.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/grifts.go b/grifts.go index cc84662b4..8d350aed5 100644 --- a/grifts.go +++ b/grifts.go @@ -36,7 +36,7 @@ func secretGrift() { rx := regexp.MustCompile(`(\W+)`) bb = rx.ReplaceAll(bb, []byte("")) s := randx.String(6) + string(bb) - logrus.Infof(s[:127]) + println(s[:127]) return nil }) } @@ -50,7 +50,7 @@ func middlewareGrift(a *App) { } func printMiddleware(a *App) { - logrus.Infof(fmt.Sprintf("-> %s", a.Name)) + logrus.Infof("-> %s", a.Name) logrus.Infof("%v\n", a.Middleware.String()) for _, x := range a.children { printMiddleware(x) diff --git a/plugins/plugins.go b/plugins/plugins.go index 4895faf34..27e3ee946 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -11,8 +11,8 @@ import ( "strings" "time" - "github.com/sirupsen/logrus" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) // List maps a Buffalo command to a slice of Command @@ -83,12 +83,12 @@ func askBin(path string) Commands { cmd.Stderr = bb err := cmd.Run() if err != nil { - logrus.Infof("[PLUGIN] error loading plugin %s: %s\n%s\n", path, err, bb.String()) + logrus.Errorf("[PLUGIN] error loading plugin %s: %s\n%s\n", path, err, bb.String()) return commands } err = json.NewDecoder(bb).Decode(&commands) if err != nil { - logrus.Infof("[PLUGIN] error loading plugin %s: %s\n", path, err) + logrus.Errorf("[PLUGIN] error loading plugin %s: %s\n", path, err) return commands } return commands From 9f5ca4051b7aa6406c41861ed35133e015314ef9 Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Fri, 15 Dec 2017 16:30:16 -0500 Subject: [PATCH 4/9] moving errors to the error level with logrus --- app.go | 8 ++++---- buffalo/cmd/plugins.go | 4 ++-- buffalo/cmd/root.go | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app.go b/app.go index 890a5f5b9..226f53687 100644 --- a/app.go +++ b/app.go @@ -68,7 +68,7 @@ func (a *App) Serve() error { err := a.Stop(ctx.Err()) if err != nil { - logrus.Debug(err) + logrus.Error(err) } if !a.WorkerOff { @@ -76,13 +76,13 @@ func (a *App) Serve() error { logrus.Info("Shutting down worker") err = a.Worker.Stop() if err != nil { - logrus.Debug(err) + logrus.Error(err) } } err = server.Shutdown(ctx) if err != nil { - logrus.Debug(err) + logrus.Error(err) } }() @@ -126,7 +126,7 @@ func (a *App) Serve() error { func (a *App) Stop(err error) error { a.cancel() if err != nil && errors.Cause(err) != context.Canceled { - logrus.Debug(err) + logrus.Error(err) return err } return nil diff --git a/buffalo/cmd/plugins.go b/buffalo/cmd/plugins.go index c52acc0ea..ecd1bdfc1 100644 --- a/buffalo/cmd/plugins.go +++ b/buffalo/cmd/plugins.go @@ -6,9 +6,9 @@ import ( "os/exec" "sync" - "github.com/sirupsen/logrus" "github.com/gobuffalo/buffalo/plugins" "github.com/gobuffalo/envy" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -23,7 +23,7 @@ func plugs() plugins.List { _plugs, err = plugins.Available() if err != nil { _plugs = plugins.List{} - logrus.Info("error loading plugins %s\n", err) + logrus.Errorf("error loading plugins %s\n", err) } } return _plugs diff --git a/buffalo/cmd/root.go b/buffalo/cmd/root.go index 7e57c6ca3..4dea52c5d 100644 --- a/buffalo/cmd/root.go +++ b/buffalo/cmd/root.go @@ -41,7 +41,7 @@ var RootCmd = &cobra.Command{ // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { if err := RootCmd.Execute(); err != nil { - logrus.Debugf("Error: %s\n\n", err) + logrus.Errorf("Error: %s\n\n", err) os.Exit(-1) } } From 83112a86fb13a0caa3fb104fa06d5efe3bdbc44e Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Fri, 15 Dec 2017 16:35:50 -0500 Subject: [PATCH 5/9] loging some other errors/failures with the Error(f) level in logrus --- buffalo/cmd/dev.go | 4 ++-- buffalo/cmd/new.go | 2 +- render/template.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/buffalo/cmd/dev.go b/buffalo/cmd/dev.go index 3b5473e63..6bb6cee01 100644 --- a/buffalo/cmd/dev.go +++ b/buffalo/cmd/dev.go @@ -6,12 +6,12 @@ import ( "os/exec" "runtime" - "github.com/sirupsen/logrus" "github.com/fatih/color" "github.com/gobuffalo/buffalo/generators/assets/webpack" rg "github.com/gobuffalo/buffalo/generators/refresh" "github.com/markbates/refresh/refresh" "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" "golang.org/x/sync/errgroup" ) @@ -39,7 +39,7 @@ This behavior can be changed in your .buffalo.dev.yml file.`, cause = err.Error() } } - logrus.Info(msg, cause) + logrus.Error(msg, cause) }() os.Setenv("GO_ENV", "development") diff --git a/buffalo/cmd/new.go b/buffalo/cmd/new.go index c12cdf965..16846ab89 100644 --- a/buffalo/cmd/new.go +++ b/buffalo/cmd/new.go @@ -89,7 +89,7 @@ func notInGoPath(ag newapp.Generator) error { if err != nil { return err } - logrus.Info(t) + logrus.Error(t) os.Exit(-1) return nil } diff --git a/render/template.go b/render/template.go index 49f145987..9e2b12038 100644 --- a/render/template.go +++ b/render/template.go @@ -8,8 +8,8 @@ import ( "sort" "strings" - "github.com/sirupsen/logrus" "github.com/pkg/errors" + "github.com/sirupsen/logrus" // this blank import is here because dep doesn't // handle transitive dependencies correctly @@ -105,7 +105,7 @@ func (s templateRenderer) exec(name string, data Data) (template.HTML, error) { for _, ext := range s.exts(name) { te, ok := s.TemplateEngines[ext] if !ok { - logrus.Warn("could not find a template engine for %s\n", ext) + logrus.Errorf("could not find a template engine for %s\n", ext) continue } body, err = te(body, data, helpers) From 54bd9cba3c47843337c9cc4e48a7c25ae7b50ede Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Mon, 18 Dec 2017 12:08:33 -0500 Subject: [PATCH 6/9] applying changes from @markbates --- buffalo/cmd/build.go | 4 ++-- buffalo/cmd/build/apkg.go | 8 ++++---- buffalo/cmd/destroy/resource.go | 20 ++++++++++++-------- buffalo/cmd/dev.go | 2 +- buffalo/cmd/setup.go | 4 ++-- generators/action/action.go | 8 ++++---- generators/assets/webpack/webpack.go | 4 ++-- grifts.go | 2 +- options.go | 2 +- 9 files changed, 29 insertions(+), 25 deletions(-) diff --git a/buffalo/cmd/build.go b/buffalo/cmd/build.go index 27698422f..99a912cc1 100644 --- a/buffalo/cmd/build.go +++ b/buffalo/cmd/build.go @@ -5,11 +5,11 @@ import ( "os" "path/filepath" - "github.com/sirupsen/logrus" "github.com/gobuffalo/buffalo/buffalo/cmd/build" "github.com/gobuffalo/buffalo/meta" "github.com/markbates/sigtx" "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -56,7 +56,7 @@ var xbuildCmd = &cobra.Command{ return errors.WithStack(err) } - logrus.Info("\nYou application was successfully built at %s\n", filepath.Join(b.Root, b.Bin)) + logrus.Infof("\nYou application was successfully built at %s\n", filepath.Join(b.Root, b.Bin)) return nil }, diff --git a/buffalo/cmd/build/apkg.go b/buffalo/cmd/build/apkg.go index 5efbf431d..0fb5f0ccb 100644 --- a/buffalo/cmd/build/apkg.go +++ b/buffalo/cmd/build/apkg.go @@ -7,8 +7,8 @@ import ( "os" "path/filepath" - "github.com/sirupsen/logrus" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) func (b *Builder) prepAPackage() error { @@ -88,13 +88,13 @@ func (b *Builder) buildADatabase() error { return errors.WithStack(err) } if !bytes.Contains(bb.Bytes(), []byte("sqlite")) { - logrus.Debugf("no sqlite usage in database.yml detected, applying the nosqlite tag") + logrus.Debug("no sqlite usage in database.yml detected, applying the nosqlite tag") b.Tags = append(b.Tags, "nosqlite") } else if !b.Static { - logrus.Debugf("you are building a SQLite application, please consider using the `--static` flag to compile a static binary") + logrus.Debug("you are building a SQLite application, please consider using the `--static` flag to compile a static binary") } } else { - logrus.Debugf("no database.yml detected, applying the nosqlite tag") + logrus.Debug("no database.yml detected, applying the nosqlite tag") // add the nosqlite build tag if there is no database being used b.Tags = append(b.Tags, "nosqlite") } diff --git a/buffalo/cmd/destroy/resource.go b/buffalo/cmd/destroy/resource.go index af1b51cc2..82c7efdfe 100644 --- a/buffalo/cmd/destroy/resource.go +++ b/buffalo/cmd/destroy/resource.go @@ -9,8 +9,8 @@ import ( "path/filepath" "strings" - "github.com/sirupsen/logrus" "github.com/markbates/inflect" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -32,7 +32,11 @@ var ResourceCmd = &cobra.Command{ fileName := inflect.Pluralize(inflect.Underscore(name)) removeTemplates(fileName) - removeActions(fileName) + err := removeActions(fileName) + if err != nil { + return err + } + removeLocales(fileName) removeModel(name) removeMigrations(fileName) @@ -52,12 +56,12 @@ func confirm(msg string) bool { func removeTemplates(fileName string) { if YesToAll || confirm("Want to remove templates? (Y/n)") { templatesFolder := fmt.Sprintf(filepath.Join("templates", fileName)) - logrus.Info("- Deleted %v folder\n", templatesFolder) + logrus.Infof("- Deleted %v folder\n", templatesFolder) os.RemoveAll(templatesFolder) } } -func removeActions(fileName string) { +func removeActions(fileName string) error { if YesToAll || confirm("Want to remove actions? (Y/n)") { logrus.Infof("- Deleted %v\n", fmt.Sprintf("actions/%v.go", fileName)) os.Remove(filepath.Join("actions", fmt.Sprintf("%v.go", fileName))) @@ -67,8 +71,8 @@ func removeActions(fileName string) { content, err := ioutil.ReadFile(filepath.Join("actions", "app.go")) if err != nil { - logrus.Info("[WARNING] error reading app.go content") - return + logrus.Warn("error reading app.go content") + return err } resourceExpression := fmt.Sprintf("app.Resource(\"/%v\", %vResource{})", fileName, inflect.Camelize(fileName)) @@ -76,8 +80,8 @@ func removeActions(fileName string) { err = ioutil.WriteFile(filepath.Join("actions", "app.go"), []byte(newContents), 0) if err != nil { - logrus.Info("[WARNING] error writing new app.go content") - return + logrus.Error("error writing new app.go content") + return err } logrus.Infof("- Deleted References for %v in actions/app.go\n", fileName) diff --git a/buffalo/cmd/dev.go b/buffalo/cmd/dev.go index 6bb6cee01..e50f97ba7 100644 --- a/buffalo/cmd/dev.go +++ b/buffalo/cmd/dev.go @@ -39,7 +39,7 @@ This behavior can be changed in your .buffalo.dev.yml file.`, cause = err.Error() } } - logrus.Error(msg, cause) + logrus.Errorf(msg, cause) }() os.Setenv("GO_ENV", "development") diff --git a/buffalo/cmd/setup.go b/buffalo/cmd/setup.go index acfa47e30..4bd26e2d7 100644 --- a/buffalo/cmd/setup.go +++ b/buffalo/cmd/setup.go @@ -9,10 +9,10 @@ import ( "golang.org/x/sync/errgroup" - "github.com/sirupsen/logrus" "github.com/gobuffalo/envy" "github.com/markbates/deplist" "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -214,7 +214,7 @@ func nodeCheck() error { } func run(cmd *exec.Cmd) error { - logrus.Info("--> %s\n", strings.Join(cmd.Args, " ")) + logrus.Infof("--> %s\n", strings.Join(cmd.Args, " ")) cmd.Stdin = os.Stdin cmd.Stderr = os.Stderr cmd.Stdout = os.Stdout diff --git a/generators/action/action.go b/generators/action/action.go index 7638a1934..1ad12bd83 100644 --- a/generators/action/action.go +++ b/generators/action/action.go @@ -6,8 +6,8 @@ import ( "path/filepath" "strings" - "github.com/sirupsen/logrus" "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/gobuffalo/buffalo/generators" "github.com/gobuffalo/buffalo/meta" @@ -101,7 +101,7 @@ func (act Generator) findActionsToAdd(path string) []meta.Name { for _, action := range act.Actions { funcSignature := fmt.Sprintf("func %s%s(c buffalo.Context) error", act.Name.Camel(), action.Camel()) if strings.Contains(string(fileContents), funcSignature) { - logrus.Infof("--> [warning] skipping %v%v since it already exists\n", act.Name.Camel(), action.Camel()) + logrus.Warnf("--> skipping %v%v since it already exists\n", act.Name.Camel(), action.Camel()) continue } @@ -122,7 +122,7 @@ func (act Generator) findHandlersToAdd(path string) []meta.Name { for _, action := range act.Actions { funcSignature := fmt.Sprintf("app.GET(\"/%s/%s\", %s%s)", act.Name.URL(), action.URL(), act.Name.Camel(), action.Camel()) if strings.Contains(string(fileContents), funcSignature) { - logrus.Infof("--> [warning] skipping %s from app.go since it already exists\n", funcSignature) + logrus.Warnf("--> skipping %s from app.go since it already exists\n", funcSignature) continue } @@ -143,7 +143,7 @@ func (act Generator) findTestsToAdd(path string) []meta.Name { for _, action := range act.Actions { funcSignature := fmt.Sprintf("func (as *ActionSuite) Test_%v_%v() {", act.Name.Camel(), action.Camel()) if strings.Contains(string(fileContents), funcSignature) { - logrus.Infof("--> [warning] skipping Test_%v_%v since it already exists\n", act.Name.Camel(), action.Camel()) + logrus.Warnf("--> skipping Test_%v_%v since it already exists\n", act.Name.Camel(), action.Camel()) continue } diff --git a/generators/assets/webpack/webpack.go b/generators/assets/webpack/webpack.go index 1e0dfc4f2..b3157665b 100644 --- a/generators/assets/webpack/webpack.go +++ b/generators/assets/webpack/webpack.go @@ -4,12 +4,12 @@ import ( "os/exec" "path/filepath" - "github.com/sirupsen/logrus" "github.com/gobuffalo/buffalo/generators" "github.com/gobuffalo/buffalo/generators/assets" "github.com/gobuffalo/buffalo/generators/assets/standard" "github.com/gobuffalo/makr" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) var logo = &makr.RemoteFile{ @@ -26,7 +26,7 @@ func (w Generator) Run(root string, data makr.Data) error { // if there's no npm, return! if _, err := exec.LookPath("npm"); err != nil { - logrus.Infof("Could not find npm. Skipping webpack generation.") + logrus.Info("Could not find npm. Skipping webpack generation.") return standard.Run(root, data) } diff --git a/grifts.go b/grifts.go index 8d350aed5..57cff0fd6 100644 --- a/grifts.go +++ b/grifts.go @@ -36,7 +36,7 @@ func secretGrift() { rx := regexp.MustCompile(`(\W+)`) bb = rx.ReplaceAll(bb, []byte("")) s := randx.String(6) + string(bb) - println(s[:127]) + fmt.Println(s[:127]) return nil }) } diff --git a/options.go b/options.go index 5bdebd5a9..9dd446454 100644 --- a/options.go +++ b/options.go @@ -122,7 +122,7 @@ func optionsWithDefaults(opts Options) Options { secret := envy.Get("SESSION_SECRET", "") // In production a SESSION_SECRET must be set! if opts.Env == "production" && secret == "" { - logrus.Warn("WARNING! Unless you set SESSION_SECRET env variable, your session storage is not protected!") + logrus.Warn("Unless you set SESSION_SECRET env variable, your session storage is not protected!") } opts.SessionStore = sessions.NewCookieStore([]byte(secret)) } From 955d1974e5ceb7e14b177123c3e6cb291d56e761 Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Mon, 18 Dec 2017 12:21:48 -0500 Subject: [PATCH 7/9] making resources pass --- buffalo/cmd/destroy/resource.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/buffalo/cmd/destroy/resource.go b/buffalo/cmd/destroy/resource.go index 82c7efdfe..c341c1cf3 100644 --- a/buffalo/cmd/destroy/resource.go +++ b/buffalo/cmd/destroy/resource.go @@ -86,6 +86,8 @@ func removeActions(fileName string) error { logrus.Infof("- Deleted References for %v in actions/app.go\n", fileName) } + + return nil } func removeLocales(fileName string) { From 272efaaffc5185c8c7dadf235f439e5c787625bc Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Wed, 20 Dec 2017 16:51:42 -0500 Subject: [PATCH 8/9] moving printMiddleware to use fmt.Printf --- grifts.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/grifts.go b/grifts.go index 57cff0fd6..4a3ef4010 100644 --- a/grifts.go +++ b/grifts.go @@ -10,7 +10,6 @@ import ( "github.com/markbates/going/randx" "github.com/markbates/grift/grift" "github.com/pkg/errors" - "github.com/sirupsen/logrus" "golang.org/x/crypto/bcrypt" ) @@ -50,8 +49,8 @@ func middlewareGrift(a *App) { } func printMiddleware(a *App) { - logrus.Infof("-> %s", a.Name) - logrus.Infof("%v\n", a.Middleware.String()) + fmt.Printf("-> %s ", a.Name) + fmt.Printf("%v\n", a.Middleware.String()) for _, x := range a.children { printMiddleware(x) } From a44841a7593dc96f4e500d2d701b762a6790bde4 Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Wed, 20 Dec 2017 17:12:16 -0500 Subject: [PATCH 9/9] adding missing newline --- grifts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grifts.go b/grifts.go index 4a3ef4010..7901f662d 100644 --- a/grifts.go +++ b/grifts.go @@ -49,7 +49,7 @@ func middlewareGrift(a *App) { } func printMiddleware(a *App) { - fmt.Printf("-> %s ", a.Name) + fmt.Printf("-> %s\n", a.Name) fmt.Printf("%v\n", a.Middleware.String()) for _, x := range a.children { printMiddleware(x)