Documentation
¶
Index ¶
- Variables
- func CreateID() string
- type Ctx
- func (ctx *Ctx) Debug(s ...interface{}) *Ctx
- func (ctx *Ctx) Debugf(s string, args ...interface{}) *Ctx
- func (ctx *Ctx) Error(s ...interface{}) *Ctx
- func (ctx *Ctx) Errorf(s string, args ...interface{}) *Ctx
- func (ctx *Ctx) Fatal(s ...interface{}) *Ctx
- func (ctx *Ctx) Fatalf(s string, args ...interface{}) *Ctx
- func (ctx *Ctx) Fields(data interface{}) *Ctx
- func (ctx *Ctx) Free()
- func (ctx *Ctx) Info(s ...interface{}) *Ctx
- func (ctx *Ctx) Infof(s string, args ...interface{}) *Ctx
- func (ctx *Ctx) Print(s ...interface{})
- func (ctx *Ctx) Tag(tag string) *Ctx
- func (ctx *Ctx) Warn(s ...interface{}) *Ctx
- func (ctx *Ctx) Warnf(s string, args ...interface{}) *Ctx
- type Event
- type FormatWriter
- type Formater
- type Level
- type Logger
- func (o *Logger) Ctx(id string) *Ctx
- func (o *Logger) Debug(s ...interface{})
- func (o *Logger) Debugf(s string, args ...interface{})
- func (o *Logger) Error(s ...interface{})
- func (o *Logger) Errorf(s string, args ...interface{})
- func (o *Logger) Fatal(s ...interface{})
- func (o *Logger) Fatalf(s string, args ...interface{})
- func (o *Logger) Info(s ...interface{})
- func (o *Logger) Infof(s string, args ...interface{})
- func (o *Logger) Output(calldept int, level Level, acname, id, msg string, data interface{}) error
- func (o *Logger) Print(s ...interface{})
- func (o *Logger) SetSrvName(s string)
- func (o *Logger) Warn(s ...interface{})
- func (o *Logger) Warnf(s string, args ...interface{})
- func (o *Logger) Write(b []byte) (int, error)
Constants ¶
This section is empty.
Variables ¶
View Source
var FormatPattern = func(ev *Event) []byte { var pre string if ev.Action != "" || ev.ID != "" { pre = fmt.Sprintf("[%s] %s %s (%s#%s)-> ", ev.Timestamp, ev.Level, ev.File, ev.Action, ev.ID) } else { pre = fmt.Sprintf("[%s] %s %s-> ", ev.Timestamp, ev.Level, ev.File) } d := []byte(pre + ev.Message) if length := len(d); d[length-1] != '\n' { d = append(d, '\n') } if ev.Data != nil { d = append(d, "fields-> "...) databytes, _ := json.Marshal(ev.Data) d = append(d, databytes...) d = append(d, '\n') } return d }
FormatPattern 扁平化格式化日志事件
View Source
var TimestampLayout = "2006-01-02 15:04:05"
TimestampLayout 日志时间格式化模板
Functions ¶
Types ¶
type Ctx ¶
type Ctx struct {
// contains filtered or unexported fields
}
Ctx 携带日志id和事件名的日志对象 主要用于通过id串联一些日志 起到查询方便
type Event ¶
type Event struct { SrvName string `json:"service"` // 日志产生时的时间 Timestamp string `json:"timestamp"` // 日志等级 Level Level `json:"level"` // 所在文件行数file:line // main:20 File string `json:"file,omitempty"` // 日志id 只有Ctx方式才会使用 // 主要用于上下文关联 ID string `json:"guid,omitempty"` // 日志动作名称 描述干什么的 如 login,callback... Action string `json:"action,omitempty"` // 日志内容 Message string `json:"message"` // data Data interface{} `json:"data,omitempty"` }
Event 日志事件 记录了日志的必要信息 可以通过Formater接口输入格式化样式后的数据
type FormatWriter ¶
FormatWriter 格式化输入 用于定制日志输出内容的样式
type Level ¶
type Level int32
Level 日志级别类型
func (Level) MarshalJSON ¶
MarshalJSON 保证json编码level是不是显示数字而是string
Click to show internal directories.
Click to hide internal directories.