logx

package
v0.0.0-...-5f1e29e Latest Latest
Warning

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

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

README

更新记录

2023-01-28

  • 更新 更换logrotate工具包为lumberjack,重点支持log文件gzip压缩,以减小日志文件过大问题
  • 更新 调整部分logger配置项
    loggerCfg:
    caller: true
    console: true
    level: "debug"
    logs:
      # 文件路径
      path: "logs/service-manager.log"
      # 最大保留天数,单位:天,默认:7天
      maxAge: 30
      # 文件分割大小,单位:MB,默认:100MB
      size: 100
      # 最大保留文件数量,默认:0为全部保留
      count: 0
      # 是否使用UTC时间
      isUTC: false 
      # 是否启用gzip压缩
      isGzip: true
    file:
    # 文件模式默认启用压缩且不使用UTC时间,如需支持请完善相应代码
      - path: "logs/debug.log"
        # 保存日志级别
        level: "debug"
        # 最大保留天数,单位:天,默认:7天
        maxAge: 7
        # 文件分割大小,单位:MB,默认:100MB
        size: 500
        # 最大保留文件数量,默认:0为全部保留
        count: 0
      - path: "logs/info.log"
        level: "info"
        maxAge: 30
    

Documentation

Index

Constants

View Source
const (
	File           = "file"           //文件路径
	Title          = "title"          //名称
	Trans          = "Trans"          //事务  (列 : 整个视频的调用流程)
	Action         = "Action"         //操作  (列 : 具体的功能)
	Method         = "Method"         //方法  (列 : 具体的方法)
	AppID          = "AppID"          //
	ServiceCluster = "ServiceCluster" //集群ID
	ServiceID      = "ServiceID"      //服务ID
	ServiceName    = "ServiceName"    //服务名称
)

Variables

This section is empty.

Functions

func DPanic

func DPanic(msg string, fields ...zap.Field)

DPanic .

func DPanicf

func DPanicf(msg string, args ...interface{})

DPanicf .

func Debug

func Debug(msg string, fields ...zap.Field)

Debug .

func Debugf

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

Debugf .

func DefaultWithMap

func DefaultWithMap(m map[string]interface{}) error

func Error

func Error(msg string, fields ...zap.Field)

Error .

func Errorf

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

Errorf .

func Fatal

func Fatal(msg string, fields ...zap.Field)

Fatal .

func Fatalf

func Fatalf(msg string, args ...interface{})

Fatalf .

func Info

func Info(msg string, fields ...zap.Field)

Info .

func Infof

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

Infof .

func InitLogZapMQ

func InitLogZapMQ(path string)

func Log

func Log(lvl Level, msg string, fields ...zap.Field)

func NewRocketMQCore

func NewRocketMQCore(enc zapcore.Encoder, topic string, MqProducer *rocketmq.MqProducer, enab zapcore.LevelEnabler) zapcore.Core

NewRocketMQCore creates a Core that writes logs to a WriteSyncer.

func Warn

func Warn(msg string, fields ...zap.Field)

Warn .

func Warnf

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

Warnf .

Types

type Base

type Base struct {
	Code            string `thrift:"code,1" db:"code" json:"code"`
	LogType         string `thrift:"logType,2" db:"logType" json:"logType"`
	Level           string `thrift:"level,3" db:"level" json:"level"`
	Source          string `thrift:"source,4" db:"source" json:"source"`
	IP              string `thrift:"ip,5" db:"ip" json:"ip"`
	Trans           string `thrift:"trans,6" db:"trans" json:"trans"`
	TransId         string `thrift:"transId,7" db:"transId" json:"transId"`
	Action          string `thrift:"action,8" db:"action" json:"action"`
	Method          string `thrift:"method,9" db:"method" json:"method"`
	Description     string `thrift:"description,10" db:"description" json:"description"`
	ApiType         string `thrift:"apiType,11" db:"apiType" json:"apiType"`
	ApiUrl          string `thrift:"apiUrl,12" db:"apiUrl" json:"apiUrl"`
	ProtoData       string `thrift:"protoData,13" db:"protoData" json:"protoData"`
	CreateTimestamp string `thrift:"createTimestamp,14" db:"createTimestamp" json:"createTimestamp"`
}

type FileLogger

type FileLogger struct {
	Path       string
	Level      *Level
	MaxSize    int
	MaxAge     int
	MaxBackups int
	IsUTC      bool
	IsCompress bool
}

type FilesLogger

type FilesLogger struct {
	Path       string
	MaxSize    int
	MaxAge     int
	MaxBackups int
	IsUTC      bool
	IsCompress bool
}

type Level

type Level int8
const (
	DebugLevel Level = iota - 1
	InfoLevel
	WarnLevel
	ErrorLevel
	DPanicLevel
	PanicLevel
	FatalLevel
)

Log level

func (Level) ZapLevel

func (level Level) ZapLevel() zapcore.Level

ZapLevel .

type LogBody

