Skip to content

Commit

Permalink
Merge pull request #225 from gotomicro/feature/elog-comments
Browse files Browse the repository at this point in the history
feat: [elog] mark printf and key-val paris method to deprecated
  • Loading branch information
askuy authored Nov 22, 2021
2 parents 3829e48 + 111d4af commit 0a8fc82
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
23 changes: 16 additions & 7 deletions core/elog/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ func (logger *Component) ZapSugaredLogger() *zap.SugaredLogger {
return logger.sugar
}

// StdLog ...
//func (logger *Component) StdLog() *log.Logger {
// return zap.NewStdLog(logger.desugar)
//}

// AutoLevel ...
func (logger *Component) AutoLevel(confKey string) {
econf.OnChange(func(config *econf.Configuration) {
Expand Down Expand Up @@ -174,6 +169,7 @@ func (logger *Component) Debug(msg string, fields ...Field) {
logger.desugar.Debug(msg, fields...)
}

// Deprecated: Will be removed in future versions, use *Component.Debug instead.
// Debugw ...
func (logger *Component) Debugw(msg string, keysAndValues ...interface{}) {
if logger.IsDebugMode() {
Expand All @@ -182,6 +178,7 @@ func (logger *Component) Debugw(msg string, keysAndValues ...interface{}) {
logger.sugar.Debugw(msg, keysAndValues...)
}

// Deprecated: Will be removed in future versions, use *Component.Debug instead.
// Debugf ...
func (logger *Component) Debugf(template string, args ...interface{}) {
logger.sugar.Debugf(template, args...)
Expand All @@ -195,6 +192,7 @@ func (logger *Component) Info(msg string, fields ...Field) {
logger.desugar.Info(msg, fields...)
}

// Deprecated: Will be removed in future versions, use *Component.Info instead.
// Infow ...
func (logger *Component) Infow(msg string, keysAndValues ...interface{}) {
if logger.IsDebugMode() {
Expand All @@ -203,6 +201,7 @@ func (logger *Component) Infow(msg string, keysAndValues ...interface{}) {
logger.sugar.Infow(msg, keysAndValues...)
}

// Deprecated: Will be removed in future versions, use *Component.Info instead.
// Infof ...
func (logger *Component) Infof(template string, args ...interface{}) {
logger.sugar.Infof(template, args...)
Expand All @@ -216,6 +215,7 @@ func (logger *Component) Warn(msg string, fields ...Field) {
logger.desugar.Warn(msg, fields...)
}

// Deprecated: Will be removed in future versions, use *Component.Warn instead.
// Warnw ...
func (logger *Component) Warnw(msg string, keysAndValues ...interface{}) {
if logger.IsDebugMode() {
Expand All @@ -224,6 +224,7 @@ func (logger *Component) Warnw(msg string, keysAndValues ...interface{}) {
logger.sugar.Warnw(msg, keysAndValues...)
}

// Deprecated: Will be removed in future versions, use *Component.Warn instead.
// Warnf ...
func (logger *Component) Warnf(template string, args ...interface{}) {
logger.sugar.Warnf(template, args...)
Expand All @@ -237,6 +238,7 @@ func (logger *Component) Error(msg string, fields ...Field) {
logger.desugar.Error(msg, fields...)
}

// Deprecated: Will be removed in future versions, use *Component.Error instead.
// Errorw ...
func (logger *Component) Errorw(msg string, keysAndValues ...interface{}) {
if logger.IsDebugMode() {
Expand All @@ -245,6 +247,7 @@ func (logger *Component) Errorw(msg string, keysAndValues ...interface{}) {
logger.sugar.Errorw(msg, keysAndValues...)
}

// Deprecated: Will be removed in future versions, use *Component.Error instead.
// Errorf ...
func (logger *Component) Errorf(template string, args ...interface{}) {
logger.sugar.Errorf(template, args...)
Expand All @@ -259,6 +262,7 @@ func (logger *Component) Panic(msg string, fields ...Field) {
logger.desugar.Panic(msg, fields...)
}

// Deprecated: Will be removed in future versions, use *Component.Panic instead.
// Panicw ...
func (logger *Component) Panicw(msg string, keysAndValues ...interface{}) {
if logger.IsDebugMode() {
Expand All @@ -267,6 +271,7 @@ func (logger *Component) Panicw(msg string, keysAndValues ...interface{}) {
logger.sugar.Panicw(msg, keysAndValues...)
}

// Deprecated: Will be removed in future versions, use *Component.Panic instead.
// Panicf ...
func (logger *Component) Panicf(template string, args ...interface{}) {
logger.sugar.Panicf(template, args...)
Expand All @@ -281,6 +286,7 @@ func (logger *Component) DPanic(msg string, fields ...Field) {
logger.desugar.DPanic(msg, fields...)
}

// Deprecated: Will be removed in future versions, use *Component.DPanic instead.
// DPanicw ...
func (logger *Component) DPanicw(msg string, keysAndValues ...interface{}) {
if logger.IsDebugMode() {
Expand All @@ -289,6 +295,7 @@ func (logger *Component) DPanicw(msg string, keysAndValues ...interface{}) {
logger.sugar.DPanicw(msg, keysAndValues...)
}

// Deprecated: Will be removed in future versions, use *Component.DPanic instead.
// DPanicf ...
func (logger *Component) DPanicf(template string, args ...interface{}) {
logger.sugar.DPanicf(template, args...)
Expand All @@ -298,12 +305,13 @@ func (logger *Component) DPanicf(template string, args ...interface{}) {
func (logger *Component) Fatal(msg string, fields ...Field) {
if logger.IsDebugMode() {
panicDetail(msg, fields...)
//msg = normalizeMessage(msg)
// msg = normalizeMessage(msg)
return
}
logger.desugar.Fatal(msg, fields...)
}

// Deprecated: Will be removed in future versions, use *Component.Fatal instead.
// Fatalw ...
func (logger *Component) Fatalw(msg string, keysAndValues ...interface{}) {
if logger.IsDebugMode() {
Expand All @@ -312,12 +320,13 @@ func (logger *Component) Fatalw(msg string, keysAndValues ...interface{}) {
logger.sugar.Fatalw(msg, keysAndValues...)
}

// Deprecated: Will be removed in future versions, use *Component.Fatal instead.
// Fatalf ...
func (logger *Component) Fatalf(template string, args ...interface{}) {
logger.sugar.Fatalf(template, args...)
}

// With ...
// With creates a child logger
func (logger *Component) With(fields ...Field) *Component {
desugarLogger := logger.desugar.With(fields...)
return &Component{
Expand Down
14 changes: 14 additions & 0 deletions core/elog/elog_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,71 +52,85 @@ func Fatal(msg string, fields ...Field) {
DefaultLogger.Fatal(msg, fields...)
}

// Deprecated: Will be removed in future versions, use Debug instead.
// Debugw ...
func Debugw(msg string, keysAndValues ...interface{}) {
DefaultLogger.Debugw(msg, keysAndValues...)
}

// Deprecated: Will be removed in future versions, use Info instead.
// Infow ...
func Infow(msg string, keysAndValues ...interface{}) {
DefaultLogger.Infow(msg, keysAndValues...)
}

// Deprecated: Will be removed in future versions, use Warn instead.
// Warnw ...
func Warnw(msg string, keysAndValues ...interface{}) {
DefaultLogger.Warnw(msg, keysAndValues...)
}

// Deprecated: Will be removed in future versions, use Error instead.
// Errorw ...
func Errorw(msg string, keysAndValues ...interface{}) {
DefaultLogger.Errorw(msg, keysAndValues...)
}

// Deprecated: Will be removed in future versions, use Panic instead.
// Panicw ...
func Panicw(msg string, keysAndValues ...interface{}) {
DefaultLogger.Panicw(msg, keysAndValues...)
}

// Deprecated: Will be removed in future versions, use DPanic instead.
// DPanicw ...
func DPanicw(msg string, keysAndValues ...interface{}) {
DefaultLogger.DPanicw(msg, keysAndValues...)
}

// Deprecated: Will be removed in future versions, use Fatal instead.
// Fatalw ...
func Fatalw(msg string, keysAndValues ...interface{}) {
DefaultLogger.Fatalw(msg, keysAndValues...)
}

// Deprecated: Will be removed in future versions, use Debug instead.
// Debugf ...
func Debugf(msg string, args ...interface{}) {
DefaultLogger.Debugf(msg, args...)
}

// Deprecated: Will be removed in future versions, use Info instead.
// Infof ...
func Infof(msg string, args ...interface{}) {
DefaultLogger.Infof(msg, args...)
}

// Deprecated: Will be removed in future versions, use Warn instead.
// Warnf ...
func Warnf(msg string, args ...interface{}) {
DefaultLogger.Warnf(msg, args...)
}

// Deprecated: Will be removed in future versions, use Error instead.
// Errorf ...
func Errorf(msg string, args ...interface{}) {
DefaultLogger.Errorf(msg, args...)
}

// Deprecated: Will be removed in future versions, use Panic instead.
// Panicf ...
func Panicf(msg string, args ...interface{}) {
DefaultLogger.Panicf(msg, args...)
}

// Deprecated: Will be removed in future versions, use DPanic instead.
// DPanicf ...
func DPanicf(msg string, args ...interface{}) {
DefaultLogger.DPanicf(msg, args...)
}

// Deprecated: Will be removed in future versions, use Fatal instead.
// Fatalf ...
func Fatalf(msg string, args ...interface{}) {
DefaultLogger.Fatalf(msg, args...)
Expand Down
8 changes: 5 additions & 3 deletions task/ecron/wrappedlogger.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package ecron

import "github.com/gotomicro/ego/core/elog"
import (
"github.com/gotomicro/ego/core/elog"
)

type wrappedLogger struct {
*elog.Component
}

// Info logs routine messages about cron's operation.
func (wl *wrappedLogger) Info(msg string, keysAndValues ...interface{}) {
wl.Infow("cron "+msg, keysAndValues...)
wl.Component.ZapSugaredLogger().Infow("cron "+msg, keysAndValues...)
}

// Error logs an error condition.
func (wl *wrappedLogger) Error(err error, msg string, keysAndValues ...interface{}) {
wl.Errorw("cron "+msg, append(keysAndValues, "err", err)...)
wl.Component.ZapSugaredLogger().Errorw("cron "+msg, append(keysAndValues, "err", err)...)
}

0 comments on commit 0a8fc82

Please sign in to comment.