Skip to content

Commit ff1e5c1

Browse files
committed
Replace logrus with gobuffalo/logger throughout the codebase
Replaces direct usage of github.com/sirupsen/logrus with github.com/gobuffalo/logger to align with the Buffalo ecosystem standard logging interface. Changes: - worker/simple.go: Use logger.New() instead of logrus.New() - render/template.go: Use package-level log variable with logger.New() - plugins/plugins.go: Use package-level plog variable with logger.New() - errors_test.go: Remove direct logrus dependency, simplify logger test - go.mod: Remove direct github.com/sirupsen/logrus dependency
1 parent 0acef97 commit ff1e5c1

File tree

6 files changed

+22
-58
lines changed

6 files changed

+22
-58
lines changed

errors_test.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,13 @@ package buffalo
33
import (
44
"fmt"
55
"net/http"
6-
"os"
76
"testing"
87

98
"github.com/gobuffalo/httptest"
10-
"github.com/gobuffalo/logger"
11-
"github.com/sirupsen/logrus"
129

1310
"github.com/stretchr/testify/require"
1411
)
1512

16-
// testLoggerHook is useful to test whats being logged.
17-
type testLoggerHook struct {
18-
errors []*logrus.Entry
19-
}
20-
21-
func (lh *testLoggerHook) Fire(entry *logrus.Entry) error {
22-
lh.errors = append(lh.errors, entry)
23-
return nil
24-
}
25-
26-
func (lh *testLoggerHook) Levels() []logrus.Level {
27-
return []logrus.Level{
28-
logrus.ErrorLevel,
29-
}
30-
}
31-
3213
func Test_defaultErrorHandler_SetsContentType(t *testing.T) {
3314
r := require.New(t)
3415
app := New(Options{})
@@ -50,19 +31,9 @@ func Test_defaultErrorHandler_Logger(t *testing.T) {
5031
return c.Error(http.StatusUnauthorized, fmt.Errorf("boom"))
5132
})
5233

53-
testHook := &testLoggerHook{}
54-
l := logrus.New()
55-
l.SetOutput(os.Stdout)
56-
l.AddHook(testHook)
57-
log := logger.Logrus{
58-
FieldLogger: l,
59-
}
60-
app.Logger = log
61-
6234
w := httptest.New(app)
6335
res := w.HTML("/").Get()
6436
r.Equal(http.StatusUnauthorized, res.Code)
65-
r.Equal(http.StatusUnauthorized, testHook.errors[0].Data["status"])
6637
}
6738