type LogBody struct {
	LogHeader
	//测量维度
	Measurement string `json:"Measurement,omitempty"`
	//应用ID
	AppID string `json:"AppID,omitempty"`
	////原始数据
	RawData string `json:"-"`
	//运行时间 (毫秒us) //耗时(毫秒us)
	ElapsedTime time.Duration `json:"ElapsedTime,omitempty"`
	Fields      []LogField    `gorm:"-"`
	//客户端IP
	ClientIP string `gorm:"comment:客户端IP" json:"ClientIP,omitempty"`
	//开始时间 (毫秒时间戳)
	StartTime string `gorm:"comment:开始时间" json:"StartTime,omitempty"`
	//结束时间 (毫秒时间戳)
	EndTime      string `gorm:"comment:结束时间" json:"EndTime,omitempty"`
	TimeUsed     int64
	TimeUsedType string
}

type LogDingding

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

LogDingding .

func (*LogDingding) Write

func (ld *LogDingding) Write(p []byte) (int, error)

Write 实现io.Writer 发送给钉钉群

type LogField

type LogField struct {
	Field string
	Value any `gorm:"-"` // influxdb _value
}

func LogAny

func LogAny(key string, val any) LogField

type LogHeader

type LogHeader struct {
	//ID (雪花算法)
	ID int64 `gorm:"type:bigint(20);primaryKey;comment: 自增 ID" json:"ID,omitempty"`
	//事务ID (雪花算法)
	TransId int64 `json:"TransId,omitempty"`
	//集群ID
	ServiceCluster string `json:"ServiceCluster,omitempty"`
	//服务ID
	ServiceID string `json:"ServiceID,omitempty"`
	//服务名
	ServiceName string `json:"ServiceName,omitempty"`

	//名称
	Title string `json:"title"`
	Level string `json:"level,omitempty"` //级别 (Debug, Info, Warn, Error, Panic, Fatal)
	Time  string `json:"time"`            //时间
	File  string `json:"file,omitempty"`  //
	Msg   string `json:"msg"`

	//事务  (列 : 整个视频的调用流程)
	Trans string `json:"Trans,omitempty"`
	//操作  (列 : 具体的功能)
	Action string `json:"Action,omitempty"`
	//方法  (列 : 具体的方法)
	Method string `json:"Method,omitempty"`

	//数据类型(QPS/服务/事件)
	DataType   string        `json:"DataType,omitempty"`
	CreateTime time.Duration `json:"CreateTime,omitempty"`
}

type LogKafka

type LogKafka struct {
	Topic   string
	Address []string
	Level   *Level
	// contains filtered or unexported fields
}

LogKafka 写入kafka

func (*LogKafka) Write

func (lk *LogKafka) Write(p []byte) (int, error)

Write 实现io.Writer接口

type LogQuery

type LogQuery struct {
	TransId     string `json:"TransId,omitempty"` //事务ID (雪花算法)
	Trans       string `json:"Trans,omitempty"`   //事务
	Level       string `json:"omitempty"`         //级别 (Debug, Info, Warn, Error, Panic, Fatal)
	Bucket      string `json:"Bucket,omitempty"`
	Measurement string `json:"Measurement,omitempty"` //测量维度
	StartTime   int64  `json:"StartTime,omitempty"`   //开始时间 (毫秒时间戳)
	EndTime     int64  `json:"EndTime,omitempty"`     //结束时间 (毫秒时间戳)
	LastTime    string `json:"LastTime,omitempty"`    //最近时间 (-2d/天;-5m/分钟)
	ServiceID   string `json:"ServiceID,omitempty"`   //服务ID
	ServiceName string `json:"ServiceName,omitempty"` //服务名
	AppID       string `json:"AppID,omitempty"`       //应用ID
	ClientIP    string `json:"ClientIP,omitempty"`    //客户端IP
}

type LogRocket

type LogRocket struct {
	Topic string
	Group string
	Tag   string
	Key   string
	*rocketmq.MqProducer
	LogBody
}

func NewProbeLog

func NewProbeLog(m map[string]interface{}) (*LogRocket, error)

NewProbeLog 初始化 数据探针

func (*LogRocket) MQDebug

func (l *LogRocket) MQDebug(title, trans, action string, fields ...LogField)

func (*LogRocket) MQError

func (l *LogRocket) MQError(title, trans, action string, fields ...LogField)

func (*LogRocket) MQInfo

func (l *LogRocket) MQInfo(title, trans, action string, fields ...LogField)

func (*LogRocket) MQPanic

func (l *LogRocket) MQPanic(title, trans, action string, fields ...LogField)

func (*LogRocket) MQWarn

func (l *LogRocket) MQWarn(title, trans, action string, fields ...LogField)

func (*LogRocket) SetTagKey

func (l *LogRocket) SetTagKey(tag, key string) *LogRocket

type LogRocketMQ

type LogRocketMQ struct {
	Topic   string
	Group   string
	Address []string
	Level   *Level
	// contains filtered or unexported fields
}

func (*LogRocketMQ) Write

func (l *LogRocketMQ) Write(p []byte) (int, error)

