rlog

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

RLog

Why RLog

Rlog is a wrapper for the Uber Zap logging framework. The reason we want to wrap zap and not use it directly is that it makes it easier to change logger in the future if necessary. RLog was made when we wanted to switch from Logrus to Zap and encountered this exact problem.

What RLog offers

Rlog offers a global logger with both context (go context) and non context aware logging functions. Context aware functions will add certain predefined fields from a context and also correlate any trace information with the logs.

Rlog offers leveled and structured logging in the same manner as Zap does. The levels supported are Info, Debug, Warn, Error and Fatal. Logs are normally output as JSON but can be output in a more readable form when developing, its important to note that in prod all logs shall be in the JSON format.

Config

Rlog is configured using environment variables, from either an env file or the environment its running in.

LOG_LEVEL

sets the log level

LOG_OUTPUT

set where the logs should be sent, defaults to stderr. Logs can be sent to a file an url or stdout/stderr. Logs can be sent to multiple locations with a comma separated string. E.g. LOG_OUTPUT="/home/user/foo/.ror/log,stderr". This example logs to both a file and stderr

LOG_OUTPUT_ERROR

Set where error level logs should be sent, works the same as LOG_OUTPUT

LOG_DEVELOP

Set wheter or not logs should be on JSON format or a more human readable format. False = JSON True = more human readable

Documentation

Index

Constants

View Source
const (
	RequestIdKey CorrelationIdType = iota
	SessionIdKey
	LOG_LEVEL        = "LOG_LEVEL"
	LOG_OUTPUT       = "LOG_OUTPUT"
	LOG_OUTPUT_ERROR = "LOG_OUTPUT_ERROR"
	LOG_DEVELOP      = "LOG_DEVELOP"
)

Variables

This section is empty.

Functions

func AddContextKeyField added in v0.0.11

func AddContextKeyField(key string) error

AddContextKeyField adds a key to look for in a contexts so that we can add the context value as a persistent field to all logs

func Debug

func Debug(msg string, fields ...Field)

Debug logs a message at InfoLevel. The message includes any fields passed at the log site.

func Debugc

func Debugc(ctx context.Context, msg string, fields ...Field)

Debugc logs a message at DebugLevel with context. The message includes any fields passed at the log site and any tracing fields in the attached context, if the context contains known fields these are also added

func Error

func Error(msg string, err error, fields ...Field)

Error logs a message at InfoLevel. The message includes any fields passed at the log site.

func Errorc

func Errorc(ctx context.Context, msg string, err error, fields ...Field)

Errorc logs a message at ErrorLevel with context. The message includes any fields passed at the log site and any tracing fields in the attached context, if the context contains known fields these are also added

func Fatal

func Fatal(msg string, err error, fields ...Field)

Fatal logs a message at InfoLevel. The message includes any fields passed at the log site. The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.

func Fatalc

func Fatalc(ctx context.Context, msg string, err error, fields ...Field)

Fatalc logs a message at FatalLevel with context. The message includes any fields passed at the log site and any tracing fields in the attached context, if the context contains known fields these are also added The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.

func Info

func Info(msg string, fields ...Field)

Info logs a message at InfoLevel. The message includes any fields passed at the log site.

func Infoc

func Infoc(ctx context.Context, msg string, fields ...Field)

Infoc logs a message at InfoLevel with context. The message includes any fields passed at the log site and any tracing fields in the attached context, if the context contains known fields these are also added

func Infof

func Infof(format string, v ...any)

Infof logs a message at InfoLevel with context. The message is formated with sprintf.

func InitializeRlog

func InitializeRlog()

func LogMiddleware

func LogMiddleware() gin.HandlerFunc

func Warn

func Warn(msg string, fields ...Field)

Warn logs a message at InfoLevel. The message includes any fields passed at the log site.

func Warnc

func Warnc(ctx context.Context, msg string, fields ...Field)

Warnc logs a message at WarnLevel with context. The message includes any fields passed at the log site and any tracing fields in the attached context, if the context contains known fields these are also added

Types

type CorrelationIdType

type CorrelationIdType int

type Field

type Field = zap.Field

func Any

func Any(key string, value interface{}) Field

func ByteString

func ByteString(key string, value []byte) Field

func Int

func Int(key string, value int) Field

func Int64

func Int64(key string, value int64) Field

func String

func String(key, value string) Field

func Strings

func Strings(key string, value []string) Field

func Uint

func Uint(key string, value uint) Field

type Logger

type Logger struct {
	*zap.Logger
	ContextKeyFields []string
}

Jump to

Keyboard shortcuts

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