logger

package module
v0.1.1-0...-587f1f2 Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: MulanPSL-2.0 Imports: 10 Imported by: 0

README

logger

介绍

自定义日志输出,测试版!!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MaxStackTrace 记录的错误信息的调用栈最大深度
	MaxStackTrace = 10
)

Functions

func NewFormatter

func NewFormatter(service, env string) logrus.Formatter

NewFormatter 获得日志规范对应的格式化对象

func NewLogger

func NewLogger(service, env string) (*logrus.Logger, error)

NewLogger 创建新的日志对象

Types

type LogsV1

type LogsV1 struct {
	Schema      string                 `json:"schema"`
	Time        string                 `json:"t"`
	Level       string                 `json:"l"`
	Service     string                 `json:"s"`
	Channel     string                 `json:"c"`
	ID          string                 `json:"i"`
	Environment string                 `json:"e"`
	User        string                 `json:"u"`
	Message     string                 `json:"m"`
	Context     map[string]interface{} `json:"ctx"`
	Err         string                 `json:"err"`
	Request     *RequestData           `json:"request,omitempty"`
}

LogsV1 logs.v1 日志输出内容

type LogsV1Formatter

type LogsV1Formatter struct {
	// 时间格式,默认ISO8601,精确到秒
	TimeLayout  string
	Service     string
	Environment string
}

LogsV1Formatter 日志格式化

func (*LogsV1Formatter) Format

func (af *LogsV1Formatter) Format(entry *logrus.Entry) ([]byte, error)

Format implements logrus.Formatter interface

type RequestData

type RequestData struct {
	IP       string            `json:"ip"`
	Method   string            `json:"method"`
	Path     string            `json:"path"`
	Headers  map[string]string `json:"header"`
	Status   string            `json:"status"`
	Duration string            `json:"duration"`
	Param    logrus.Fields     `json:"param"`
}

RequestData 请求相关的参数

type Schema

type Schema string

Schema 日志规范

const (
	// LogsV1 运行日志
	SchemaGeneralLogsV1 Schema = "general.logs.v1"
	// HTTPRequestV1 请求日志
	SchemaHTTPRequestV1 Schema = "http.request.v1"
)

Jump to

Keyboard shortcuts

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