修复相关BUG + 增加单元测试, 覆盖率100%
This commit is contained in:
52
logger.go
52
logger.go
@ -9,15 +9,15 @@ package consts
|
||||
|
||||
type LogLevel string
|
||||
|
||||
func (ll *LogLevel) String() string {
|
||||
return string(*ll)
|
||||
func (ll LogLevel) String() string {
|
||||
return string(ll)
|
||||
}
|
||||
|
||||
func (ll *LogLevel) MarshalJSON() ([]byte, error) {
|
||||
return []byte(ll.String()), nil
|
||||
func (ll LogLevel) MarshalJSON() ([]byte, error) {
|
||||
return []byte(`"` + ll.String() + `"`), nil
|
||||
}
|
||||
|
||||
func (ll *LogLevel) IsValid() bool {
|
||||
func (ll LogLevel) IsValid() bool {
|
||||
levelList := []LogLevel{
|
||||
LogLevelDebug,
|
||||
LogLevelInfo,
|
||||
@ -26,14 +26,14 @@ func (ll *LogLevel) IsValid() bool {
|
||||
LogLevelPanic,
|
||||
}
|
||||
for _, level := range levelList {
|
||||
if level == *ll {
|
||||
if level == ll {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
const (
|
||||
LogLevelDebug LogLevel = "DEBUG"
|
||||
LogLevelInfo LogLevel = "INFO"
|
||||
LogLevelWarn LogLevel = "WARN"
|
||||
@ -47,18 +47,12 @@ func (ls LogSplit) String() string {
|
||||
return string(ls)
|
||||
}
|
||||
func (ls LogSplit) MarshalJSON() ([]byte, error) {
|
||||
return []byte(ls.String()), nil
|
||||
return []byte(`"` + ls.String() + `"`), nil
|
||||
}
|
||||
|
||||
func (ls LogSplit) IsValid() bool {
|
||||
supportSplitList := []LogSplit{
|
||||
LogSplitHour,
|
||||
LogSplitDay,
|
||||
LogSplitMonth,
|
||||
LogSplitYear,
|
||||
}
|
||||
for _, supportSplit := range supportSplitList {
|
||||
if supportSplit == ls {
|
||||
for _, supportSplit := range SupportLogSplitList {
|
||||
if supportSplit.Value == ls || supportSplit.Value.String() == ls.String() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -72,6 +66,32 @@ const (
|
||||
LogSplitYear LogSplit = "YEAR"
|
||||
)
|
||||
|
||||
type LogSplitDesc struct {
|
||||
Value LogSplit `json:"value"`
|
||||
Desc string `json:"desc"`
|
||||
}
|
||||
|
||||
var (
|
||||
SupportLogSplitList = []LogSplitDesc{
|
||||
{
|
||||
Value: LogSplitHour,
|
||||
Desc: "按小时切割",
|
||||
},
|
||||
{
|
||||
Value: LogSplitDay,
|
||||
Desc: "按天切割",
|
||||
},
|
||||
{
|
||||
Value: LogSplitMonth,
|
||||
Desc: "按月切割",
|
||||
},
|
||||
{
|
||||
Value: LogSplitYear,
|
||||
Desc: "按年切割",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
LogPathDefault = "logs"
|
||||
)
|
||||
|
Reference in New Issue
Block a user