logging

package
v1.2.29 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: MIT Imports: 23 Imported by: 0

README

mindbenders

Logger

type ILogWriter interface {
	Log(context.Context, Fields, Level, string)
	Info(context.Context, Fields, string)
	Error(context.Context, Fields, string)
	Warn(context.Context, Fields, string)
	Debug(context.Context, Fields, string)
}

//ILogger ...
type IDotpeLogger interface {
    ILogWriter
    GinLogger() gin.HandlerFunc
}

In order to initialize one has to have pass the 2 things for sure.

  1. logger.WithAppInfo(os.Getenv("APP")), definition is as follows

    func WithAppInfo(app string) Option {
        return func(dlogger *dlogger) {
            dlogger.app = app
        }
    }
    

logger initializations Usage [link]

package utils

import (
    "os"

    mbinterfaces "gitlab.com/dotpe/mindbenders/interfaces"
    logger "gitlab.com/dotpe/mindbenders/logging"
)

var DLogger mbinterfaces.IDotpeLogger

//write your logic to initialize or fetch hookContainer objectct

// InitLogger ..
DLogger, err := logger.Init(
    logger.WithAppInfo(os.Getenv("APP")),
    logger.WithAccessLogOptions(
        logger.AccessLogOptionRequestBody,
        aopt1, // check definition of aopt1, similary you can pass more functions as you need
    ),
    logger.WithLogOptions(opt1),// check definition of opt1, similary you can pass more functions as you need
)

func aopt1(c *gin.Context, fields *Fields) {
    c.Set("ip", c.ClientIP())
}

func opt1(ctx context.Context, fields *Fields) {
    (*fields)["clientIP"] = ctx.Value("ip")
}

attaching GinLogger to add accessLog apiGroup.Use(utils.DLogger.GinLogger())

Recovery Middleware

The call ginmiddleware.Recovery(utils.DLogger) is for making the gin-engine failure safe.

Note: you can't control crashes in orphened go-routines

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessLogOptionRequestBody added in v1.1.0

func AccessLogOptionRequestBody(c *gin.Context, fields Fields)

func WithZap added in v1.2.29

func WithZap(dlogger *dlogger)

func WithZero added in v1.2.29

func WithZero(dlogger *dlogger)

Types

type Fields added in v1.2.29

type Fields map[string]interface{}

type IDotpeLogger added in v1.2.14

type IDotpeLogger interface {
	ILogWriter
	Gin() gin.HandlerFunc
}

ILogger ...

func MustGet added in v1.2.15

func MustGet(opts ...Option) IDotpeLogger

type ILogWriter added in v1.2.14

type ILogWriter interface {
	// Deprecated: Use [Log] instead.
	WriteLogs(context.Context, Fields, Level, string)

	Log(context.Context, Fields, Level, string)
	Info(context.Context, Fields, string)
	Warn(context.Context, Fields, string)
	Error(context.Context, Fields, string)
	Debug(context.Context, Fields, string)
	Panic(context.Context, Fields, string)
	Fatal(context.Context, Fields, string)
}

func DefaultLogWriter added in v1.2.15

func DefaultLogWriter() ILogWriter

func LogWriter added in v1.2.15

func LogWriter() ILogWriter

type Level added in v1.2.29

type Level int8
const (
	PanicLevel Level = iota
	FatalLevel
	ErrorLevel
	WarnLevel
	InfoLevel
	DebugLevel
	TraceLevel
)

func (Level) String added in v1.2.29

func (l Level) String() string

type Option added in v1.1.0

type Option func(dlogger *dlogger)

func WithAccessLogOptions added in v1.1.0

func WithAccessLogOptions(opts ...accessLogOption) Option

func WithAppInfo added in v1.1.0

func WithAppInfo(app string) Option

func WithLogOptions added in v1.1.0

func WithLogOptions(opts ...logOption) Option

func WithMetric added in v1.2.29

func WithMetric(level Level) Option

Jump to

Keyboard shortcuts

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