Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Moving log and fmt PrintX to be logrus Info and Debug #796

Merged
merged 16 commits into from
Dec 20, 2017

Conversation

paganotoni
Copy link
Member

This is related with #765

Copy link
Member

@markbates markbates left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it looks good. Note that the Siruspen repo was moved a while ago to siruspen so all of the import statements in this PR are a regression, so that needs to be fixed. There are also a bunch of places where errors are being logged, those should go to the Error logger. I also found at least one place where the output shouldn't go to the logger, but is meant to be printed to the screen as is.

app.go Outdated

err := a.Stop(ctx.Err())
if err != nil {
fmt.Println(err)
logrus.Debug(err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be sent to the Error logger.

app.go Outdated
err = a.Worker.Stop()
if err != nil {
fmt.Println(err)
logrus.Debug(err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be sent to the Error logger.

app.go Outdated
}
}

err = server.Shutdown(ctx)
if err != nil {
fmt.Println(err)
logrus.Debug(err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be sent to the Error logger.

app.go Outdated
@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be sent to the Error logger.

@@ -4,7 +4,7 @@ import (
"os"
"path/filepath"

"github.com/sirupsen/logrus"
"github.com/Sirupsen/logrus"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repo is now lower case sirupsen. Can you please undo these import changes?

@@ -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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error logger

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error logger

"os"
"path/filepath"
"sort"
"strings"

"github.com/Sirupsen/logrus"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repo is now lower case sirupsen. Can you please undo these import changes?

@@ -3,10 +3,10 @@ package buffalo
import (
"time"

"github.com/Sirupsen/logrus"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repo is now lower case sirupsen. Can you please undo these import changes?

worker/simple.go Outdated
@@ -5,8 +5,8 @@ import (
"sync"
"time"

"github.com/Sirupsen/logrus"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repo is now lower case sirupsen. Can you please undo these import changes?

@paganotoni
Copy link
Member Author

@markbates thanks for the feedback, all these have been implemented, let me know how is it looking when you have the chance, thanks again!

@@ -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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be Infof

@@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be just Debug

@@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be just Debug

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be Infof

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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Warn and we can remove the warning label

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Warnf and we can remove the warning label

@@ -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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Warnf and we can remove the warning label

@@ -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.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Info

grifts.go Outdated
@@ -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])
println(s[:127])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still be using fmt.Println

options.go Outdated
@@ -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!")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove the warning label

@paganotoni
Copy link
Member Author

@markbates next round of changes applied :)

grifts.go Outdated
fmt.Println(fmt.Sprintf("-> %s", a.Name))
fmt.Println(a.Middleware.String())
fmt.Println()
logrus.Infof("-> %s", a.Name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function needs to go back to using Println.

Copy link
Member

@markbates markbates left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just the one comment and then we're good to go!

@paganotoni
Copy link
Member Author

@markbates all set :)

grifts.go Outdated
fmt.Println(fmt.Sprintf("-> %s", a.Name))
fmt.Println(a.Middleware.String())
fmt.Println()
fmt.Printf("-> %s ", a.Name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for this, but this statement is missing a newline. Last change, I swear! :)

@paganotoni
Copy link
Member Author

lol, now all set

@markbates markbates merged commit ec4fab3 into development Dec 20, 2017
@markbates
Copy link
Member

Awesome! Thanks.

@paganotoni
Copy link
Member Author

Thank you for all the help here!

@paganotoni paganotoni deleted the task/moving-logs-to-logrus branch December 20, 2017 22:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants