log

package
v0.0.48 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 16 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CInfo

func CInfo(ctx context.Context, msg string, keysAndValues ...any)

func InitConsoleLogger

func InitConsoleLogger(moduleName string,
	logLevel int,
	isJson bool, moduleVersion string) error

InitConsoleLogger init osStdout and osStderr.

func InitFromConfig

func InitFromConfig(
	loggerPrefixName, moduleName string,
	logLevel int,
	isStdout bool,
	isJson bool,
	logLocation string,
	rotateCount uint,
	rotationTime uint,
	moduleVersion string,
) error

InitFromConfig initializes a Zap-based logger.

func ZDebug

func ZDebug(ctx context.Context, msg string, keysAndValues ...any)

func ZError

func ZError(ctx context.Context, msg string, err error, keysAndValues ...any)

func ZInfo

func ZInfo(ctx context.Context, msg string, keysAndValues ...any)

func ZWarn

func ZWarn(ctx context.Context, msg string, err error, keysAndValues ...any)

Types

type Color

type Color uint8

Color represents a text color.

const (
	Black Color = iota + 30
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	White
)

Foreground colors.

func (Color) Add

func (c Color) Add(s string) string

Add adds the coloring to the given string.

type Logger

type Logger interface {
	// Debug logs a message at the debug level including any supplementary key-value pairs.
	// Useful for detailed output for debugging purposes.
	Debug(ctx context.Context, msg string, keysAndValues ...any)

	// Info logs a message at the info level along with any supplementary key-value pairs.
	// Ideal for general operational messages that inform about the system's state.
	Info(ctx context.Context, msg string, keysAndValues ...any)

	// Warn logs a message at the warning level, indicating potential issues in the system.
	// It includes an error object and any supplementary key-value pairs.
	Warn(ctx context.Context, msg string, err error, keysAndValues ...any)

	// Error logs a message at the error level, indicating serious problems that need attention.
	// It includes an error object and any supplementary key-value pairs.
	Error(ctx context.Context, msg string, err error, keysAndValues ...any)

	// WithValues returns a new Logger instance that will include the specified key-value pairs
	// in all subsequent log messages. Useful for adding consistent context to a series of logs.
	WithValues(keysAndValues ...any) Logger

	// WithName returns a new Logger instance prefixed with the specified name.
	// This is helpful for distinguishing logs generated from different sources or components.
	WithName(name string) Logger

	// WithCallDepth returns a new Logger instance that adjusts the call depth for identifying
	// the source of log messages. Useful in wrapper or middleware layers to maintain accurate log source information.
	WithCallDepth(depth int) Logger
}

type SqlLogger

type SqlLogger struct {
	LogLevel                  gormLogger.LogLevel
	IgnoreRecordNotFoundError bool
	SlowThreshold             time.Duration
}

func NewSqlLogger

func NewSqlLogger(logLevel gormLogger.LogLevel, ignoreRecordNotFoundError bool, slowThreshold time.Duration) *SqlLogger

func (SqlLogger) Error

func (SqlLogger) Error(ctx context.Context, msg string, args ...any)

func (SqlLogger) Info

func (SqlLogger) Info(ctx context.Context, msg string, args ...any)

func (*SqlLogger) LogMode

func (l *SqlLogger) LogMode(logLevel gormLogger.LogLevel) gormLogger.Interface

func (*SqlLogger) Trace

func (l *SqlLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (SqlLogger) Warn

func (SqlLogger) Warn(ctx context.Context, msg string, args ...any)

type ZapLogger

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

func NewConsoleZapLogger

func NewConsoleZapLogger(
	moduleName string,
	logLevel int,
	isJson bool,
	moduleVersion string,
	outPut *os.File) (*ZapLogger, error)

func NewZapLogger

func NewZapLogger(
	loggerPrefixName, moduleName string,
	logLevel int,
	isStdout bool,
	isJson bool,
	logLocation string,
	rotateCount uint,
	rotationTime uint,
	moduleVersion string,
) (*ZapLogger, error)

func (*ZapLogger) Debug

func (l *ZapLogger) Debug(ctx context.Context, msg string, keysAndValues ...any)

func (*ZapLogger) Error

func (l *ZapLogger) Error(ctx context.Context, msg string, err error, keysAndValues ...any)

func (*ZapLogger) Info

func (l *ZapLogger) Info(ctx context.Context, msg string, keysAndValues ...any)

func (*ZapLogger) ToZap

func (l *ZapLogger) ToZap() *zap.SugaredLogger

func (*ZapLogger) Warn

func (l *ZapLogger) Warn(ctx context.Context, msg string, err error, keysAndValues ...any)

func (*ZapLogger) WithCallDepth

func (l *ZapLogger) WithCallDepth(depth int) Logger

func (*ZapLogger) WithName

func (l *ZapLogger) WithName(name string) Logger

func (*ZapLogger) WithValues

func (l *ZapLogger) WithValues(keysAndValues ...any) Logger

type ZkLogger

type ZkLogger struct{}

func NewZkLogger

func NewZkLogger() *ZkLogger

func (*ZkLogger) Printf

func (l *ZkLogger) Printf(format string, a ...any)

Jump to

Keyboard shortcuts

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