consts/logger.go

130 lines
2.6 KiB
Go

// Package consts ...
//
// Description : consts ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-06-24 15:46
package consts
type LogLevel string
func (ll LogLevel) String() string {
return string(ll)
}
func (ll LogLevel) MarshalJSON() ([]byte, error) {
return []byte(`"` + ll.String() + `"`), nil
}
func (ll LogLevel) IsValid() bool {
levelList := []LogLevel{
LogLevelDebug,
LogLevelInfo,
LogLevelWarn,
LogLevelError,
LogLevelPanic,
}
for _, level := range levelList {
if level == ll {
return true
}
}
return false
}
const (
LogLevelDebug LogLevel = "DEBUG"
LogLevelInfo LogLevel = "INFO"
LogLevelWarn LogLevel = "WARN"
LogLevelError LogLevel = "ERROR"
LogLevelPanic LogLevel = "PANIC"
)
type LogSplit string
func (ls LogSplit) String() string {
return string(ls)
}
func (ls LogSplit) MarshalJSON() ([]byte, error) {
return []byte(`"` + ls.String() + `"`), nil
}
func (ls LogSplit) IsValid() bool {
for _, supportSplit := range SupportLogSplitList {
if supportSplit.Value == ls || supportSplit.Value.String() == ls.String() {
return true
}
}
return false
}
const (
LogSplitHour LogSplit = "HOUR"
LogSplitDay LogSplit = "DAY"
LogSplitMonth LogSplit = "MONTH"
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"
)
const (
LogMessageKey = "message"
LogLevelKey = "level"
LogTimeKey = "time"
LogCallerKey = "caller"
)
const (
LogAccessName = "access.log"
LogRequestName = "request.log"
LogProxyName = "proxy.log"
LogBusinessName = "business.log"
LogMonitorName = "monitor.log"
LogDatabaseName = "database.log"
LogRateLimitName = "rate-limit.log"
LogEventName = "event.log"
LogCacheName = "cache.log"
)
const (
LogTypeAccess = "access" // 访问日志
LogTypeRequest = "request" // 请求日志
LogTypeOutput = "output" // 响应日志
LogTypeProxy = "proxy" // 代理请求日志
LogTypeBusiness = "business" // 业务日志
LogTypeMonitor = "monitor" // 监控日志
LogTypeDatabase = "database" // 数据库日志
LogTypeRateLimit = "rate-limit" // 流控日志
LogTypeEvent = "event" // 事件日志
LogTypeCache = "cache" // 缓存日志
)