Documentation
¶
Index ¶
- Constants
- Variables
- func AddHook(hooks ...logrus.Hook)
- func Debug(args ...any)
- func Debugf(args ...any)
- func Debugln(args ...any)
- func Error(args ...any)
- func Errorf(args ...any)
- func Errorln(args ...any)
- func Fatal(args ...any)
- func Fatalf(args ...any)
- func Fatalln(args ...any)
- func FmtString(i any) string
- func GetStructFields(st any) (fields map[string]any, err error)
- func Info(args ...any)
- func Infof(args ...any)
- func Infoln(args ...any)
- func Init(level string, organizeLog, reportCaller bool, out io.Writer, tags ...TagGetter)
- func JsonString(r any) string
- func Panic(args ...any)
- func Panicf(args ...any)
- func Panicln(args ...any)
- func Print(args ...any)
- func Printf(args ...any)
- func Println(args ...any)
- func ProtoToPrintString(p proto.Message) string
- func String(i any) fmt.Stringer
- func StructToString(p any) string
- func Trace(args ...any)
- func Tracef(args ...any)
- func Traceln(args ...any)
- func Warn(args ...any)
- func Warnf(args ...any)
- func Warning(args ...any)
- func Warningf(args ...any)
- func Warningln(args ...any)
- func Warnln(args ...any)
- type DealStringHookFunc
- type DefaultLogTag
- type FieldMap
- type Formatter
- type HandlerFormatFile
- type HandlerFormatFunc
- type Hook
- type JSONFormatter
- type Level
- type TagGetter
- type TagSourceFormatter
- type TextFormatter
- func (f *TextFormatter) Format(entry *logrus.Entry) ([]byte, error)
- func (f *TextFormatter) FormatHook(hook *Hook) ([]byte, error)
- func (f *TextFormatter) RegisterFields(args ...string)
- func (f *TextFormatter) SetFormat(msgFmts ...string)
- func (f *TextFormatter) SetFormatAndTagSource(sourceFmt TagSourceFormatter, msgFmts ...string)
Constants ¶
const ( FieldKeyMsg = logrus.FieldKeyMsg FieldKeyLevel = logrus.FieldKeyLevel FieldKeyTime = logrus.FieldKeyTime FieldKeyLogrusError = logrus.FieldKeyLogrusError FieldKeyFunc = logrus.FieldKeyFunc FieldKeyFile = logrus.FieldKeyFile FieldKeyLine = "line" TagBL = "[" TagBR = "]" TagColon = ":" TagVBar = "|" )
Variables ¶
var ( // PrintProtoLen 设置打印pb报文的长度,超过这个长度将会对报文中的超长字段进行处理(截断) PrintProtoLen = 1024 // PrintStringLen 设置打印报文中字符串的长度,超过这个长度将会对报文中的超长字段进行处理(截断) PrintStringLen = 64 // PrintSliceLen 设置打印报文中的slice或者array的长度,超过这个长度将会对报文中的超长内容进行处理(截断) PrintSliceLen = 64 // 处理string的方式,默认截断后面补上 "..." DealStringHook DealStringHookFunc = getStringSlice )
var ( FunctionNameLength = 25 FileNameLength = 20 )
var (
AddedHooks []logrus.Hook
)
Functions ¶
func GetStructFields ¶
GetStructFields 把结构体转换成一个map
func Init ¶
对日志初始化,参数如下: level :设置日志级别, 方便从配置文件中直接获取,所以使用string organizeLog :是否整理日志, 本地调试或者不需要收集时建议true, 配合OrganizeLogMiddleware 使用 reportCaller :是否打印函数调用栈 out :日志打印到何处 tags :设置日志中获取上下文的接口
func ProtoToPrintString ¶
ProtoToPrintString pb协议转换成可打印的json string,会对超长内容截断
func String ¶
use this
String 入参换成可打印的json string,包括protobuf和普通结构体,或者其他类型 返回 fmt.Stringer, 防止日志级别不够时,还执行这个很消耗资源的操作
func StructToString ¶
StructToPrintString 结构体转换成可打印的json string,会对超长内容截断
Types ¶
type DealStringHookFunc ¶
type DefaultLogTag ¶
type DefaultLogTag struct {
}
type FieldMap ¶
type FieldMap map[fieldKey]string
FieldMap allows customization of the key names for default fields.
type HandlerFormatFile ¶
HandlerFormatFile format file name
type HandlerFormatFunc ¶
HandlerFormatFunc format function name
type Hook ¶
type Hook struct {
ReportCaller bool
Formatter Formatter
Out io.Writer
// Contains all the fields set by the user.
Data logrus.Fields
// Time at which the log entry was created
Time time.Time
// Level the log entry was logged at: Trace, Debug, Info, Warn, Error, Fatal or Panic
// This field will be set on entry firing and the value will be equal to the one in Logger struct field.
Level logrus.Level
// Calling method, with package name
Caller *runtime.Frame
// Message passed to Trace, Debug, Info, Warn, Error, Fatal or Panic
Message string
// Contains the context set by the user. Useful for hook processing etc.
Context context.Context
// When formatter is called in entry.log(), a Buffer may be set to entry
Buffer *bytes.Buffer
// contains filtered or unexported fields
}
goroutine unsafe, 里面的变量只能在初始化时赋值 Hook hook for log
type JSONFormatter ¶
type JSONFormatter struct {
// TagGetter implement this to get all tag you want, like traceid , requestid etc...
TagGetters []TagGetter
// TimestampFormat sets the format used for marshaling timestamps.
TimestampFormat string
// DisableTimestamp allows disabling automatic timestamps in output
DisableTimestamp bool
// DisableHTMLEscape allows disabling html escaping in output
DisableHTMLEscape bool
// DataKey allows users to put all the log entry parameters into a nested dictionary at a given key.
DataKey string
// FieldMap allows users to customize the names of keys for default fields.
// As an example:
// formatter := &JSONFormatter{
// FieldMap: FieldMap{
// FieldKeyTime: "@timestamp",
// FieldKeyLevel: "@level",
// FieldKeyMsg: "@message",
// FieldKeyFunc: "@caller",
// },
// }
FieldMap FieldMap
// CallerPrettyfier can be set by the user to modify the content
// of the function and file keys in the json data when ReportCaller is
// activated. If any of the returned value is the empty string the
// corresponding key will be removed from json fields.
CallerPrettyfier func(*runtime.Frame) (function string, file string)
// PrettyPrint will indent all json logs
PrettyPrint bool
}
JSONFormatter formats logs into parsable json
var ( LogFileNameLen = 40 JsonFormatter *JSONFormatter )
func (*JSONFormatter) FormatHook ¶
func (f *JSONFormatter) FormatHook(entry *Hook) ([]byte, error)
Format renders a single log entry
type Level ¶
func (Level) MarshalText ¶
type TagSourceFormatter ¶
type TextFormatter ¶
type TextFormatter struct {
// TagGetter implement this to get all tag you want, like traceid , requestid etc...
TagGetters []TagGetter
// TimestampFormat to use for display when a full timestamp is printed
TimestampFormat string
// QuoteEmptyFields will wrap empty fields in quotes if true
QuoteEmptyFields bool
NoQuoteFields bool
FormatFuncName HandlerFormatFunc
FormatFileName HandlerFormatFile
TagSource bool
FieldKeys []string
TagSourceFormatter
// contains filtered or unexported fields
}
TextFormatter formats logs into text
var ( StdFormatter *TextFormatter SimpleFormatter *TextFormatter SingleLineFormatter *TextFormatter )
func (*TextFormatter) FormatHook ¶
func (f *TextFormatter) FormatHook(hook *Hook) ([]byte, error)
nolint
func (*TextFormatter) RegisterFields ¶
func (f *TextFormatter) RegisterFields(args ...string)
func (*TextFormatter) SetFormat ¶
func (f *TextFormatter) SetFormat(msgFmts ...string)
func (*TextFormatter) SetFormatAndTagSource ¶
func (f *TextFormatter) SetFormatAndTagSource(sourceFmt TagSourceFormatter, msgFmts ...string)