Skip to content

Commit

Permalink
fix: warnings from golangci-lint: S1009 should omit nil check; non-co…
Browse files Browse the repository at this point in the history
…nstant format string in call to fmt.Errorf

Signed-off-by: Cheng Fang <[email protected]>
  • Loading branch information
chengfang committed Aug 30, 2024
1 parent 8c9e269 commit 3f75025
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ext/git/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (m *nativeGitClient) Commit(pathSpec string, opts *CommitOptions) error {

out, err := m.runCmd(args...)
if err != nil {
log.Errorf(out)
log.Errorf("%s %v", out, err)
return err
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ func (logctx *LogContext) AddField(key string, value interface{}) *LogContext {
return logctx
}

// Logger retrieves the native logger interface. Use with care.
// Log retrieves the native logger interface. Use with care.
func Log() *logrus.Logger {
return logger
}

// Tracef logs a debug message for logctx to stdout
func (logctx *LogContext) Tracef(format string, args ...interface{}) {
logger.SetOutput(logctx.normalOut)
if logctx.fields != nil && len(logctx.fields) > 0 {
if len(logctx.fields) > 0 {
logger.WithFields(logctx.fields).Tracef(format, args...)
} else {
logger.Tracef(format, args...)
Expand All @@ -88,7 +88,7 @@ func (logctx *LogContext) Tracef(format string, args ...interface{}) {
// Debugf logs a debug message for logctx to stdout
func (logctx *LogContext) Debugf(format string, args ...interface{}) {
logger.SetOutput(logctx.normalOut)
if logctx.fields != nil && len(logctx.fields) > 0 {
if len(logctx.fields) > 0 {
logger.WithFields(logctx.fields).Debugf(format, args...)
} else {
logger.Debugf(format, args...)
Expand All @@ -98,7 +98,7 @@ func (logctx *LogContext) Debugf(format string, args ...interface{}) {
// Infof logs an informational message for logctx to stdout
func (logctx *LogContext) Infof(format string, args ...interface{}) {
logger.SetOutput(logctx.normalOut)
if logctx.fields != nil && len(logctx.fields) > 0 {
if len(logctx.fields) > 0 {
logger.WithFields(logctx.fields).Infof(format, args...)
} else {
logger.Infof(format, args...)
Expand All @@ -108,7 +108,7 @@ func (logctx *LogContext) Infof(format string, args ...interface{}) {
// Warnf logs a warning message for logctx to stdout
func (logctx *LogContext) Warnf(format string, args ...interface{}) {
logger.SetOutput(logctx.normalOut)
if logctx.fields != nil && len(logctx.fields) > 0 {
if len(logctx.fields) > 0 {
logger.WithFields(logctx.fields).Warnf(format, args...)
} else {
logger.Warnf(format, args...)
Expand All @@ -118,7 +118,7 @@ func (logctx *LogContext) Warnf(format string, args ...interface{}) {
// Errorf logs a non-fatal error message for logctx to stdout
func (logctx *LogContext) Errorf(format string, args ...interface{}) {
logger.SetOutput(logctx.errorOut)
if logctx.fields != nil && len(logctx.fields) > 0 {
if len(logctx.fields) > 0 {
logger.WithFields(logctx.fields).Errorf(format, args...)
} else {
logger.Errorf(format, args...)
Expand All @@ -128,14 +128,14 @@ func (logctx *LogContext) Errorf(format string, args ...interface{}) {
// Fatalf logs a fatal error message for logctx to stdout
func (logctx *LogContext) Fatalf(format string, args ...interface{}) {
logger.SetOutput(logctx.errorOut)
if logctx.fields != nil && len(logctx.fields) > 0 {
if len(logctx.fields) > 0 {
logger.WithFields(logctx.fields).Fatalf(format, args...)
} else {
logger.Fatalf(format, args...)
}
}

// Debugf logs a warning message without context to stdout
// Tracef logs a warning message without context to stdout
func Tracef(format string, args ...interface{}) {
logCtx := NewContext()
logCtx.Tracef(format, args...)
Expand Down

0 comments on commit 3f75025

Please sign in to comment.