// Package log is the logging library used by IPFS & libp2p // (https://github.com/ipfs/go-ipfs).
package log import ( ) // StandardLogger provides API compatibility with standard printf loggers // eg. go-logging type StandardLogger interface { Debug(args ...interface{}) Debugf(format string, args ...interface{}) Error(args ...interface{}) Errorf(format string, args ...interface{}) Fatal(args ...interface{}) Fatalf(format string, args ...interface{}) Info(args ...interface{}) Infof(format string, args ...interface{}) Panic(args ...interface{}) Panicf(format string, args ...interface{}) Warn(args ...interface{}) Warnf(format string, args ...interface{}) } // EventLogger extends the StandardLogger interface to allow for log items // containing structured metadata type EventLogger interface { StandardLogger } // Logger retrieves an event logger by name func ( string) *ZapEventLogger { if len() == 0 { := getLogger("setup-logger") .Error("Missing name parameter") = "undefined" } := getLogger() := .Desugar().WithOptions(zap.AddCallerSkip(1)).Sugar() return &ZapEventLogger{ system: , SugaredLogger: *, skipLogger: *, } } // ZapEventLogger implements the EventLogger and wraps a go-logging Logger type ZapEventLogger struct { zap.SugaredLogger // used to fix the caller location when calling Warning and Warningf. skipLogger zap.SugaredLogger system string } // Warning is for compatibility // Deprecated: use Warn(args ...interface{}) instead func ( *ZapEventLogger) ( ...interface{}) { .skipLogger.Warn(...) } // Warningf is for compatibility // Deprecated: use Warnf(format string, args ...interface{}) instead func ( *ZapEventLogger) ( string, ...interface{}) { .skipLogger.Warnf(, ...) } // FormatRFC3339 returns the given time in UTC with RFC3999Nano format. func ( time.Time) string { return .UTC().Format(time.RFC3339Nano) } func ( *ZapEventLogger, LogLevel) *ZapEventLogger { := * .SugaredLogger = *.SugaredLogger.Desugar(). WithOptions(zap.AddStacktrace(zapcore.Level())).Sugar() .skipLogger = *.SugaredLogger.Desugar().WithOptions(zap.AddCallerSkip(1)).Sugar() return & } // WithSkip returns a new logger that skips the specified number of stack frames when reporting the // line/file. func ( *ZapEventLogger, int) *ZapEventLogger { := * .SugaredLogger = *.SugaredLogger.Desugar(). WithOptions(zap.AddCallerSkip()).Sugar() .skipLogger = *.SugaredLogger.Desugar().WithOptions(zap.AddCallerSkip(1)).Sugar() return & }