log

package
v0.0.0-...-3192183 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package log direct use logger

Index

Constants

This section is empty.

Variables

View Source
var (

	// CommonLogOpt use to easliy construct custom log options
	CommonLogOpt = defaultLogOpt
)

Functions

func GetTraceIdWithCtx

func GetTraceIdWithCtx(ctx context.Context) string

GetTraceIdWithCtx get trace id from ctx

func NewTraceIdWithCtx

func NewTraceIdWithCtx(ctx context.Context) context.Context

NewTraceIdWithCtx TODO

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger self defined Logger

func GetDefaultLogger

func GetDefaultLogger() *Logger

GetDefaultLogger get default logger if no default logger was initilized ** nil ** will be return

func GetLogger

func GetLogger(name string, opt *LoggerOpt) *Logger

GetLogger get logger with specified name or new a logger with options

func NewFromLogger

func NewFromLogger(logger *Logger) *Logger

NewFromLogger new a logger from a logger

func (*Logger) Debug

func (l *Logger) Debug(ctx context.Context, msg string, fields ...zap.Field)

Debug the msg

func (*Logger) Error

func (l *Logger) Error(ctx context.Context, msg string, fields ...zap.Field)

Error the msg

func (*Logger) Fatal

func (l *Logger) Fatal(ctx context.Context, msg string, fields ...zap.Field)

Fatal the msg and exit with errcode 1

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, msg string, fields ...zap.Field)

Info the msg

func (*Logger) SetLevel

func (l *Logger) SetLevel(level zapcore.Level)

SetLevel setting log level

func (*Logger) Warn

func (l *Logger) Warn(ctx context.Context, msg string, fields ...zap.Field)

Warn the msg

func (*Logger) WithLoggerMetaFields

func (l *Logger) WithLoggerMetaFields(fields ...zapcore.Field) *Logger

WithLoggerMetaFields set meta fields for logger

type LoggerOpt

type LoggerOpt struct {
	LogLevel         zapcore.Level
	Directory        string // log file directory
	Name             string // log file name
	TraceIDEnable    bool   // enable traceid field
	MaxSize          int    // Log File Max Size MB
	MaxBackups       int    // The number of backup log file
	MaxAge           int    // The days the log will be kept
	IsDefault        bool   // is defalut logger?
	ConsoleLogEnable bool   // enable console log?
}

LoggerOpt configures the logger

func (LoggerOpt) CreateDirectory

func (opt LoggerOpt) CreateDirectory() error

CreateDirectory create logfile directory

func (LoggerOpt) GetLogFilePath

func (opt LoggerOpt) GetLogFilePath() string

GetLogFilePath get log dst file path

func (LoggerOpt) WithConsoleLog

func (opt LoggerOpt) WithConsoleLog(enable bool) LoggerOpt

WithConsoleLog enable console log

func (LoggerOpt) WithDirectory

func (opt LoggerOpt) WithDirectory(path string) LoggerOpt

WithDirectory setting log file directory

func (LoggerOpt) WithLogLevel

func (opt LoggerOpt) WithLogLevel(level zapcore.Level) LoggerOpt

WithLogLevel sets log level

func (LoggerOpt) WithLogRetention

func (opt LoggerOpt) WithLogRetention(maxSize int, maxBackups int, maxAge int) LoggerOpt

WithLogRetention sets log retention

func (LoggerOpt) WithTraceIDEnable

func (opt LoggerOpt) WithTraceIDEnable(enable bool) LoggerOpt

WithTraceIDEnable setting traceid

Directories

Path Synopsis
Package gorm Logger Implementation
Package gorm Logger Implementation

Jump to

Keyboard shortcuts

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