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 ¶ added in v0.4.0
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 ¶ added in v0.2.1
func SetCorrelationIdContextKey(key string)
SetCorrelationIdContextKey sets the correlation ID context key. By default, it is "correlation_id"
func SetCorrelationIdFieldKey ¶ added in v0.2.1
func SetCorrelationIdFieldKey(key string)
SetCorrelationIdFieldKey sets the correlation ID field key in JSON responses. By default, it is "correlation_id"
Types ¶
type CLogger ¶ added in v0.2.0
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 ¶ added in v0.2.1
WithContextCorrelationId returns an instance of the same logger with the correlation ID taken from the context added to it.
func (*CLogger) WithCorrelationId ¶ added in v0.2.0
WithCorrelationId returns an instance of the same logger with the correlation ID field added to it.
type CSugaredLogger ¶ added in v0.2.0
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 ¶ added in v0.4.2
func (l *CSugaredLogger) Fatalln(args ...interface{})
func (*CSugaredLogger) Print ¶ added in v0.4.1
func (l *CSugaredLogger) Print(args ...interface{})
func (*CSugaredLogger) Printf ¶ added in v0.4.1
func (l *CSugaredLogger) Printf(format string, args ...interface{})
func (*CSugaredLogger) Println ¶ added in v0.4.1
func (l *CSugaredLogger) Println(args ...interface{})
func (*CSugaredLogger) With ¶ added in v0.5.0
func (l *CSugaredLogger) With(args ...interface{}) *CSugaredLogger
func (*CSugaredLogger) WithContextCorrelationId ¶ added in v0.2.1
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 ¶ added in v0.2.0
func (l *CSugaredLogger) WithCorrelationId(correlationId interface{}) *CSugaredLogger
WithCorrelationId returns an instance of the same logger with the correlation ID field added to it.