Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type Entry
- func (entry *Entry) Debug(format string)
- func (entry *Entry) Debugw(format string, args map[string]interface{})
- func (entry *Entry) EnableDebugMode() *Entry
- func (entry *Entry) Error(format string)
- func (entry *Entry) Errorw(format string, args map[string]interface{})
- func (entry *Entry) Fatal(format string)
- func (entry *Entry) Fatalw(format string, args map[string]interface{})
- func (entry *Entry) Info(format string)
- func (entry *Entry) Infow(format string, args map[string]interface{})
- func (entry *Entry) Panic(format string)
- func (entry *Entry) Panicw(format string, args map[string]interface{})
- func (entry *Entry) Warn(format string)
- func (entry *Entry) Warnw(format string, args map[string]interface{})
- func (entry *Entry) WithContext(ctx context.Context, ctxFields []string) *Entry
- func (entry *Entry) WithError(err error) *Entry
- func (entry *Entry) WithField(key string, value interface{}) *Entry
- func (entry *Entry) WithFields(fields map[string]interface{}) *Entry
- type MutexWrap
- type Option
- type ZapLogger
- func (l *ZapLogger) Debug(format string)
- func (l *ZapLogger) Debugw(format string, args map[string]interface{})
- func (l *ZapLogger) Fatal(format string)
- func (l *ZapLogger) Fatalw(format string, args map[string]interface{})
- func (l *ZapLogger) Info(format string)
- func (l *ZapLogger) Infow(format string, args map[string]interface{})
- func (l *ZapLogger) Panic(format string)
- func (l *ZapLogger) Panicw(format string, args map[string]interface{})
- func (l *ZapLogger) Warn(format string)
- func (l *ZapLogger) Warnw(format string, args map[string]interface{})
- func (logger *ZapLogger) WithContext(ctx context.Context, ctxFields []string) *Entry
- func (logger *ZapLogger) WithError(err error) *Entry
- func (logger *ZapLogger) WithField(key string, value interface{}) *Entry
- func (logger *ZapLogger) WithFields(fields map[string]interface{}) *Entry
- func (logger *ZapLogger) WithOptions(opts ...Option) *ZapLogger
Constants ¶
const ( //Debug has verbose message Debug = "debug" //Info is default log level Info = "info" //Warn is for logging messages about possible issues Warn = "warn" //Error is for logging errors Error = "error" //Fatal is for logging fatal messages. The sytem shutsdown after logging the message. Fatal = "fatal" //TODO: Should we add panic and DPanic like what zap uses internally? //DefaultContextString is for adding extra context DefaultContextString = "extra" //DefaultFieldConstant for adding existing context DefaultFieldConstant = "context" //Unique Identifier for context key LoggerCtxKey contextKey = iota // DefaultStacktraceKey ... default key for stacktrace if none provided in config DefaultStacktraceKey = "stacktrace" // DefaultStacktraceLevel ... default log level: error for which stacktrace will be added to logs DefaultStacktraceLevel = "error" )
Fields Type to pass when we want to call WithFields for structured logging var DefaultFields = make(map[string]interface{}, 0) var mutex = & sync.RWMutex{}
Variables ¶
var ( // Defines the key when adding errors using WithError. ErrorKey = "error" // DefaultCallerSkip defines the default caller skip setting DefaultCallerSkip int = 2 )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
//LogLevel ... the default log level
LogLevel string
//ContextString ... in case of logging extra context information to logs, this should be enabled
ContextString string
// StackTraceKey... key for stacktrace data in logs
StackTraceKey string
// StackTraceLevel ... log level for & above which stacktrace will be logged
StackTraceLevel string
// CallerSkip
CallerSkip *int
}
Config ... largely kept for extensions and other hooks
type Entry ¶
type Entry struct {
Logger *ZapLogger
// Contains all the fields set by the user.
Data map[string]interface{}
DebugMode bool
// contains filtered or unexported fields
}
An entry is the final or intermediate log entry. It contains all the fields passed with WithField{,s}. It's finally logged when Trace, Debug, Info, Warn, Error, Fatal or Panic is called on it. These objects can be reused and passed around as much as you wish to avoid field duplication.
func Ctx ¶
Ctx gets logger instance from context if available else creates a new one basic on the existing config and returns a logger object or error
func (*Entry) Debugw ¶
Debug logs a message with some additional context. `args` mentioned here as a key value map of extra context logging specific to this log message
func (*Entry) EnableDebugMode ¶
func (*Entry) Errorw ¶
Warn logs a message with some additional context. `args` mentioned here as a key value map of extra context logging specific to this log message
func (*Entry) Fatalw ¶
Fatal logs a message with some additional context. `args` mentioned here as a key value map of extra context logging specific to this log message
func (*Entry) Infow ¶
Info logs a message with some additional context. `args` mentioned here as a key value map of extra context logging specific to this log message
func (*Entry) Panicw ¶
Panic logs a message with some additional context. `args` mentioned here as a key value map of extra context logging specific to this log message
func (*Entry) Warnw ¶
Warn logs a message with some additional context. `args` mentioned here as a key value map of extra context logging specific to this log message
func (*Entry) WithContext ¶
func (*Entry) WithError ¶
Add an error as single field (using the key defined in ErrorKey) to the Entry.
func (*Entry) WithFields ¶
Add a map of fields to the Entry.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
An Option configures a ZapLogger.
func AddCallerSkip ¶
AddCallerSkip increases the number of callers skipped by caller annotation It adds skip level to the current caller skip level.
type ZapLogger ¶
type ZapLogger struct {
// contains filtered or unexported fields
}
ZapLogger ... struct for handling the logger and associated methods. Kept public to ensure it can be accessible from tests
func NewModuleLogger ¶
NewModuleLogger This is used when you want different loggers at different log levels for different modules
func (*ZapLogger) WithContext ¶
WithContext returns an instance of the logger with the supplied context populated
func (*ZapLogger) WithError ¶
WithError adds an error as single field (using the key defined in ErrorKey) to the Entry.
func (*ZapLogger) WithField ¶
Adds a field to the log entry, note that it doesn't log until you call Debug, Print, Info, Warn, Error, Fatal or Panic. It only creates a log entry. If you want multiple fields, use `WithFields`.
func (*ZapLogger) WithFields ¶
WithFields takes default extra context that needs to be attached to every other log message and adds it as part of a default map from where it is added through every through other log method like Debug, Info etc
func (*ZapLogger) WithOptions ¶
WithOptions applies the given Options and returns a new instance of Logger