Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2023-09-21 13:15:10 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2023-09-21 14:27:36 +0300
commite52fdb6a6f09a1cfe7192272a7aabff0d7c84c4b (patch)
tree2e0598aacf334f3eb0afe3ce124590b715eb2766 /internal
parent2fd12987428f5f7b69d31253b86c1749e4a5935c (diff)
log: Simplify Debug et al to accept single argument only
The functions `Debug()`, `Info()` and related accept multiple arguments. The first hunch would be that the logger would format those arguments via a call to `fmt.Sprintf()`, and that's seemingly also the assumption that many of our callsites had. But in fact, the logrus logger will call `fmt.Sprint()`, which joins the arguments by spaces when neither of the arguments is a string. While not being obvious, the current definition also conflicts with the `slog` package. While the respective functions there also accept a variable number of arguments, they will instead be interpreted as key value pairs of structured data. Let's simplify our calling conventions such that the functions only accept a single message parameter and adjust callsites that misused these functions accordingly. This fixes a source of misformatted log messages and prepares us for the conversion to the `slog` package.
Diffstat (limited to 'internal')
-rw-r--r--internal/cache/walker.go2
-rw-r--r--internal/git/localrepo/refs.go2
-rw-r--r--internal/gitaly/repoutil/lock.go2
-rw-r--r--internal/gitaly/service/repository/rename.go4
-rw-r--r--internal/grpc/backchannel/backchannel.go2
-rw-r--r--internal/grpc/middleware/cache/cache.go2
-rw-r--r--internal/log/logger.go28
7 files changed, 31 insertions, 11 deletions
diff --git a/internal/cache/walker.go b/internal/cache/walker.go
index aed509046..17d668f71 100644
--- a/internal/cache/walker.go
+++ b/internal/cache/walker.go
@@ -117,7 +117,7 @@ func (c *DiskCache) walkLoop(walkPath string) {
}
if err := c.cleanWalk(walkPath); err != nil {
- logger.Error(err)
+ logger.WithError(err).Error("disk cache cleanup failed")
}
select {
diff --git a/internal/git/localrepo/refs.go b/internal/git/localrepo/refs.go
index fe38e93c3..984f916b7 100644
--- a/internal/git/localrepo/refs.go
+++ b/internal/git/localrepo/refs.go
@@ -164,7 +164,7 @@ func (repo *Repo) setDefaultBranchWithTransaction(ctx context.Context, txManager
}
defer func() {
if err := lockingFileWriter.Close(); err != nil {
- log.FromContext(ctx).WithError(err).Error("closing locked HEAD: %w", err)
+ log.FromContext(ctx).WithError(err).Error("closing locked HEAD failed")
}
}()
diff --git a/internal/gitaly/repoutil/lock.go b/internal/gitaly/repoutil/lock.go
index 3bbf30716..f0c13d29a 100644
--- a/internal/gitaly/repoutil/lock.go
+++ b/internal/gitaly/repoutil/lock.go
@@ -41,7 +41,7 @@ func Lock(ctx context.Context, locator storage.Locator, repository storage.Repos
unlock := func() {
if err := locker.Close(); err != nil {
- log.FromContext(ctx).Error("closing repository locker: %w", err)
+ log.FromContext(ctx).WithError(err).Error("closing repository locker failed")
}
}
diff --git a/internal/gitaly/service/repository/rename.go b/internal/gitaly/service/repository/rename.go
index 296d59e5c..29c35085e 100644
--- a/internal/gitaly/service/repository/rename.go
+++ b/internal/gitaly/service/repository/rename.go
@@ -62,7 +62,7 @@ func (s *server) renameRepository(ctx context.Context, sourceRepo, targetRepo *g
}
defer func() {
if err := sourceLocker.Close(); err != nil {
- log.FromContext(ctx).Error("closing source repo locker: %w", err)
+ log.FromContext(ctx).WithError(err).Error("closing source repo locker failed")
}
}()
@@ -72,7 +72,7 @@ func (s *server) renameRepository(ctx context.Context, sourceRepo, targetRepo *g
}
defer func() {
if err := targetLocker.Close(); err != nil {
- log.FromContext(ctx).Error("closing target repo locker: %w", err)
+ log.FromContext(ctx).WithError(err).Error("closing target repo locker failed")
}
}()
diff --git a/internal/grpc/backchannel/backchannel.go b/internal/grpc/backchannel/backchannel.go
index bcbc09c0e..d992ecb84 100644
--- a/internal/grpc/backchannel/backchannel.go
+++ b/internal/grpc/backchannel/backchannel.go
@@ -42,7 +42,7 @@ type yamuxLogWrapper struct {
}
func (l yamuxLogWrapper) Print(args ...any) {
- l.logger.Info(args...)
+ l.logger.Info(fmt.Sprint(args...))
}
func (l yamuxLogWrapper) Printf(format string, args ...any) {
diff --git a/internal/grpc/middleware/cache/cache.go b/internal/grpc/middleware/cache/cache.go
index b9d5474ba..39dab9596 100644
--- a/internal/grpc/middleware/cache/cache.go
+++ b/internal/grpc/middleware/cache/cache.go
@@ -16,7 +16,7 @@ import (
func methodErrLogger(logger log.Logger, method string) func(error) {
return func(err error) {
countMethodErr(method)
- logger.WithField("full_method_name", method).Error(err)
+ logger.WithField("full_method_name", method).Error(err.Error())
}
}
diff --git a/internal/log/logger.go b/internal/log/logger.go
index 9f07ec205..ebed6293e 100644
--- a/internal/log/logger.go
+++ b/internal/log/logger.go
@@ -23,10 +23,10 @@ type Logger interface {
Warnf(format string, args ...any)
Errorf(format string, args ...any)
- Debug(args ...any)
- Info(args ...any)
- Warn(args ...any)
- Error(args ...any)
+ Debug(msg string)
+ Info(msg string)
+ Warn(msg string)
+ Error(msg string)
StreamServerInterceptor(...grpcmwlogrus.Option) grpc.StreamServerInterceptor
UnaryServerInterceptor(...grpcmwlogrus.Option) grpc.UnaryServerInterceptor
@@ -57,6 +57,26 @@ func (l LogrusLogger) WithError(err error) Logger {
return LogrusLogger{Entry: l.Entry.WithError(err)}
}
+// Debug writes a log message at debug level.
+func (l LogrusLogger) Debug(msg string) {
+ l.Entry.Debug(msg)
+}
+
+// Info writes a log message at info level.
+func (l LogrusLogger) Info(msg string) {
+ l.Entry.Info(msg)
+}
+
+// Warn writes a log message at warn level.
+func (l LogrusLogger) Warn(msg string) {
+ l.Entry.Warn(msg)
+}
+
+// Error writes a log message at error level.
+func (l LogrusLogger) Error(msg string) {
+ l.Entry.Error(msg)
+}
+
// ToContext injects the logger into the given context so that it can be retrieved via `FromContext()`.
func (l LogrusLogger) ToContext(ctx context.Context) context.Context {
return ctxlogrus.ToContext(ctx, l.Entry)