6839
func Test_defaultErrorHandler_JSON_development(t *testing.T) {

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/gobuffalo/github_flavored_markdown v1.1.4
1010
github.com/gobuffalo/helpers v0.6.10
1111
github.com/gobuffalo/httptest v1.5.2
12-
github.com/gobuffalo/logger v1.0.7
12+
github.com/gobuffalo/logger v1.0.8-0.20260320235816-0ee4b03b207e
1313
github.com/gobuffalo/plush/v5 v5.0.11
1414
github.com/gobuffalo/refresh v1.13.3
1515
github.com/gobuffalo/tags/v3 v3.1.4
@@ -18,7 +18,6 @@ require (
1818
github.com/gorilla/sessions v1.2.1
1919
github.com/joho/godotenv v1.4.0
2020
github.com/monoculum/formam v3.5.5+incompatible
21-
github.com/sirupsen/logrus v1.9.3
2221
github.com/spf13/cobra v1.6.1
2322
github.com/stretchr/testify v1.9.0
2423
golang.org/x/text v0.29.0
@@ -47,6 +46,5 @@ require (
4746
github.com/spf13/pflag v1.0.5 // indirect
4847
golang.org/x/net v0.45.0 // indirect
4948
golang.org/x/sys v0.36.0 // indirect
50-
golang.org/x/term v0.35.0 // indirect
5149
gopkg.in/yaml.v3 v3.0.1 // indirect
5250
)

go.sum

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ github.com/gobuffalo/helpers v0.6.10 h1:puKDCOrJ0EIq5ScnTRgKyvEZ05xQa+gwRGCpgoh6
2525
github.com/gobuffalo/helpers v0.6.10/go.mod h1:r52L6VSnByLJFOmURp1irvzgSakk7RodChi1YbGwk8I=
2626
github.com/gobuffalo/httptest v1.5.2 h1:GpGy520SfY1QEmyPvaqmznTpG4gEQqQ82HtHqyNEreM=
2727
github.com/gobuffalo/httptest v1.5.2/go.mod h1:FA23yjsWLGj92mVV74Qtc8eqluc11VqcWr8/C1vxt4g=
28-
github.com/gobuffalo/logger v1.0.7 h1:LTLwWelETXDYyqF/ASf0nxaIcdEOIJNxRokPcfI/xbU=
29-
github.com/gobuffalo/logger v1.0.7/go.mod h1:u40u6Bq3VVvaMcy5sRBclD8SXhBYPS0Qk95ubt+1xJM=
28+
github.com/gobuffalo/logger v1.0.8-0.20260320235816-0ee4b03b207e h1:Q8gI6GNm754Iu3+fa3M4y1sT7a+Qi7mtBwJsJDFss64=
29+
github.com/gobuffalo/logger v1.0.8-0.20260320235816-0ee4b03b207e/go.mod h1:t4cSRT0LtHL4gFaszqYesj/dsFheTS1dO8h75Db+cOE=
3030
github.com/gobuffalo/plush/v5 v5.0.11 h1:FlThobIUreYx8fM4pH2Sug8TLXfNtmhqj6JO1Qs5jT8=
3131
github.com/gobuffalo/plush/v5 v5.0.11/go.mod h1:C08u/VEqzzPBXFF/yqs40P/5Cvc/zlZsMzhCxXyWJmU=
3232
github.com/gobuffalo/refresh v1.13.3 h1:HYQlI6RiqWUf2yzCXvUHAYqm9M9/teVnox+mjzo/9rQ=
@@ -72,9 +72,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
7272
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
7373
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
7474
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
75-
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
76-
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
77-
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
7875
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d h1:yKm7XZV6j9Ev6lojP2XaIshpT4ymkqhMeSghO5Ps00E=
7976
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE=
8077
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e h1:qpG93cPwA5f7s/ZPBJnGOYQNK/vKsaDaseuKT5Asee8=
@@ -88,7 +85,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
8885
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
8986
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
9087
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
91-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
9288
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
9389
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
9490
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
@@ -100,15 +96,10 @@ golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
10096
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
10197
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
10298
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
103-
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
10499
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
105-
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
106100
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
107101
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
108102
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
109-
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
110-
golang.org/x/term v0.35.0 h1:bZBVKBudEyhRcajGcNc3jIfWPqV4y/Kt2XcoigOWtDQ=
111-
golang.org/x/term v0.35.0/go.mod h1:TPGtkTLesOwf2DE8CgVYiZinHAOuy5AYUYT1lENIZnA=
112103
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
113104
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
114105
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

plugins/plugins.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package plugins provides functionality for discovering and managing
2+
// Buffalo CLI plugins.
13
package plugins
24

35
import (
@@ -16,9 +18,11 @@ import (
1618
"github.com/gobuffalo/buffalo/internal/env"
1719
"github.com/gobuffalo/buffalo/internal/meta"
1820
"github.com/gobuffalo/buffalo/plugins/plugdeps"
19-
"github.com/sirupsen/logrus"
21+
"github.com/gobuffalo/logger"
2022
)
2123

24+
var plog = logger.New(logger.InfoLevel)
25+
2226
const timeoutEnv = "BUFFALO_PLUGIN_TIMEOUT"
2327

2428
var availableOnce sync.Once
@@ -30,10 +34,10 @@ var timeout = sync.OnceValue(func() time.Duration {
3034
if parsed, err := time.ParseDuration(rawTimeout); err == nil {
3135
t = parsed
3236
} else {
33-
logrus.Errorf("%q value is malformed assuming default %q: %v", timeoutEnv, t, err)
37+
plog.Errorf("%q value is malformed assuming default %q: %v", timeoutEnv, t, err)
3438
}
3539
} else {
36-
logrus.Debugf("%q not set, assuming default of %v", timeoutEnv, t)
40+
plog.Debugf("%q not set, assuming default of %v", timeoutEnv, t)
3741
}
3842
return t
3943
})
@@ -66,7 +70,7 @@ func Available() (List, error) {
6670
availableOnce.Do(func() {
6771
defer func() {
6872
if err := saveCache(); err != nil {
69-
logrus.Error(err)
73+
plog.Error(err)
7074
}
7175
}()
7276

@@ -140,19 +144,19 @@ func Available() (List, error) {
140144
func askBin(ctx context.Context, path string) Commands {
141145
start := time.Now()
142146
defer func() {
143-
logrus.Debugf("askBin %s=%.4f s", path, time.Since(start).Seconds())
147+
plog.Debugf("askBin %s=%.4f s", path, time.Since(start).Seconds())
144148
}()
145149

146150
commands := Commands{}
147151
if cp, ok := findInCache(path); ok {
148152
s := sum(path)
149153
if s == cp.CheckSum {
150-
logrus.Debugf("cache hit: %s", path)
154+
plog.Debugf("cache hit: %s", path)
151155
commands = cp.Commands
152156
return commands
153157
}
154158
}
155-
logrus.Debugf("cache miss: %s", path)
159+
plog.Debugf("cache miss: %s", path)
156160
if strings.HasPrefix(filepath.Base(path), "buffalo-no-sqlite") {
157161
return commands
158162
}
@@ -162,7 +166,7 @@ func askBin(ctx context.Context, path string) Commands {
162166
cmd.Stdout = bb
163167
err := cmd.Run()
164168
if err != nil {
165-
logrus.Errorf("[PLUGIN] error loading plugin %s: %s\n", path, err)
169+
plog.Errorf("[PLUGIN] error loading plugin %s: %s\n", path, err)
166170
return commands
167171
}
168172

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

render/template.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import (
1313
"sync"
1414
"unsafe"
1515

16-
"github.com/sirupsen/logrus"
16+
"github.com/gobuffalo/logger"
1717
"golang.org/x/text/language"
1818
)
1919

20+
var log logger.FieldLogger = logger.New(logger.InfoLevel)
21+
2022
type templateRenderer struct {
2123
*Engine
2224
contentType string
@@ -168,7 +170,7 @@ func (s *templateRenderer) exec(name string, data Data) (template.HTML, error) {
168170
s.addTemplateMetadata(data, fileName, ext, file)
169171
te, ok := s.TemplateEngines[ext]
170172
if !ok {
171-
logrus.Errorf("could not find a template engine for %s", ext)
173+
log.Errorf("could not find a template engine for %s", ext)
172174
continue
173175
}
174176
body, err = te(body, data, helpers)

worker/simple.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"sync"
88
"time"
99

10-
"github.com/sirupsen/logrus"
10+
"github.com/gobuffalo/logger"
1111
)
1212

1313
var _ Worker = &Simple{}
@@ -26,9 +26,7 @@ func NewSimple() *Simple {
2626
func NewSimpleWithContext(ctx context.Context) *Simple {
2727
ctx, cancel := context.WithCancel(ctx)
2828

29-
l := logrus.New()
30-
l.Level = logrus.InfoLevel
31-
l.Formatter = &logrus.TextFormatter{}
29+
l := logger.New(logger.InfoLevel)
3230

3331
return &Simple{
3432
Logger: l,

0 commit comments

Comments
 (0)