Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions default_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (

"github.com/gobuffalo/buffalo/render"
"github.com/gobuffalo/httptest"
"github.com/gobuffalo/logger"
"github.com/gobuffalo/logger/v2"
"github.com/stretchr/testify/require"
)

func basicContext() DefaultContext {
return DefaultContext{
Context: context.Background(),
logger: logger.New(logger.DebugLevel),
logger: logger.Default(),
data: newRequestData(),
flash: &Flash{data: make(map[string][]string)},
}
Expand Down
29 changes: 0 additions & 29 deletions errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,13 @@ package buffalo
import (
"fmt"
"net/http"
"os"
"testing"

"github.com/gobuffalo/httptest"
"github.com/gobuffalo/logger"
"github.com/sirupsen/logrus"

"github.com/stretchr/testify/require"
)

// testLoggerHook is useful to test whats being logged.
type testLoggerHook struct {
errors []*logrus.Entry
}

func (lh *testLoggerHook) Fire(entry *logrus.Entry) error {
lh.errors = append(lh.errors, entry)
return nil
}

func (lh *testLoggerHook) Levels() []logrus.Level {
return []logrus.Level{
logrus.ErrorLevel,
}
}

func Test_defaultErrorHandler_SetsContentType(t *testing.T) {
r := require.New(t)
app := New(Options{})
Expand All @@ -50,19 +31,9 @@ func Test_defaultErrorHandler_Logger(t *testing.T) {
return c.Error(http.StatusUnauthorized, fmt.Errorf("boom"))
})

testHook := &testLoggerHook{}
l := logrus.New()
l.SetOutput(os.Stdout)
l.AddHook(testHook)
log := logger.Logrus{
FieldLogger: l,
}
app.Logger = log

w := httptest.New(app)
res := w.HTML("/").Get()
r.Equal(http.StatusUnauthorized, res.Code)
r.Equal(http.StatusUnauthorized, testHook.errors[0].Data["status"])
}

func Test_defaultErrorHandler_JSON_development(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/gobuffalo/github_flavored_markdown v1.1.4
github.com/gobuffalo/helpers v0.6.10
github.com/gobuffalo/httptest v1.5.2
github.com/gobuffalo/logger v1.0.7
github.com/gobuffalo/logger/v2 v2.0.1
github.com/gobuffalo/plush/v5 v5.0.11
github.com/gobuffalo/refresh v1.13.3
github.com/gobuffalo/tags/v3 v3.1.4
Expand All @@ -18,7 +18,6 @@ require (
github.com/gorilla/sessions v1.2.1
github.com/joho/godotenv v1.4.0
github.com/monoculum/formam v3.5.5+incompatible
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.6.1
github.com/stretchr/testify v1.9.0
golang.org/x/text v0.29.0
Expand Down Expand Up @@ -47,6 +46,5 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.45.0 // indirect
golang.org/x/sys v0.36.0 // indirect
golang.org/x/term v0.35.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
13 changes: 2 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ github.com/gobuffalo/helpers v0.6.10 h1:puKDCOrJ0EIq5ScnTRgKyvEZ05xQa+gwRGCpgoh6
github.com/gobuffalo/helpers v0.6.10/go.mod h1:r52L6VSnByLJFOmURp1irvzgSakk7RodChi1YbGwk8I=
github.com/gobuffalo/httptest v1.5.2 h1:GpGy520SfY1QEmyPvaqmznTpG4gEQqQ82HtHqyNEreM=
github.com/gobuffalo/httptest v1.5.2/go.mod h1:FA23yjsWLGj92mVV74Qtc8eqluc11VqcWr8/C1vxt4g=
github.com/gobuffalo/logger v1.0.7 h1:LTLwWelETXDYyqF/ASf0nxaIcdEOIJNxRokPcfI/xbU=
github.com/gobuffalo/logger v1.0.7/go.mod h1:u40u6Bq3VVvaMcy5sRBclD8SXhBYPS0Qk95ubt+1xJM=
github.com/gobuffalo/logger/v2 v2.0.1 h1:0+Nn5ttjB2V9G9vsImv+4c1BVgmLOHIZ18ykbnoWo1k=
github.com/gobuffalo/logger/v2 v2.0.1/go.mod h1:VKjrMWUWvBALWBWttrMAUNBqcbooxR5QZ0fPURxz03A=
github.com/gobuffalo/plush/v5 v5.0.11 h1:FlThobIUreYx8fM4pH2Sug8TLXfNtmhqj6JO1Qs5jT8=
github.com/gobuffalo/plush/v5 v5.0.11/go.mod h1:C08u/VEqzzPBXFF/yqs40P/5Cvc/zlZsMzhCxXyWJmU=
github.com/gobuffalo/refresh v1.13.3 h1:HYQlI6RiqWUf2yzCXvUHAYqm9M9/teVnox+mjzo/9rQ=
Expand Down Expand Up @@ -72,9 +72,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d h1:yKm7XZV6j9Ev6lojP2XaIshpT4ymkqhMeSghO5Ps00E=
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE=
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e h1:qpG93cPwA5f7s/ZPBJnGOYQNK/vKsaDaseuKT5Asee8=
Expand All @@ -88,7 +85,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
Expand All @@ -100,15 +96,10 @@ golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.35.0 h1:bZBVKBudEyhRcajGcNc3jIfWPqV4y/Kt2XcoigOWtDQ=
golang.org/x/term v0.35.0/go.mod h1:TPGtkTLesOwf2DE8CgVYiZinHAOuy5AYUYT1lENIZnA=
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
2 changes: 1 addition & 1 deletion logger.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package buffalo

import (
"github.com/gobuffalo/logger"
"github.com/gobuffalo/logger/v2"
)

// Logger interface is used throughout Buffalo
Expand Down
3 changes: 2 additions & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/gobuffalo/buffalo/internal/defaults"
"github.com/gobuffalo/buffalo/internal/env"
"github.com/gobuffalo/buffalo/worker"
"github.com/gobuffalo/logger"
"github.com/gobuffalo/logger/v2"
"github.com/gorilla/sessions"
)

Expand Down Expand Up @@ -124,6 +124,7 @@ func optionsWithDefaults(opts Options) Options {
}

opts.Logger = logger.New(opts.LogLvl)
logger.SetDefault(opts.Logger)
}

