logger

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

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

Go to latest
Published: Apr 8, 2021 License: Apache-2.0 Imports: 14 Imported by: 3

README

说明

GIN + ENT/SQLX + CASBIN + WIRE + I18N

为了保持系统精简性(目前数据库处理只使用SQLX), 暂时移除了ENT相关的内容, 结构暂时保留

Documentation

Index

Constants

View Source
const (
	TraceIDKey   = "trace_id"
	UserIDKey    = "user_id"
	RoleIDKey    = "role_id"
	VersionKey   = "version"
	HostnameKey  = "hostname"
	ClientIPKey  = "clientip"
	StackKey     = "stack"
	LogVerKey    = "@version"
	NamespaceKey = "@namespace"
)

定义键名

View Source
const (
	KeyUserInfo = prefix + ":user-info"
	KeyTraceID  = prefix + ":tract-id"
)

定义上下文中的键

Variables

View Source
var (
	// ShowShortName 显示短的名字
	ShowShortName = true
)

Functions

func AddHook

func AddHook(hook Hook)

AddHook 增加日志钩子

func Debugf

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

Debugf 写入调试日志

func ErrorStack

func ErrorStack(ctx context.Context, err error)

ErrorStack 输出错误栈

func ErrorWW

func ErrorWW(err error) string

ErrorWW 输出异常 Error with where

func Errorf

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

Errorf 写入错误日志

func Fatalf

func Fatalf(ctx context.Context, format string, args ...interface{})

Fatalf 写入重大错误日志

func GetTraceCIP

func GetTraceCIP(ctx context.Context) string

GetTraceCIP 从上下文中获取用户ID

func GetTraceID

func GetTraceID(ctx context.Context) string

GetTraceID 从上下文中获取跟踪ID

func GetTraceUID

func GetTraceUID(ctx context.Context) string

GetTraceUID 从上下文中获取用户ID

func Infof

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

Infof 写入消息日志

func InitLogger

func InitLogger(ctx context.Context) (func(), error)

InitLogger 初始化日志模块

func Printf

func Printf(ctx context.Context, format string, args ...interface{})

Printf 写入消息日志

func SetFormatter

func SetFormatter(format string)

SetFormatter 设定日志输出格式

func SetLevel

func SetLevel(level string)

SetLevel 设定日志级别

func SetOutput

func SetOutput(out io.Writer)

SetOutput 设定日志输出

func SetVersion

func SetVersion(v string)

SetVersion 设定版本

func Stack

func Stack(skip int) []byte

Stack returns a nicely formatted stack frame, skipping skip frames.

func Stack2

func Stack2(skip int, max int) []byte

Stack2 returns a nicely formatted stack frame, skipping skip frames.

func Stack3

func Stack3(skip, max int, short bool) []byte

Stack3 returns a nicely formatted stack frame, skipping skip frames.

func Warnf

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

Warnf 写入警告日志

func Whereis

func Whereis(short bool) []byte

Whereis where is

Types

type ContextTrace

type ContextTrace interface {
	GetTraceID() string
	GetTraceCIP() string
	GetTraceUID() string
}

ContextTrace ...

type Entry

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

Entry 定义统一的日志写入方式

func StartTrace

func StartTrace(ctx context.Context) *Entry

StartTrace 开始一个追踪单元

func (*Entry) Debugf

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

Debugf 写入调试日志

func (*Entry) Errorf

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

Errorf 错误日志

func (*Entry) Fatalf

func (e *Entry) Fatalf(format string, args ...interface{})

Fatalf 重大错误日志

func (*Entry) Infof

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

Infof 消息日志

func (*Entry) Printf

func (e *Entry) Printf(format string, args ...interface{})

Printf 消息日志

func (*Entry) Warnf

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

Warnf 警告日志

func (*Entry) WithField

func (e *Entry) WithField(key string, value interface{}) *Entry

WithField 结构化字段写入

func (*Entry) WithFields

func (e *Entry) WithFields(fields map[string]interface{}) *Entry

WithFields 结构化字段写入

type Hook

type Hook = logrus.Hook

Hook 定义日志钩子别名

type Logger

type Logger = logrus.Logger

Logger 定义日志别名

func StandardLogger

func StandardLogger() *Logger

StandardLogger 获取标准日志

Jump to

Keyboard shortcuts

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