[F3] set the logger for all drivers

The logger is set for the local Forgejo driver only. Even when --debug
is specified, the other drivers do not display debug
information. Use the gof3 context to set the logger for all of them at
once.
This commit is contained in:
Earl Warren 2023-09-09 20:00:16 +02:00
parent 87b8cfe5a1
commit 8aa7de8ba0
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
5 changed files with 22 additions and 25 deletions

View file

@ -6,14 +6,33 @@ import (
"context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
_ "code.gitea.io/gitea/services/f3/driver" // register the driver
"github.com/urfave/cli/v2"
f3_cmd "lab.forgefriends.org/friendlyforgeformat/gof3/cmd"
f3_types "lab.forgefriends.org/friendlyforgeformat/gof3/config/types"
)
func F3Logger() *f3_types.Logger {
messenger := func(message string, args ...interface{}) {
log.Info("Message: "+message, args...)
}
return &f3_types.Logger{
Message: f3_types.LoggerFun(messenger),
Trace: log.Trace,
Debug: log.Debug,
Info: log.Info,
Warn: log.Warn,
Error: log.Error,
Critical: log.Critical,
Fatal: log.Fatal,
}
}
func CmdF3(ctx context.Context) *cli.Command {
ctx = f3_types.ContextSetLogger(ctx, F3Logger())
return &cli.Command{
Name: "f3",
Usage: "F3",

2
go.mod
View file

@ -118,7 +118,7 @@ require (
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v3 v3.0.1
lab.forgefriends.org/friendlyforgeformat/gof3 v1.0.1-0.20230908154825-4143ad6e0e14
lab.forgefriends.org/friendlyforgeformat/gof3 v1.0.1-0.20230909181317-1e49a01bb3b7
mvdan.cc/xurls/v2 v2.5.0
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
xorm.io/builder v0.3.13

4
go.sum
View file

@ -1596,8 +1596,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
lab.forgefriends.org/friendlyforgeformat/gof3 v1.0.1-0.20230908154825-4143ad6e0e14 h1:zO8alnKMKqWXQIpygY93BwGuBpTQwcsi9dR46mp/v2U=
lab.forgefriends.org/friendlyforgeformat/gof3 v1.0.1-0.20230908154825-4143ad6e0e14/go.mod h1:TcKaEsgVihjAjw290iDvvirCT0P+DZNpzc0ZgNgy3E4=
lab.forgefriends.org/friendlyforgeformat/gof3 v1.0.1-0.20230909181317-1e49a01bb3b7 h1:7/4APz7dLeZ51rBxBQjwCpZBmJeOEhLIQfkuVQilN4g=
lab.forgefriends.org/friendlyforgeformat/gof3 v1.0.1-0.20230909181317-1e49a01bb3b7/go.mod h1:TcKaEsgVihjAjw290iDvvirCT0P+DZNpzc0ZgNgy3E4=
lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI=
lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=

View file

@ -8,8 +8,6 @@ import (
auth_model "code.gitea.io/gitea/models/auth"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/migrations"
@ -49,27 +47,8 @@ func getAuthenticationSource(ctx context.Context, authenticationSource string) (
return source, nil
}
func ToF3Logger(messenger base.Messenger) *f3_types.Logger {
if messenger == nil {
messenger = func(message string, args ...interface{}) {
log.Info("Message: "+message, args...)
}
}
return &f3_types.Logger{
Message: f3_types.LoggerFun(messenger),
Trace: log.Trace,
Debug: log.Debug,
Info: log.Info,
Warn: log.Warn,
Error: log.Error,
Critical: log.Critical,
Fatal: log.Fatal,
}
}
func (o *Options) FromFlags(ctx context.Context, c *cli.Context, prefix string) f3_types.OptionsInterface {
o.Options.FromFlags(ctx, c, prefix)
o.Options.Logger = ToF3Logger(nil)
sourceName := c.String("authentication-source")
if sourceName != "" {
source, err := getAuthenticationSource(ctx, sourceName)

View file

@ -100,7 +100,6 @@ func (o *forgejoInstance) Init(t f3_tests.TestingT) {
Type: strings.ToLower(Name),
},
Features: config_types.AllFeatures,
Logger: ToF3Logger(nil),
},
Doer: doer,
}