Skip to content

Commit

Permalink
remove unused part of logger
Browse files Browse the repository at this point in the history
  • Loading branch information
dbadura committed Jan 20, 2025
1 parent ba8d67b commit 6713133
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 210 deletions.
11 changes: 0 additions & 11 deletions components/serverless/internal/logging/logger/logger.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package logger

import (
"context"
"os"

"github.com/pkg/errors"

"github.com/go-logr/zapr"
"github.com/kyma-project/serverless/components/serverless/internal/logging/tracing"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -56,15 +54,6 @@ func new(format Format, levelEnabler zapcore.LevelEnabler, additionalCores ...za
return &Logger{zap.New(zapcore.NewTee(cores...), zap.AddCaller()).Sugar()}, nil
}

func (l *Logger) WithTracing(ctx context.Context) *zap.SugaredLogger {
newLogger := *l
for key, val := range tracing.GetMetadata(ctx) {
newLogger.zapLogger = newLogger.zapLogger.With(key, val)
}

return newLogger.WithContext()
}

func (l *Logger) WithContext() *zap.SugaredLogger {
return l.zapLogger.With(zap.Namespace("context"))
}
Expand Down
41 changes: 2 additions & 39 deletions components/serverless/internal/logging/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package logger_test

import (
"bytes"
"context"
"encoding/json"
"io"
"os"
Expand All @@ -21,8 +20,6 @@ import (
type logEntry struct {
Context map[string]string `json:"context"`
Msg string `json:"message"`
TraceID string `json:"traceid"`
SpanID string `json:"spanid"`
Timestamp string `json:"timestamp"`
Level string `json:"level"`
Caller string `json:"caller"`
Expand Down Expand Up @@ -75,9 +72,8 @@ func TestLogger(t *testing.T) {
log, err := logger.New(logger.JSON, logger.DEBUG)
require.NoError(t, err)

ctx := fixContext(map[string]string{"traceid": "trace", "spanid": "span"})
// WHEN
log.WithTracing(ctx).With("key", "value").Info("example message")
log.WithContext().With("key", "value").Info("example message")

// THEN
err = w.Close()
Expand All @@ -95,8 +91,6 @@ func TestLogger(t *testing.T) {

assert.Equal(t, "INFO", entry.Level)
assert.Equal(t, "example message", entry.Msg)
assert.Equal(t, "trace", entry.TraceID)
assert.Equal(t, "span", entry.SpanID)
assert.Contains(t, entry.Caller, "logger_test.go")

assert.NotEmpty(t, entry.Timestamp)
Expand All @@ -113,10 +107,8 @@ func TestLogger(t *testing.T) {

log, err := logger.New(logger.JSON, logger.DEBUG)
require.NoError(t, err)
ctx := fixContext(map[string]string{"traceid": "trace", "spanid": "span"})

// WHEN
log.WithTracing(ctx).With("key", "first").Info("first message")
log.WithContext().With("key", "first").Info("first message")
log.WithContext().With("key", "second").Error("second message")

// THEN
Expand All @@ -141,8 +133,6 @@ func TestLogger(t *testing.T) {
assert.Equal(t, "INFO", infoEntry.Level)
assert.Equal(t, "first message", infoEntry.Msg)
assert.EqualValues(t, map[string]string{"key": "first"}, infoEntry.Context, 0.0)
assert.Equal(t, "span", infoEntry.SpanID)
assert.Equal(t, "trace", infoEntry.TraceID)

assert.NotEmpty(t, infoEntry.Timestamp)
_, err = time.Parse(time.RFC3339, infoEntry.Timestamp)
Expand All @@ -157,8 +147,6 @@ func TestLogger(t *testing.T) {
assert.Equal(t, "ERROR", errorEntry.Level)
assert.Equal(t, "second message", errorEntry.Msg)
assert.EqualValues(t, map[string]string{"key": "second"}, errorEntry.Context, 0.0)
assert.Empty(t, errorEntry.SpanID)
assert.Empty(t, errorEntry.TraceID)

assert.NotEmpty(t, errorEntry.Timestamp)
_, err = time.Parse(time.RFC3339, errorEntry.Timestamp)
Expand All @@ -176,32 +164,7 @@ func TestLogger(t *testing.T) {
//THEN
assert.NotSame(t, firstLogger, secondLogger)
})

t.Run("with tracing should create new logger", func(t *testing.T) {
//GIVEN
log, err := logger.New(logger.TEXT, logger.INFO)
require.NoError(t, err)
ctx := fixContext(map[string]string{"traceid": "trace", "spanid": "span"})

//WHEN
firstLogger := log.WithTracing(ctx)
secondLogger := log.WithTracing(ctx)

//THEN
assert.NotSame(t, firstLogger, secondLogger)
})
}

func fixContext(values map[string]string) context.Context {
ctx := context.TODO()
for k, v := range values {
//nolint:staticcheck
ctx = context.WithValue(ctx, k, v)
}

return ctx
}

func rollbackStderr(oldStdErr *os.File) {
os.Stderr = oldStdErr
}
17 changes: 0 additions & 17 deletions components/serverless/internal/logging/tracing/helper.go

This file was deleted.

46 changes: 0 additions & 46 deletions components/serverless/internal/logging/tracing/helper_test.go

This file was deleted.

42 changes: 0 additions & 42 deletions components/serverless/internal/logging/tracing/middleware.go

This file was deleted.

55 changes: 0 additions & 55 deletions components/serverless/internal/logging/tracing/middleware_test.go

This file was deleted.

0 comments on commit 6713133

Please sign in to comment.