logger

package module
v0.0.0-...-ac297d4 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: MIT Imports: 16 Imported by: 0

README

使用方法

中间件

conn, err := logger.NewConnection(
    config.Viper.GetStringSlice("KAFKA_SERVER"),
    config.Viper.GetString("KAFKA_TOPIC_CALLCHAIN"),
    0,
)
// 用户信息需在前一中间件中写入gin.Context
// 如 c.Set("user-info", "用户ID-用户名")
if err == nil {
    defer conn.Close()
    g.Use(logger.SetLogger(
        conn,
        logger.ConfigAppid(viper.GetString("KAFKA_LOG_APP_ID")),
        logger.ConfigEnvtype(viper.GetString("KAFKA_LOG_ENV_TYPE")),
        logger.ConfigLogname(viper.GetString("KAFKA_LOG_CALLCHAIN_NAME")),
        logger.ConfigLogthread(viper.GetString("KAFKA_LOG_THREAD")),
        logger.ConfigPort(strings.Trim(viper.GetString("RESTFUL_PORT"), ":")),
        logger.ConfigWithBody(viper.GetBool("KAFKA_LOG_BODY")),
    ))
}

应用日志

conn, err := logger.NewConnection(
    config.Viper.GetStringSlice("KAFKA_SERVER"),
    config.Viper.GetString("KAFKA_TOPIC_INNER"),
    0,
)
if err == nil {
	logger.LogInner(c, conn,
		logger.WithAppid(viper.GetString("KAFKA_LOG_APP_ID")),
		logger.WithEnvtype(viper.GetString("KAFKA_LOG_ENV_TYPE")),
		logger.WithLogname(viper.GetString("KAFKA_LOG_INNER_NAME")),
		logger.WithLogthread(viper.GetString("KAFKA_LOG_THREAD")),
		logger.WithPort(strings.Trim(viper.GetString("RESTFUL_PORT"), ":")),
		// logger.WithUser("123-456"),
		// logger.WithThrowable("dddddd"),
		logger.WithLevel("INFO"),
		logger.WithLogKey("key"),
		logger.WithLogMsg("msg"),
    )
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogInner

func LogInner(conn *Connection, fds ...Field) error

LogInner 应用日志

func SetLogger

func SetLogger(conn *Connection, configs ...Config) gin.HandlerFunc

SetLogger initializes the logging middleware.

Types

type Config

type Config interface {
	// contains filtered or unexported methods
}

Config 配置

func ConfigAppid

func ConfigAppid(appid string) Config

ConfigAppid 应用

func ConfigCspanidHeader

func ConfigCspanidHeader(cspanidHeader string) Config

ConfigCspanidHeader 调用链header

func ConfigEnvtype

func ConfigEnvtype(envtype string) Config

ConfigEnvtype 环境

func ConfigExceptPrefix

func ConfigExceptPrefix(exceptPrefix []string) Config

ConfigExceptPrefix 排除路径

func ConfigLogname

func ConfigLogname(logname string) Config

ConfigLogname 日志名

func ConfigLogthread

func ConfigLogthread(logthread string) Config

ConfigLogthread 日志进程

func ConfigPort

func ConfigPort(port string) Config

ConfigPort 端口

func ConfigPspanidHeader

func ConfigPspanidHeader(pspanidHeader string) Config

ConfigPspanidHeader 调用链header

func ConfigRequestidHeader

func ConfigRequestidHeader(requestidHeader string) Config

ConfigRequestidHeader 调用链header

func ConfigUseridHeader

func ConfigUseridHeader(useridHeader string) Config

ConfigUseridHeader 调用链header

func ConfigWithBody

func ConfigWithBody(withBody bool) Config

ConfigWithBody 记录请求内容

type Connection

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

Connection 连接

func NewConnection

func NewConnection(servers []string, topic string) (*Connection, error)

NewConnection 连接kafka

func (*Connection) Close

func (conn *Connection) Close() error

Close 关闭连接

func (*Connection) Reload

func (conn *Connection) Reload() error

Reload 重新连接

type Field

type Field interface {
	// contains filtered or unexported methods
}

Field 字段值

func WithAppid

func WithAppid(appid string) Field

WithAppid 应用

func WithCtx

func WithCtx(ctx *gin.Context) Field

WithCtx Gin上下文

func WithEnvtype

func WithEnvtype(envtype string) Field

WithEnvtype 环境

func WithLevel

func WithLevel(level string) Field

WithLevel 日志级别

func WithLogKey

func WithLogKey(key string) Field

WithLogKey 日志关键字

func WithLogMsg

func WithLogMsg(logmsg string) Field

WithLogMsg 日志内容

func WithLogname

func WithLogname(logname string) Field

WithLogname 日志名

func WithLogthread

func WithLogthread(logthread string) Field

WithLogthread 日志进程

func WithPort

func WithPort(port string) Field

WithPort 端口

func WithRequestidHeader

func WithRequestidHeader(requestidHeader string) Field

WithRequestidHeader 用户 ID-Name

func WithThrowable

func WithThrowable(throwable string) Field

WithThrowable 异常堆栈

func WithUser

func WithUser(user string) Field

WithUser 用户 ID-Name

Jump to

Keyboard shortcuts

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