Skip to content

Commit

Permalink
trimming
Browse files Browse the repository at this point in the history
  • Loading branch information
cho4036 committed Jan 24, 2024
1 parent 19f7d04 commit 53b3677
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 120 deletions.
51 changes: 0 additions & 51 deletions internal/delivery/api/api.go

This file was deleted.

9 changes: 0 additions & 9 deletions internal/delivery/api/group.go

This file was deleted.

28 changes: 0 additions & 28 deletions internal/delivery/api/project.go

This file was deleted.

77 changes: 45 additions & 32 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"io"
"os"
"path"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -59,8 +58,7 @@ func (f *CustomFormatter) Format(entry *logrus.Entry) ([]byte, error) {
func Info(v ...interface{}) {
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": path.Base(file),
"line": line,
"file": file + ":" + strconv.Itoa(line),
}).Info(v...)
} else {
logger.Info(v...)
Expand All @@ -69,27 +67,39 @@ func Info(v ...interface{}) {
func Infof(format string, v ...interface{}) {
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": path.Base(file),
"line": line,
"file": file + ":" + strconv.Itoa(line),
}).Infof(format, v...)
} else {
logger.Infof(format, v...)
}
}
func InfoWithContext(ctx context.Context, v ...interface{}) {
reqID := ctx.Value(internal.ContextKeyRequestID)
logger.WithField(string(internal.ContextKeyRequestID), reqID).Info(v...)
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": file + ":" + strconv.Itoa(line),
string(internal.ContextKeyRequestID): reqID,
}).Info(v...)
} else {
logger.WithField(string(internal.ContextKeyRequestID), reqID).Info(v...)
}
}
func InfofWithContext(ctx context.Context, format string, v ...interface{}) {
reqID := ctx.Value(internal.ContextKeyRequestID)
logger.WithField(string(internal.ContextKeyRequestID), reqID).Infof(format, v...)
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": file + ":" + strconv.Itoa(line),
string(internal.ContextKeyRequestID): reqID,
}).Infof(format, v...)
} else {
logger.WithField(string(internal.ContextKeyRequestID), reqID).Infof(format, v...)
}
}

func Warn(v ...interface{}) {
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": file,
"line": line,
"file": file + ":" + strconv.Itoa(line),
}).Warn(v...)
} else {
logger.Warn(v...)
Expand All @@ -98,8 +108,7 @@ func Warn(v ...interface{}) {
func Warnf(format string, v ...interface{}) {
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": file,
"line": line,
"file": file + ":" + strconv.Itoa(line),
}).Warnf(format, v...)
} else {
logger.Warnf(format, v...)
Expand All @@ -110,7 +119,6 @@ func WarnWithContext(ctx context.Context, v ...interface{}) {
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": file + ":" + strconv.Itoa(line),
"line": line,
string(internal.ContextKeyRequestID): reqID,
}).Warn(v...)
} else {
Expand All @@ -121,8 +129,7 @@ func WarnfWithContext(ctx context.Context, format string, v ...interface{}) {
reqID := ctx.Value(internal.ContextKeyRequestID)
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": file,
"line": line,
"file": file + ":" + strconv.Itoa(line),
string(internal.ContextKeyRequestID): reqID,
}).Warnf(format, v...)
} else {
Expand All @@ -133,8 +140,7 @@ func WarnfWithContext(ctx context.Context, format string, v ...interface{}) {
func Debug(v ...interface{}) {
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": file,
"line": line,
"file": file + ":" + strconv.Itoa(line),
}).Debug(v...)
} else {
logger.Debug(v...)
Expand All @@ -143,27 +149,39 @@ func Debug(v ...interface{}) {
func Debugf(format string, v ...interface{}) {
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": file,
"line": line,
"file": file + ":" + strconv.Itoa(line),
}).Debugf(format, v...)
} else {
logger.Debugf(format, v...)
}
}
func DebugWithContext(ctx context.Context, v ...interface{}) {
reqID := ctx.Value(internal.ContextKeyRequestID)
logger.WithField(string(internal.ContextKeyRequestID), reqID).Debug(v...)
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": file + ":" + strconv.Itoa(line),
string(internal.ContextKeyRequestID): reqID,
}).Debug(v...)
} else {
logger.WithField(string(internal.ContextKeyRequestID), reqID).Debug(v...)
}
}
func DebugfWithContext(ctx context.Context, format string, v ...interface{}) {
reqID := ctx.Value(internal.ContextKeyRequestID)
logger.WithField(string(internal.ContextKeyRequestID), reqID).Debugf(format, v...)
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": file + ":" + strconv.Itoa(line),
string(internal.ContextKeyRequestID): reqID,
}).Debugf(format, v...)
} else {
logger.WithField(string(internal.ContextKeyRequestID), reqID).Debugf(format, v...)
}
}

func Error(v ...interface{}) {
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": file,
"line": line,
"file": file + ":" + strconv.Itoa(line),
}).Error(v...)
} else {
logger.Error(v...)
Expand All @@ -172,8 +190,7 @@ func Error(v ...interface{}) {
func Errorf(format string, v ...interface{}) {
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": file,
"line": line,
"file": file + ":" + strconv.Itoa(line),
}).Errorf(format, v...)
} else {
logger.Errorf(format, v...)
Expand All @@ -183,8 +200,7 @@ func ErrorWithContext(ctx context.Context, v ...interface{}) {
reqID := ctx.Value(internal.ContextKeyRequestID)
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": file,
"line": line,
"file": file + ":" + strconv.Itoa(line),
string(internal.ContextKeyRequestID): reqID,
}).Error(v...)
} else {
Expand All @@ -195,8 +211,7 @@ func ErrorfWithContext(ctx context.Context, format string, v ...interface{}) {
reqID := ctx.Value(internal.ContextKeyRequestID)
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": file,
"line": line,
"file": file + ":" + strconv.Itoa(line),
string(internal.ContextKeyRequestID): reqID,
}).Errorf(format, v...)
} else {
Expand All @@ -207,8 +222,7 @@ func ErrorfWithContext(ctx context.Context, format string, v ...interface{}) {
func Fatal(v ...interface{}) {
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": file,
"line": line,
"file": file + ":" + strconv.Itoa(line),
}).Fatal(v...)
} else {
logger.Fatal(v...)
Expand All @@ -217,8 +231,7 @@ func Fatal(v ...interface{}) {
func Fatalf(format string, v ...interface{}) {
if _, file, line, ok := runtime.Caller(1); ok {
logger.WithFields(logrus.Fields{
"file": file,
"line": line,
"file": file + ":" + strconv.Itoa(line),
}).Fatalf(format, v...)
} else {
logger.Fatalf(format, v...)
Expand Down

0 comments on commit 53b3677

Please sign in to comment.