logs

package
v2.9.6 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

README

日志

package logger_test

import (
	"errors"
	"testing"

	"github.com/aid297/aid/v2/logger"
	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
)

func Test1(t *testing.T) {
	t.Run("test1 创建日志", func(t *testing.T) {
		var (
			zapLogger *zap.Logger
			err       error
		)

		if zapLogger, err = logger.NewZapLog(
			logger.Level(zapcore.DebugLevel),
			logger.Path("."),
			logger.InConsole(false),
			logger.EncoderType(logger.EncoderTypeConsole),
			logger.Compress(true),
			logger.MaxBackup(30),
			logger.MaxSize(10),
			logger.MaxDay(30),
		); err != nil {
			t.Fatal(err)
		}

		zapLogger.Info("test-info", zap.String("a", "b"))
		zapLogger.Debug("test-debug", zap.String("c", "d"))
		zapLogger.Warn("test-warning", zap.Any("any", []any{"haha", "hehe", 1, 2, 3, 4}))
		zapLogger.Error("test-error", zap.Errors("errors", []error{errors.New("err1"), errors.New("err2"), errors.New("err3")}))
	})
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewZapLog

func NewZapLog(attrs ...ZapLogAttr) (*zap.Logger, error)

Types

type ZapLog

type ZapLog struct {
	Level     zapcore.Level
	Filename  string
	MaxSize   int
	MaxBackup int
	MaxDay    int
	Compress  bool
	InConsole bool
	// Extension   string
	EncoderType ZapLogEncoderType
}

ZapProvider Zap日志服务提供者

func (*ZapLog) GetCompress

func (zapLog *ZapLog) GetCompress() bool

func (*ZapLog) GetFilename

func (zapLog *ZapLog) GetFilename() string

func (*ZapLog) GetInConsole

func (zapLog *ZapLog) GetInConsole() bool

func (*ZapLog) GetLevel

func (zapLog *ZapLog) GetLevel() zapcore.Level

func (*ZapLog) GetMaxBackup

func (zapLog *ZapLog) GetMaxBackup() int

func (*ZapLog) GetMaxDay

func (zapLog *ZapLog) GetMaxDay() int

func (*ZapLog) GetMaxSize

func (zapLog *ZapLog) GetMaxSize() int

func (*ZapLog) SetAttrs

func (my *ZapLog) SetAttrs(attrs ...ZapLogAttr) (err error)

func (*ZapLog) SetCompress

func (zapLog *ZapLog) SetCompress(compress bool) (err error)

func (*ZapLog) SetEncoderType

func (zapLog *ZapLog) SetEncoderType(encoderType ZapLogEncoderType) (err error)
func (zapLog *ZapLog) SetExtension(extension string) (err error) {
	zapLog.Extension = extension
	return nil
}

func (*ZapLog) SetFilename

func (zapLog *ZapLog) SetFilename(filename string) (err error)

func (*ZapLog) SetInConsole

func (zapLog *ZapLog) SetInConsole(inConsole bool) (err error)

func (*ZapLog) SetLevel

func (zapLog *ZapLog) SetLevel(level zapcore.Level) (err error)

func (*ZapLog) SetMaxBackup

func (zapLog *ZapLog) SetMaxBackup(maxBackup int) (err error)

func (*ZapLog) SetMaxDay

func (zapLog *ZapLog) SetMaxDay(maxDay int) (err error)

func (*ZapLog) SetMaxSize

func (zapLog *ZapLog) SetMaxSize(maxSize int) (err error)

type ZapLogAttr

type ZapLogAttr func(zapLog ZapLogger) (err error)

func Compress

func Compress(compress bool) ZapLogAttr

func EncoderType

func EncoderType(encoderType ZapLogEncoderType) ZapLogAttr

func Filename

func Filename(filename string) ZapLogAttr

func InConsole

func InConsole(inConsole bool) ZapLogAttr

func Level

func Level(level zapcore.Level) ZapLogAttr

func MaxBackup

func MaxBackup(maxBackup int) ZapLogAttr

func MaxDay

func MaxDay(maxDay int) ZapLogAttr

func MaxSize

func MaxSize(maxSize int) ZapLogAttr

type ZapLogEncoderType

type ZapLogEncoderType string

ZapProvider Zap日志服务提供者

const (
	EncoderTypeConsole ZapLogEncoderType = "CONSOLE"
	EncoderTypeJson    ZapLogEncoderType = "JSON"
)

type ZapLogger

type ZapLogger interface {
	SetLevel(level zapcore.Level) (err error)
	SetFilename(path string) (err error)
	SetMaxSize(maxSize int) (err error)
	SetMaxBackup(maxBackup int) (err error)
	SetMaxDay(maxDay int) (err error)
	SetCompress(compress bool) (err error)
	SetInConsole(inConsole bool) (err error)
	SetEncoderType(encoderType ZapLogEncoderType) (err error)
	GetLevel() zapcore.Level
	GetFilename() string
	GetMaxSize() int
	GetMaxBackup() int
	GetMaxDay() int
	GetCompress() bool
	GetInConsole() bool
	SetAttrs(attrs ...ZapLogAttr) (err error)
}

ZapProvider Zap日志服务提供者

Jump to

Keyboard shortcuts

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