wangpl_study/day06/mylogger_test/console.go

38 lines
611 B
Go
Raw Normal View History

2024-10-11 20:38:52 +08:00
package mylogger_test
import "fmt"
//logger 日志结构体
type Logger struct {
2024-10-15 20:05:52 +08:00
Level LogLevel
2024-10-11 20:38:52 +08:00
}
//Newlog 构造函数
2024-10-15 20:05:52 +08:00
func NewLog(levelStr string) Logger {
level,err :=parseLogLevel(levelStr)
if err !=nil{
panic(err)
}
return Logger{
Level:level,
}
2024-10-11 20:38:52 +08:00
}
func (l Logger) Debug(msg string) {
2024-10-15 20:05:52 +08:00
now :=time.Now()
fmt.Printf("[%s] %s" now.Format("2006-01-02 15:04:05"),msg)
2024-10-11 20:38:52 +08:00
}
func (l Logger) Info(msg string) {
2024-10-15 20:05:52 +08:00
fmt.Println(msg)
2024-10-11 20:38:52 +08:00
}
func (l Logger) Warning(msg string) {
fmt.Println(msg)
}
func (l Logger) Error(msg string) {
fmt.Println(msg)
}
func (l Logger) Fatal(msg string) {
fmt.Println(msg)
}