1 Star 0 Fork 0

newlife/gnatsd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
log.go 1.81 KB
一键复制 编辑 原始数据 按行查看 历史
Derek Collison 提交于 2015-06-16 12:48 . race fixes, tests
// Copyright 2012-2015 Apcera Inc. All rights reserved.
package server
import (
"sync"
"sync/atomic"
)
// Package globals for performance checks
var trace int32
var debug int32
var log = struct {
sync.Mutex
logger Logger
}{}
type Logger interface {
Noticef(format string, v ...interface{})
Fatalf(format string, v ...interface{})
Errorf(format string, v ...interface{})
Debugf(format string, v ...interface{})
Tracef(format string, v ...interface{})
}
func (s *Server) SetLogger(logger Logger, debugFlag, traceFlag bool) {
if debugFlag {
atomic.StoreInt32(&debug, 1)
}
if traceFlag {
atomic.StoreInt32(&trace, 1)
}
log.Lock()
log.logger = logger
log.Unlock()
}
func Noticef(format string, v ...interface{}) {
executeLogCall(func(logger Logger, format string, v ...interface{}) {
logger.Noticef(format, v...)
}, format, v...)
}
func Errorf(format string, v ...interface{}) {
executeLogCall(func(logger Logger, format string, v ...interface{}) {
logger.Errorf(format, v...)
}, format, v...)
}
func Fatalf(format string, v ...interface{}) {
executeLogCall(func(logger Logger, format string, v ...interface{}) {
logger.Fatalf(format, v...)
}, format, v...)
}
func Debugf(format string, v ...interface{}) {
if atomic.LoadInt32(&debug) == 0 {
return
}
executeLogCall(func(logger Logger, format string, v ...interface{}) {
logger.Debugf(format, v...)
}, format, v...)
}
func Tracef(format string, v ...interface{}) {
if atomic.LoadInt32(&trace) == 0 {
return
}
executeLogCall(func(logger Logger, format string, v ...interface{}) {
logger.Tracef(format, v...)
}, format, v...)
}
func executeLogCall(f func(logger Logger, format string, v ...interface{}), format string, args ...interface{}) {
log.Lock()
defer log.Unlock()
if log.logger == nil {
return
}
f(log.logger, format, args...)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/newlife/gnatsd.git
git@gitee.com:newlife/gnatsd.git
newlife
gnatsd
gnatsd
v0.6.2

搜索帮助

0d507c66 1850385 C8b1a773 1850385