logging

package
v0.15.0 Latest Latest
Warning

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

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

Documentation

Overview

Package logging is the logging package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDefaultLogger

func GetDefaultLogger() *zerolog.Logger

GetDefaultLogger generates and returns a default logger instance.

Types

type GormLoggerAdapter

type GormLoggerAdapter struct {
	Logger *zerolog.Logger
	// contains filtered or unexported fields
}

GormLoggerAdapter is an adapter for integrating the GORM library with the zerolog logger.

func CreateGormLoggerAdapter

func CreateGormLoggerAdapter(zLog *zerolog.Logger, serviceName string) *GormLoggerAdapter

CreateGormLoggerAdapter creates a new instance of the GormLoggerAdapter struct that wraps a zerolog.Logger and provides logging functionality for GORM. It takes a pointer to a zerolog.Logger and a serviceName string as parameters. It determines the log level based on the global log level of the zerolog.Logger and assigns the corresponding logger.GormLogLevel to the newly created GormLoggerAdapter. It creates a subservice logger by setting the "subservice" field in the zerolog.Logger context with the serviceName parameter and returns the GormLoggerAdapter.

func (*GormLoggerAdapter) Error

func (a *GormLoggerAdapter) Error(_ context.Context, msg string, parameters ...any)

Error logs an error message.

func (*GormLoggerAdapter) GetMode

func (a *GormLoggerAdapter) GetMode() logger.GormLogLevel

GetMode returns the current log level of the GormLoggerAdapter.

func (*GormLoggerAdapter) GetStackLevel

func (a *GormLoggerAdapter) GetStackLevel() int

GetStackLevel returns the stack level of the GormLoggerAdapter.

func (*GormLoggerAdapter) Info

func (a *GormLoggerAdapter) Info(_ context.Context, msg string, parameters ...any)

Info logs an informative message.

func (*GormLoggerAdapter) SetMode

func (a *GormLoggerAdapter) SetMode(level logger.GormLogLevel) logger.GormLoggerInterface

SetMode sets the log level of the GormLoggerAdapter to the specified value. If the level is Silent, set the logLevel to 1. If the level is Error, set the logLevel to 2 and set the Logger level to zerolog.ErrorLevel. If the level is Warn, set the logLevel to 3 and set the Logger level to zerolog.WarnLevel. If the level is Info, set the logLevel to 4 and set the Logger level to zerolog.InfoLevel. There is no Debug mode inn GormLoggerAdapter.

func (*GormLoggerAdapter) SetStackLevel

func (a *GormLoggerAdapter) SetStackLevel(level int)

SetStackLevel sets the stack level to the specified value.

func (*GormLoggerAdapter) Trace

func (a *GormLoggerAdapter) Trace(_ context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

Trace logs the execution time and details of a database query. It checks the log level and the error status to determine the appropriate logging action. If the log level is set to logger.Error and there is an error (excluding "record not found"), it logs a warning message with the error details and the executed query. If the elapsed time exceeds the slow query threshold and the log level is set to logger.Warn, it logs a warning message with the slow query details. If the log level is set to logger.Info, it logs an executing query message with the query details.

func (*GormLoggerAdapter) Warn

func (a *GormLoggerAdapter) Warn(_ context.Context, msg string, parameters ...any)

Warn logs a warning message.

Jump to

Keyboard shortcuts

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