if opts.SessionStore == nil {
Expand Down
22 changes: 13 additions & 9 deletions plugins/plugins.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package plugins provides functionality for discovering and managing
// Buffalo CLI plugins.
package plugins

import (
Expand All @@ -16,9 +18,11 @@ import (
"github.com/gobuffalo/buffalo/internal/env"
"github.com/gobuffalo/buffalo/internal/meta"
"github.com/gobuffalo/buffalo/plugins/plugdeps"
"github.com/sirupsen/logrus"
"github.com/gobuffalo/logger/v2"
)

var plog = logger.Default()

const timeoutEnv = "BUFFALO_PLUGIN_TIMEOUT"

var availableOnce sync.Once
Expand All @@ -30,10 +34,10 @@ var timeout = sync.OnceValue(func() time.Duration {
if parsed, err := time.ParseDuration(rawTimeout); err == nil {
t = parsed
} else {
logrus.Errorf("%q value is malformed assuming default %q: %v", timeoutEnv, t, err)
plog.Errorf("%q value is malformed assuming default %q: %v", timeoutEnv, t, err)
}
} else {
logrus.Debugf("%q not set, assuming default of %v", timeoutEnv, t)
plog.Debugf("%q not set, assuming default of %v", timeoutEnv, t)
}
return t
})
Expand Down Expand Up @@ -66,7 +70,7 @@ func Available() (List, error) {
availableOnce.Do(func() {
defer func() {
if err := saveCache(); err != nil {
logrus.Error(err)
plog.Error(err)
}
}()

Expand Down Expand Up @@ -140,19 +144,19 @@ func Available() (List, error) {
func askBin(ctx context.Context, path string) Commands {
start := time.Now()
defer func() {
logrus.Debugf("askBin %s=%.4f s", path, time.Since(start).Seconds())
plog.Debugf("askBin %s=%.4f s", path, time.Since(start).Seconds())
}()

commands := Commands{}
if cp, ok := findInCache(path); ok {
s := sum(path)
if s == cp.CheckSum {
logrus.Debugf("cache hit: %s", path)
plog.Debugf("cache hit: %s", path)
commands = cp.Commands
return commands
}
}
logrus.Debugf("cache miss: %s", path)
plog.Debugf("cache miss: %s", path)
if strings.HasPrefix(filepath.Base(path), "buffalo-no-sqlite") {
return commands
}
Expand All @@ -162,7 +166,7 @@ func askBin(ctx context.Context, path string) Commands {
cmd.Stdout = bb
err := cmd.Run()
if err != nil {
logrus.Errorf("[PLUGIN] error loading plugin %s: %s\n", path, err)
plog.Errorf("[PLUGIN] error loading plugin %s: %s\n", path, err)
return commands
}

Expand All @@ -177,7 +181,7 @@ func askBin(ctx context.Context, path string) Commands {
}
msg = msg[1:]
}
logrus.Errorf("[PLUGIN] error decoding plugin %s: %s\n%s\n", path, err, msg)
plog.Errorf("[PLUGIN] error decoding plugin %s: %s\n%s\n", path, err, msg)
return commands
}

Expand Down
6 changes: 4 additions & 2 deletions render/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import (
"sync"
"unsafe"

"github.com/sirupsen/logrus"
"github.com/gobuffalo/logger/v2"
"golang.org/x/text/language"
)

var log logger.FieldLogger = logger.Default()

type templateRenderer struct {
*Engine
contentType string
Expand Down Expand Up @@ -168,7 +170,7 @@ func (s *templateRenderer) exec(name string, data Data) (template.HTML, error) {
s.addTemplateMetadata(data, fileName, ext, file)
te, ok := s.TemplateEngines[ext]
if !ok {
logrus.Errorf("could not find a template engine for %s", ext)
log.Errorf("could not find a template engine for %s", ext)
continue
}
body, err = te(body, data, helpers)
Expand Down
8 changes: 2 additions & 6 deletions worker/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"
"time"

"github.com/sirupsen/logrus"
"github.com/gobuffalo/logger/v2"
)

var _ Worker = &Simple{}
Expand All @@ -26,12 +26,8 @@ func NewSimple() *Simple {
func NewSimpleWithContext(ctx context.Context) *Simple {
ctx, cancel := context.WithCancel(ctx)

l := logrus.New()
l.Level = logrus.InfoLevel
l.Formatter = &logrus.TextFormatter{}

return &Simple{
Logger: l,
Logger: logger.Default(),
ctx: ctx,
cancel: cancel,
handlers: map[string]Handler{},
Expand Down
Loading