logger

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	InstanceZapLogger int = iota
	InstanceLogrusLogger
)

Variables

View Source
var (
	RqIDCtxKey       = contextKey("request_id")
	RqClientIPCtxKey = contextKey("client_ip")
	RqExecTimeCtxKey = contextKey("exec_time")
	RqURICtxKey      = contextKey("request_uri")
)

Context key definition. RqIDCtxKey is request ID context key. RqClientIPCtxKey is request client IP context key. ExecTimeCtxKey is execute time context key.

Functions

func Debugf

func Debugf(format string, args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Fatalf

func Fatalf(err error, format string, args ...interface{})

func GenRequestID

func GenRequestID() string

func GetRqClientIPFromCtx

func GetRqClientIPFromCtx(ctx context.Context) string

GetRqClientIPFromCtx get client IP in context and returns as string.

func GetRqExecTimeFromCtx

func GetRqExecTimeFromCtx(ctx context.Context) float64

GetRqExecTimeFromCtx get exec time in context and returns as string.

func GetRqIDFromCtx

func GetRqIDFromCtx(ctx context.Context) string

GetRqIDFromCtx get request ID in context and returns as string.

func GetRqURIFromCtx

func GetRqURIFromCtx(ctx context.Context) string

GetRqURIFromCtx get exec time in context and returns as string.

func Infof

func Infof(format string, args ...interface{})

func Infow

func Infow(args ...interface{})

func NewLogger

func NewLogger(config Configuration, loggerInstance int) error

NewLogger returns an instance of logger

func Panicf

func Panicf(format string, args ...interface{})

func Report

func Report(err error, format string, args ...interface{})

func SetRqIDToCtx

func SetRqIDToCtx(ctx context.Context) context.Context

SetRqIDToCtx set request ID to context

func SetTimeToCtx

func SetTimeToCtx(ctx context.Context) context.Context

SetTimeToCtx get exec time in context and returns as string.

func Warnf

func Warnf(format string, args ...interface{})

Types

type Configuration

type Configuration struct {
	EnableConsole     bool
	ConsoleJSONFormat bool
	ConsoleLevel      string
	EnableFile        bool
	FileJSONFormat    bool
}

Configuration stores the config for the logger For some loggers there can only be one level across writers, for such the level of Console is picked by default

type Fields

type Fields map[string]interface{}

Fields Type to pass when we want to call WithFields for structured logging

type LoggerV2

type LoggerV2 interface {
	Debugf(format string, args ...interface{})

	Infof(format string, args ...interface{})
	Infow(args ...interface{})

	Warnf(format string, args ...interface{})

	Errorf(format string, args ...interface{})

	Fatalf(err error, format string, args ...interface{})

	Panicf(format string, args ...interface{})

	Report(err error, format string, args ...interface{})

	WithFields(keyValues Fields) LoggerV2
}

LoggerV2 is our contract for the logger

func Context

func Context(ctx context.Context) LoggerV2

func Log

func Log() LoggerV2

func WithFields

func WithFields(keyValues Fields) LoggerV2

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL