Ai
1 Star 0 Fork 0

simplexyz/simplego

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
console.go 1.73 KB
一键复制 编辑 原始数据 按行查看 历史
李文建 提交于 2023-11-04 19:00 +08:00 . 持续完善
package log
import (
"fmt"
"log"
"os"
"sync/atomic"
)
type consoleLogger struct {
level atomic.Int32
logger *log.Logger
}
func CreateConsoleLogger() ILogger {
l := &consoleLogger{
logger: log.New(os.Stdout, "", log.LstdFlags),
}
l.level.Store(int32(LevelDebug))
return l
}
func (l *consoleLogger) Destroy() {
}
func (l *consoleLogger) SetLevel(level Level) {
l.level.Store(int32(level))
}
func (l *consoleLogger) Debug(args ...interface{}) {
if LevelDebug > Level(l.level.Load()) {
return
}
l.logger.Printf("[D] %s\n", fmt.Sprint(args...))
}
func (l *consoleLogger) Debugf(format string, args ...interface{}) {
if LevelDebug > Level(l.level.Load()) {
return
}
l.logger.Printf("[D] %s\n", fmt.Sprintf(format, args...))
}
func (l *consoleLogger) Info(args ...interface{}) {
if LevelInfo > Level(l.level.Load()) {
return
}
l.logger.Printf("[I] %s\n", fmt.Sprint(args...))
}
func (l *consoleLogger) Infof(format string, args ...interface{}) {
if LevelInfo > Level(l.level.Load()) {
return
}
l.logger.Printf("[I] %s\n", fmt.Sprintf(format, args...))
}
func (l *consoleLogger) Warn(args ...interface{}) {
if LevelWarn > Level(l.level.Load()) {
return
}
l.logger.Printf("[W] %s\n", fmt.Sprint(args...))
}
func (l *consoleLogger) Warnf(format string, args ...interface{}) {
if LevelWarn > Level(l.level.Load()) {
return
}
l.logger.Printf("[W] %s\n", fmt.Sprintf(format, args...))
}
func (l *consoleLogger) Error(args ...interface{}) {
if LevelError > Level(l.level.Load()) {
return
}
l.logger.Printf("[E] %s\n", fmt.Sprint(args...))
}
func (l *consoleLogger) Errorf(format string, args ...interface{}) {
if LevelError > Level(l.level.Load()) {
return
}
l.logger.Printf("[E] %s\n", fmt.Sprintf(format, args...))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/simplexyz/simplego.git
git@gitee.com:simplexyz/simplego.git
simplexyz
simplego
simplego
d62e3dcece80

搜索帮助