代码拉取完成,页面将自动刷新
package lager
import (
"encoding/json"
)
//LogLevel is a user defined variable of type int
type LogLevel int
const (
//DEBUG is a constant of user defined type LogLevel
DEBUG LogLevel = iota
INFO
WARN
ERROR
FATAL
)
//FormatLogLevel is a function which returns string format of log level
func FormatLogLevel(x LogLevel) string {
var level string
switch x {
case DEBUG:
level = "DEBUG"
case INFO:
level = "INFO"
case WARN:
level = "WARN"
case ERROR:
level = "ERROR"
case FATAL:
level = "FATAL"
}
return level
}
//MarshalJSON is a function which returns data in JSON format
func (x LogLevel) MarshalJSON() ([]byte, error) {
// var level string
var level = FormatLogLevel(x)
return json.Marshal(level)
}
//Data is a map
type Data map[string]interface{}
//LogFormat is a struct which stores details about log
type LogFormat struct {
LogLevel LogLevel `json:"level"`
Timestamp string `json:"timestamp"`
File string `json:"file"`
Message string `json:"msg"`
Data Data `json:"data,omitempty"`
}
//ToJSON which converts data of log file in to JSON file
func (log LogFormat) ToJSON() ([]byte, error) {
return json.Marshal(log)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。