Documentation
¶
Index ¶
- Constants
- Variables
- func EnableTagFileRouter()
- func FeishuRobotDetail(msg string, appName ...string)
- func FlushAsyncHooks()
- func GetCurrentPath() string
- func LogInit(noConsole bool) io.Writer
- func LogInitRobot(noConsole, robot bool, appName string) io.Writer
- func LogInitWithDir(noConsole bool, appName string, logDir string, level logrus.Level, ...) io.Writer
- func LogInitWithLevel(noConsole bool, appName string, level logrus.Level) io.Writer
- func LogInitWithMaxBackup(noConsole bool, appName string, level logrus.Level, ...) io.Writer
- func LogInitWithName(noConsole bool, appName string) io.Writer
- func LogInitWithParam(noConsole bool, appName string, level logrus.Level, ...) io.Writer
- func LogrusInit(noConsole bool, appName, dir string, level logrus.Level, ...) io.Writer
- func MkLogdir(logPath string)
- func PanicHandler()
- func RegisterAsyncHook(hook *AsyncHook)
- func RequestJson(method string, url string, paramBody io.Reader, headerMap map[string]string)
- func SendRobotMessage(content string, talkType, ReceiverId, RobotId int)
- func SendToRobotMessage(appName, msg string, talkType, ReceiverId, RobotId int)
- func SetupSignalHandler()
- type AsyncHook
- type Formatter
- type MailAuthHook
- type MailHook
- type MessageParamIM
- type NewMessageParamIM
- type NewRobotTextMessageRequest
- type RobotLog
- type TagRouterHook
- type TenantAccessTokenBody
Constants ¶
const DefaultReserveDuration = time.Duration(72) * time.Hour
const DefaultRotationSize int64 = 20 * 1024 * 1024
Variables ¶
var ( GlobalReserveDuration = DefaultReserveDuration GlobalRotationSize int64 = DefaultRotationSize GlobalMaxBackups = 3 )
供扩展能力(如标签日志)复用的全局配置(由 LogrusInit 赋值)
var AppName string
var LogBaseDir string
LogBaseDir 保存日志的根目录(由 LogrusInit 赋值)
Functions ¶
func EnableTagFileRouter ¶ added in v1.6.6
func EnableTagFileRouter()
EnableTagFileRouter 启用 Tag 旁路写入能力 默认查找字段名 "tag",例如: log.WithField("tag", "order").Info("created") 开闭原则:不改变任何现有接口,由业务层在初始化后主动调用启用
func FeishuRobotDetail ¶ added in v1.4.1
func GetCurrentPath ¶ added in v1.5.1
func GetCurrentPath() string
获取当前执行文件的目录,但是IDE下获取当前工程目录。两者都需要兼容。
func LogInitRobot ¶ added in v1.4.0
本配置处理了三个日志输出,1. 控制台(二选一) 2. all.log 所有日志 (二选一) 3. log文件夹下面的分级日志(一定会输出) Deprecated
func LogInitWithDir ¶ added in v1.6.6
func LogInitWithLevel ¶ added in v1.5.3
func LogInitWithMaxBackup ¶ added in v1.6.4
func LogInitWithName ¶ added in v1.5.1
本配置处理了三个日志输出,1. 控制台(二选一) 2. all.log 所有日志 (二选一) 3. log文件夹下面的分级日志(一定会输出)
func LogInitWithParam ¶ added in v1.5.8
func LogrusInit ¶ added in v1.5.3
func LogrusInit(noConsole bool, appName, dir string, level logrus.Level, reserveDuration time.Duration, rotationSize int64, maxBackups int) io.Writer
支持日志存放位置
func MkLogdir ¶ added in v1.5.7
func MkLogdir(logPath string)
FIXME: 这里注意日志文件启动路径会不会随着脚本启动的时候执行目录不一样,日志文件存储也不一样。日志不是与可执行文件同一目录,而是与执行启动目录在一起。
func PanicHandler ¶ added in v1.4.0
func PanicHandler()
异常处理 https://blog.csdn.net/xia_xing/article/details/80597472
func RegisterAsyncHook ¶ added in v1.6.2
func RegisterAsyncHook(hook *AsyncHook)
RegisterAsyncHook 注册一个异步Hook以便程序退出时刷新
func RequestJson ¶ added in v1.3.8
func SendRobotMessage ¶ added in v1.3.8
func SendToRobotMessage ¶ added in v1.4.0
func SetupSignalHandler ¶ added in v1.6.2
func SetupSignalHandler()
SetupSignalHandler 设置信号处理程序,在程序退出前刷新日志
Types ¶
type AsyncHook ¶ added in v1.6.2
type AsyncHook struct {
// contains filtered or unexported fields
}
AsyncHook 是一个异步的logrus hook,用于避免日志写入阻塞主程序
func NewAsyncHook ¶ added in v1.6.2
NewAsyncHook 创建一个新的AsyncHook
type Formatter ¶
type Formatter struct { // FieldsOrder - default: fields sorted alphabetically FieldsOrder []string // TimestampFormat - default: time.StampMilli = "Jan _2 15:04:05.000" TimestampFormat string // HideKeys - show [fieldValue] instead of [fieldKey:fieldValue] HideKeys bool // NoColors - disable colors NoColors bool // NoFieldsColors - apply colors only to the level, default is level + fields NoFieldsColors bool // NoFieldsSpace - no space between fields NoFieldsSpace bool // ShowFullLevel - show a full level [WARNING] instead of [WARN] ShowFullLevel bool // NoUppercaseLevel - no upper case for level value NoUppercaseLevel bool // TrimMessages - trim whitespaces on messages TrimMessages bool // CallerFirst - print caller info first CallerFirst bool // CustomCallerFormatter - set custom formatter for caller info CustomCallerFormatter func(*runtime.Frame) string }
Formatter - logrus formatter, implements logrus.Formatter
type MailAuthHook ¶ added in v1.3.4
type MailAuthHook struct { AppName string Host string Port int From *mail.Address To *mail.Address Username string Password string }
MailAuthHook to sends logs by email with authentication.
func NewMailAuthHook ¶ added in v1.3.4
func NewMailAuthHook(appname string, host string, port int, from string, to string, username string, password string) (*MailAuthHook, error)
creates a hook to be added to an instance of logger.
func (*MailAuthHook) Fire ¶ added in v1.3.4
func (hook *MailAuthHook) Fire(entry *logrus.Entry) error
Fire is called when a log event is fired.
func (*MailAuthHook) Levels ¶ added in v1.3.4
func (hook *MailAuthHook) Levels() []logrus.Level
Levels returns the available logging levels.
type MailHook ¶ added in v1.3.4
type MailHook struct { AppName string // contains filtered or unexported fields }
MailHook to sends logs by email without authentication.
func NewMailHook ¶ added in v1.3.4
NewMailHook creates a hook to be added to an instance of logger.
type MessageParamIM ¶ added in v1.3.8
type MessageParamIM struct { TalkType int `form:"talk_type" json:"talk_type" binding:"required,oneof=1 2" label:"talk_type"` ReceiverId int `form:"receiver_id" json:"receiver_id" binding:"required,numeric,gt=0" label:"receiver_id"` Text string `form:"text" json:"text" binding:"required,max=3000" label:"text"` RobotId int `form:"robot_id" json:"robot_id" label:"robot_id"` }
type NewMessageParamIM ¶ added in v1.4.0
type NewMessageParamIM struct { Type string `json:"type"` //SenderId int `json:"sender_id"` // TODO 最好传过来,可以标记是极兔助手还是快码机器人。但是总体来说没啥关系。 Content string `json:"content"` QuoteId string `json:"quote_id"` Mentions []interface{} `json:"mentions"` Receiver struct { ReceiverId int `json:"receiver_id"` TalkType int `json:"talk_type"` } `json:"receiver"` }
type NewRobotTextMessageRequest ¶ added in v1.4.0
type NewRobotTextMessageRequest struct { NewMessageParamIM RobotId int `json:"robot_id"` }
type RobotLog ¶ added in v1.3.8
type RobotLog struct {
AppName string
}
func NewRobotLogger ¶ added in v1.3.8
type TagRouterHook ¶ added in v1.6.6
type TagRouterHook struct{}
TagRouterHook 根据 entry.Data["tag"] 将日志额外写入 tag 专属文件 注意:该 Hook 不改变原有日志流,只做“旁路”追加
func (*TagRouterHook) Fire ¶ added in v1.6.6
func (h *TagRouterHook) Fire(entry *logrus.Entry) error
func (*TagRouterHook) Levels ¶ added in v1.6.6
func (h *TagRouterHook) Levels() []logrus.Level
type TenantAccessTokenBody ¶ added in v1.4.1
type TenantAccessTokenBody struct { Code int `json:"code"` Expire int `json:"expire"` RequestTime time.Time Msg string `json:"msg"` TenantAccessToken string `json:"tenant_access_token"` }
var LatestToken TenantAccessTokenBody // 最新的token