Documentation
¶
Index ¶
- func Init(ctx context.Context, enableLogLevelEndpoint, developmentMode bool)
- func PanicLogger()
- func SetCorrelationIdContextKey(key string)
- func SetCorrelationIdFieldKey(key string)
- type CLogger
- type CSugaredLogger
- func (l *CSugaredLogger) Fatalln(args ...interface{})
- func (l *CSugaredLogger) Print(args ...interface{})
- func (l *CSugaredLogger) Printf(format string, args ...interface{})
- func (l *CSugaredLogger) Println(args ...interface{})
- func (l *CSugaredLogger) With(args ...interface{}) *CSugaredLogger
- func (l *CSugaredLogger) WithContextCorrelationId(ctx context.Context) *CSugaredLogger
- func (l *CSugaredLogger) WithCorrelationId(correlationId interface{}) *CSugaredLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
Init bootstraps the logger. You must call this method just once at the beginning of your application. The default log level is Info.
Call Logger() or SugaredLogger() to retrieve an instance of the desired type of logger. Use WithCorrelationId() or WithContextCorrelationId() to add a correlation ID to your logs.
If enableLogLevelEndpoint is true, then an HTTP endpoint on port 53835 at /logger is exposed which can be used to change the log level dynamically. See the Zap documentation for more information.
If developmentMode is true, then the logLevel is set to Debug and caller fields are more explicit. Do not enable this in production.
func PanicLogger ¶
func PanicLogger()
PanicLogger will pass the error which caused the go routine to panic and the stack trace onto the current SugaredLogger as a Fatal message and add the field "op" with value of "panic_logger". Use it to log panics as structured logs. Remember that you must defer this call at the beginning of each goroutine!
Example
defer logger.PanicLogger()
func SetCorrelationIdContextKey ¶
func SetCorrelationIdContextKey(key string)
SetCorrelationIdContextKey sets the correlation ID context key. By default, it is "correlation_id"
func SetCorrelationIdFieldKey ¶
func SetCorrelationIdFieldKey(key string)
SetCorrelationIdFieldKey sets the correlation ID field key in JSON responses. By default, it is "correlation_id"
Types ¶
type CLogger ¶
CLogger is a superset of zap.Logger
func Logger ¶
func Logger() *CLogger
Logger returns an instance of the sugar-free logger. You must have initialized the logger prior to this call.
func (*CLogger) WithContextCorrelationId ¶
WithContextCorrelationId returns an instance of the same logger with the correlation ID taken from the context added to it.
func (*CLogger) WithCorrelationId ¶
WithCorrelationId returns an instance of the same logger with the correlation ID field added to it.
type CSugaredLogger ¶
type CSugaredLogger struct {
zap.SugaredLogger
}
CSugaredLogger is a superset of zap.SugaredLogger
func SugaredLogger ¶
func SugaredLogger() *CSugaredLogger
SugaredLogger returns an instance of the sugared logger. You must have initialized the logger prior to this call.
func (*CSugaredLogger) Fatalln ¶
func (l *CSugaredLogger) Fatalln(args ...interface{})
func (*CSugaredLogger) Print ¶
func (l *CSugaredLogger) Print(args ...interface{})
func (*CSugaredLogger) Printf ¶
func (l *CSugaredLogger) Printf(format string, args ...interface{})
func (*CSugaredLogger) Println ¶
func (l *CSugaredLogger) Println(args ...interface{})
func (*CSugaredLogger) With ¶
func (l *CSugaredLogger) With(args ...interface{}) *CSugaredLogger
func (*CSugaredLogger) WithContextCorrelationId ¶
func (l *CSugaredLogger) WithContextCorrelationId(ctx context.Context) *CSugaredLogger
WithContextCorrelationId returns an instance of the same logger with the correlation ID taken from the context added to it.
func (*CSugaredLogger) WithCorrelationId ¶
func (l *CSugaredLogger) WithCorrelationId(correlationId interface{}) *CSugaredLogger
WithCorrelationId returns an instance of the same logger with the correlation ID field added to it.