1 Star 0 Fork 0

白菜林 / go-log

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
models.go 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
白菜林 提交于 2019-08-04 18:30 . go log
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)
}
Go
1
https://gitee.com/lyhuilin/log.git
git@gitee.com:lyhuilin/log.git
lyhuilin
log
go-log
v0.0.1

搜索帮助

53164aa7 5694891 3bd8fe86 5694891