Documentation ¶
Index ¶
- Constants
- type ErrInfoExtractor
- type Fields
- type Logger
- type ZapJSONLogger
- func (z *ZapJSONLogger) Debug(msg string)
- func (z *ZapJSONLogger) Error(msg string)
- func (z *ZapJSONLogger) Flush() error
- func (z *ZapJSONLogger) Info(msg string)
- func (z *ZapJSONLogger) Warn(msg string)
- func (z *ZapJSONLogger) WithError(err error) Logger
- func (z *ZapJSONLogger) WithField(key string, value interface{}) Logger
- func (z *ZapJSONLogger) WithFields(fields Fields) Logger
Constants ¶
const (
ErrKey = "error"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrInfoExtractor ¶
ErrInfoExtractor defines a function signature for functions that can extract information from an error.
type Logger ¶
type Logger interface { // Error Used when an error has occurred that is not recoverable, and will most likely // involve returning an error to the consumer/user. Implementations must include a stacktrace at this level. Error(msg string) // Warn Used when a potential issue may exist, but the system can continue to function. Warn(msg string) // Info Used when something of interest has occurred that is useful to have logged in a // production setting. Info(msg string) // Debug Used when providing information on specific code paths with the application that are // being executed that are not required in a production setting. Debug(msg string) // WithField returns a new instance of the Logger that has the specified field attached // in all subsequent messages. WithField(key string, value interface{}) Logger // WithError provides a wrapper around WithField to add an error field to the logger, // ensuring consistency of error message keys. WithError(err error) Logger // WithFields returns a new instance of the Logger that has the specified fields attached // in all subsequent messages. WithFields(fields Fields) Logger // Flush ensures that any pending log messages are written out. For some implementations // this function will be a no-op. Flush() error }
Logger defines the repository interface for a generic application logger, intended to result in structured logging using the WithField(s) functions to add context to the logger.
Implementations are expected to provide new instances of the Logger when returning from the WithField(s) functions to allow for the creation of child loggers that's subsequent use don't influence the parent.
type ZapJSONLogger ¶
type ZapJSONLogger struct {
// contains filtered or unexported fields
}
ZapJSONLogger is an implementation of the logging repository that uses zap's sugared logger.
func NewZapJSONLogger ¶
func NewZapJSONLogger(logLevel string, outWriter, errWriter io.Writer) (*ZapJSONLogger, error)
NewZapJSONLogger creates a zap based logger that implements to Logger repository defined in this package. The logger should be flushed before the application exits.
func (*ZapJSONLogger) Debug ¶
func (z *ZapJSONLogger) Debug(msg string)
Debug logs a debug level message
func (*ZapJSONLogger) Error ¶
func (z *ZapJSONLogger) Error(msg string)
Error logs an error level message. Logs at this level implicitly add a stacktrace field.
func (*ZapJSONLogger) Info ¶
func (z *ZapJSONLogger) Info(msg string)
Info logs an info level message.
func (*ZapJSONLogger) Warn ¶
func (z *ZapJSONLogger) Warn(msg string)
Warn logs a warning level message.
func (*ZapJSONLogger) WithError ¶
func (z *ZapJSONLogger) WithError(err error) Logger
WithError provides a wrapper around WithField to add an error field to the logger, ensuring consistency of error message keys. It will also unwrap the error, unlike a normal WithField call.
func (*ZapJSONLogger) WithField ¶
func (z *ZapJSONLogger) WithField(key string, value interface{}) Logger
WithField returns a new logger with the specified key-value pair attached for subsequent logging operations. This function returns a repositories logger interface rather than the explicit ZapJSONLogger to allow it to satisfy the Logger interface
func (*ZapJSONLogger) WithFields ¶
func (z *ZapJSONLogger) WithFields(fields Fields) Logger
WithFields returns a new logger with the specified key-value pairs attached for subsequent logging operations. This function returns a repositories logger interface rather than the explicit ZapJSONLogger to allow it to satisfy the Logger interface