logrus_log_hook

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2021 License: MIT Imports: 7 Imported by: 0

README

logrus-log-hook

teamones log 服务上报 logrus hook

install

go get github.com/teamones-open/logrus-log-hook

usage

	hook := httphook.New(
		"service-name",
		"localhost:8081/monolog/add",
		logrus.AllLevels,
	)

	hook.BeforePost = func(req *http.Request) error {
		return nil
	}
	hook.AfterPost = func(res *http.Response) error {
		return nil
	}

	logrus.AddHook(hook)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AfterFunc

type AfterFunc func(res *http.Response) error

type BeforeFunc

type BeforeFunc func(req *http.Request) error

type Hook

type Hook struct {

	// 方法在执行请求之前执行
	BeforePost BeforeFunc

	// 方法在执行请求后执行
	AfterPost AfterFunc
	// contains filtered or unexported fields
}

Log服务端点配置.

func New

func New(name, endpoint string, levels []logrus.Level) *Hook

New创建钩子类型的实例,指定产生钩子的应用程序的名称

func (Hook) Fire

func (h Hook) Fire(entry *logrus.Entry) error

Fire处理 HTTP POST请求

func (Hook) Levels

func (h Hook) Levels() []logrus.Level

Levels返回由该钩子处理的所有级别的一个片段

type Log

type Log struct {
	Level        string         `json:"level"`         // 日志级别:notice,warning,error
	Route        interface{}    `json:"route"`         // 请求地址, 可不传
	RequestParam datatypes.JSON `json:"request_param"` // 请求参数 json对象,可不传
	Record       string         `json:"record"`        // 日志内容
	BelongSystem string         `json:"belong_system"` // 所属系统,获取端点配置
}

Teamones Log日志格式

type RequestParamJson

type RequestParamJson struct {
	Data logrus.Fields `json:"data"` // 日志级别:notice,warning,error
}

Jump to

Keyboard shortcuts

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