type LogStatistic

type LogStatistic struct {
	LogHeader
	FieldType string      // _field 统计值的类型, 如 在线设备 调阅耗时 网络延迟平均值 等等
	Field     string      // influxdb _field 四个类型: timeSince 时长 count 数量 num 计数 other flout64 其他
	Value     interface{} // influxdb _value
}

type Logger

type Logger struct {
	Kafka string
	File  string

	SourceItem string
	// contains filtered or unexported fields
}

logger .

func AddSkip

func AddSkip(skip int) *Logger

AddSkip 临时增加跳转层级

func Default

func Default() (*Logger, error)

Default .

func NewLog

func NewLog(opts ...Options) (*Logger, error)

New Logger

func NewWithMap

func NewWithMap(m map[string]interface{}) (*Logger, error)

NewWithMap new with map

func Stacktrace

func Stacktrace() *Logger

Stacktrace 临时开启堆栈输出

func (*Logger) AddSkip

func (l *Logger) AddSkip(skip int) *Logger

AddSkip 临时增加跳转层级

func (*Logger) DPanic

func (l *Logger) DPanic(msg string, fields ...zap.Field)

DPanic .

func (*Logger) DPanicf

func (l *Logger) DPanicf(msg string, args ...interface{})

DPanicf .

func (*Logger) Debug

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

Debug . 不同写入位置可能区分级别也不一样

func (*Logger) Debugf

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

Debugf .

func (*Logger) Error

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

Error .

func (*Logger) Errorf

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

Errorf .

func (*Logger) Fatal

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

Fatal .

func (*Logger) Fatalf

func (l *Logger) Fatalf(msg string, args ...interface{})

Fatalf .

func (*Logger) Info

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

Info .

func (*Logger) Infof

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

Infof .

func (*Logger) Log

func (l *Logger) Log(lvl Level, msg string, fields ...zap.Field)

func (*Logger) MQInfoElapsedTime

func (l *Logger) MQInfoElapsedTime(title string, fields ...zap.Field)

MQInfoElapsedTime 统计耗时

func (*Logger) Stacktrace

func (l *Logger) Stacktrace() *Logger

Stacktrace 临时开启堆栈输出

func (*Logger) Warn

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

Warn .

func (*Logger) Warnf

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

Wranf .

type Mail

type Mail struct {
	Level    *Level
	From     string
	To       string
	Subject  string
	Stmp     string
	Port     int
	Password string
	// contains filtered or unexported fields
}

Mail 发送邮件

func (*Mail) Write

func (lm *Mail) Write(p []byte) (int, error)

Write 实现io.Writer,发送邮件

type Message

type Message struct {
	Msg         string      `json:"msg"`
	Level       string      `json:"level"`
	TimeKey     string      `json:"time"`
	CallerKey   string      `json:"file"`
	ServiceName string      `json:"serviceName"`
	Location    string      `json:"location"`
	Other       interface{} `json:"detail"`
}

Message

type MsgTags

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

type Options

type Options func(l *Logger)

Options .

func WithCaller

func WithCaller() Options

WithCaller 添加文件名、行号、函数名等

func WithConsole

func WithConsole() Options

func WithDingding

func WithDingding(secret, access_token string, level Level, fields ...zap.Field) Options

func WithFile

func WithFile(fileLogger []FileLogger) Options

WithFile 开启写入文件

func WithInitialFields

func WithInitialFields(key, value string) Options

WithInitialFields 固定字段

func WithKafka

func WithKafka(kafkaLogger []LogKafka) Options

WithKafka 启用kafka后,日志将打入kafka

func WithLevel

func WithLevel(level Level) Options

WithLevel 指定日志级别

func WithLogs

func WithLogs(fileLogger FilesLogger) Options

WithLogs 开启写入单个文件

func WithLogsEncoder

func WithLogsEncoder(fileLogger FilesLogger, enCoder zapcore.Encoder) Options

WithLogs 开启写入单个文件 并且制定enCider

func WithMail

func WithMail(mailLogger []Mail) Options

WithMail 发送email 默认Level为DPanic

func WithRocketMQ

func WithRocketMQ(rocketmqLogger []LogRocketMQ) Options

WithRocketMQ 启用RocketMQ

func WithSkip

func WithSkip(skip int) Options

func WithSourceItem

func WithSourceItem(item string) Options

func WithStacktrace

func WithStacktrace(level Level) Options

type Robot

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

func NewRobot

func NewRobot(token, secret string) *Robot

func (*Robot) SendLinkMessage

func (robot *Robot) SendLinkMessage(title string, text string, messageUrl string, picUrl string) error

func (*Robot) SendMarkdownMessage

func (robot *Robot) SendMarkdownMessage(title string, text string, atMobiles []string, isAtAll bool) error

func (*Robot) SendMessage

func (robot *Robot) SendMessage(msg interface{}) error

func (*Robot) SendTextMessage

func (robot *Robot) SendTextMessage(content string, atMobiles []string, isAtAll bool) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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