This commit is contained in:
Anurag Bandyopadhyay 2024-11-14 00:28:47 -08:00 committed by GitHub
commit 4c25c04307
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 49 additions and 0 deletions

View File

@ -7,8 +7,15 @@ import (
"os"
)
// msg is the main log message.
// keysAndValues are the extra context you want to add to your log entries.
// To provide additional information for the context in which the log entry was created.
// These are passed as variadic arguments so you can pass any number of them.
type Logging interface {
Printf(ctx context.Context, format string, v ...interface{})
Info(ctx context.Context, msg string, keysAndValues ...interface{})
Error(ctx context.Context, msg string, keysAndValues ...interface{})
}
type logger struct {
@ -18,6 +25,13 @@ type logger struct {
func (l *logger) Printf(ctx context.Context, format string, v ...interface{}) {
_ = l.log.Output(2, fmt.Sprintf(format, v...))
}
func (l *logger) Info(ctx context.Context, msg string, keysAndValues ...interface{}) {
_ = l.log.Output(2, fmt.Sprintf(msg, keysAndValues...))
}
func (l *logger) Error(ctx context.Context, msg string, keysAndValues ...interface{}) {
_ = l.log.Output(2, fmt.Sprintf("ERROR: "+msg, keysAndValues...))
}
// Logger calls Output to print to the stderr.
// Arguments are handled in the manner of fmt.Print.

35
zaplogger.go Normal file
View File

@ -0,0 +1,35 @@
package redis
// Example : You can use ZapLogger in the following way :
// import (
// "context"
// "fmt"
// "go.uber.org/zap"
// )
//
// type ZapLogger struct {
// logger *zap.Logger
// }
//
// func NewZapLogger() (*ZapLogger, error) {
// logger, err := zap.NewProduction()
// if err != nil {
// return nil, err
// }
//
// return &ZapLogger{
// logger: logger,
// }, nil
// }
//
// func (z *ZapLogger) Printf(ctx context.Context, format string, v ...interface{}) {
// z.logger.Info(fmt.Sprintf(format, v...))
// }
//
// func (z *ZapLogger) Info(ctx context.Context, msg string, keysAndValues ...interface{}) {
// z.logger.Info(fmt.Sprintf(msg, keysAndValues...))
// }
//
// func (z *ZapLogger) Error(ctx context.Context, msg string, keysAndValues ...interface{}) {
// z.logger.Error(fmt.Sprintf(msg, keysAndValues...))
// }