Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: fine-tune log format (#9972)
Danny Xu6363f7052d75
diff --git a/backend/api/v1/actuator_service.go b/backend/api/v1/actuator_service.goindex 268afb0506..9a85c302a8 100644--- a/backend/api/v1/actuator_service.go+++ b/backend/api/v1/actuator_service.go@@ -43,11 +43,11 @@ func (s *ActuatorService) GetActuatorInfo(ctx context.Context, _ *v1pb.GetActuatfunc (s *ActuatorService) UpdateActuatorInfo(ctx context.Context, request *v1pb.UpdateActuatorInfoRequest) (*v1pb.ActuatorInfo, error) {for _, path := range request.UpdateMask.Paths {if path == "debug" {- lvl := slog.LevelInfo+ level := slog.LevelInfoif request.Actuator.Debug {- lvl = slog.LevelDebug+ level = slog.LevelDebug}- log.GLogLevel.Set(lvl)+ log.LogLevel.Set(level)}}diff --git a/backend/bin/server/cmd/root.go b/backend/bin/server/cmd/root.goindex 77a29086fc..8d535bda9e 100644--- a/backend/bin/server/cmd/root.go+++ b/backend/bin/server/cmd/root.go@@ -194,7 +194,12 @@ func checkPort(port int) error {func start() {if flags.debug {- log.GLogLevel.Set(slog.LevelDebug)+ log.LogLevel.Set(slog.LevelDebug)+ }+ if flags.saas {+ slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{AddSource: true, Level: log.LogLevel, ReplaceAttr: log.Replace})))+ } else {+ slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{AddSource: true, Level: log.LogLevel, ReplaceAttr: log.Replace})))}var err errordiff --git a/backend/bin/sql-service/cmd/root.go b/backend/bin/sql-service/cmd/root.goindex fdd1c7068e..44bc570e8e 100644--- a/backend/bin/sql-service/cmd/root.go+++ b/backend/bin/sql-service/cmd/root.go@@ -104,8 +104,9 @@ func init() {func start() {if flags.debug {- log.GLogLevel.Set(slog.LevelDebug)+ log.LogLevel.Set(slog.LevelDebug)}+ slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{AddSource: true, Level: log.LogLevel, ReplaceAttr: log.Replace})))// check flagsif !common.HasPrefixes(flags.host, "http://", "https://") {diff --git a/backend/common/log/slog_utils.go b/backend/common/log/slog_utils.goindex 18bb7ee9df..1ddf2e50f0 100644--- a/backend/common/log/slog_utils.go+++ b/backend/common/log/slog_utils.go@@ -2,39 +2,37 @@ package logimport ("log/slog"- "os""strings""github.com/bytebase/bytebase/backend/common/stacktrace")-var GLogLevel *slog.LevelVar--// Initializes the slog configuration.-func init() {- GLogLevel = new(slog.LevelVar)-- // https://sourcegraph.com/github.com/uber-go/zap/-/blob/zapcore/entry.go?L117- replace := func(groups []string, a slog.Attr) slog.Attr {- if a.Key == slog.SourceKey {- if source, ok := a.Value.Any().(*slog.Source); ok {- idx := strings.LastIndexByte(source.File, '/')- if idx == -1 {- return a- }- // Find the penultimate separator.- idx = strings.LastIndexByte(source.File[:idx], '/')- if idx == -1 {- return a- }- source.File = source.File[idx+1:]+// LogLevel is the default log severity level.+var LogLevel = new(slog.LevelVar)++// https://sourcegraph.com/github.com/uber-go/zap/-/blob/zapcore/entry.go?L117+// Replace is the default replace attribute.+var Replace = func(groups []string, a slog.Attr) slog.Attr {+ if a.Key == slog.SourceKey {+ if source, ok := a.Value.Any().(*slog.Source); ok {+ idx := strings.LastIndexByte(source.File, '/')+ if idx == -1 {+ return a+ }+ // Find the penultimate separator.+ idx = strings.LastIndexByte(source.File[:idx], '/')+ if idx == -1 {+ return a}+ source.File = source.File[idx+1:]}- return a}+ return a+}- textHandler := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{AddSource: true, Level: GLogLevel, ReplaceAttr: replace})- slog.SetDefault(slog.New(textHandler))+// Initializes the slog configuration.+func init() {+ LogLevel.Set(slog.LevelInfo)}func BBError(err error) slog.Attr {