log

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

func Debugf

func Debugf(format string, args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func GetWriter

func GetWriter() io.Writer

GetWriter 获取输出流

func Info

func Info(args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func InitLogger

func InitLogger(c Config)

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(format string, args ...interface{})

Types

type Config

type Config struct {
	Level      string `json:"level" yaml:"level"`           // 输出的日志级别, 默认debug
	Target     string `json:"target" yaml:"target"`         // 日志标识,一般使用服务名,必须
	ID         string `json:"id" yaml:"id"`                 // 与target组成唯一标识
	OutPath    string `json:"outPath" yaml:"outPath"`       // 日志文件输出路径,默认logs
	MaxSize    int    `json:"maxSize" yaml:"maxSize"`       // 文件最大大小 MB,默认50M
	CallerSkip int    `json:"callerSkip" yaml:"callerSkip"` // 跳过多少层次,找caller
}

func NewConfigByMap

func NewConfigByMap(m map[string]interface{}) Config

NewConfigByMap 从一个map中创建Config

func (*Config) LogPath

func (c *Config) LogPath() string

LogPath 日志文件路径

func (*Config) ServiceID

func (c *Config) ServiceID() string

ServiceID 服务ID, 使用Target+ID生成

func (*Config) Set

func (c *Config) Set(k string, v interface{})

Set 动态赋值Config属性

type Logger

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

Logger 内部实现使用zap.SugaredLogger 实现apiserver.Logger接口 日志级别 Error > Warn > Info > Debug

func New

func New(c Config) *Logger

New 通过自定义输出流,限制文件输出大小控制 未设置自动清理 未实现按日分文件 使用LocalTime作为分文件的时间点 旧文件格式 /var/log/foo/server-2016-11-04T18-30-00.000.log

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

func (*Logger) Error

func (l *Logger) Error(args ...interface{})

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

func (*Logger) Warn

func (l *Logger) Warn(args ...interface{})

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...interface{})

Jump to

Keyboard shortcuts

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