1 Star 0 Fork 0

micro-tools / wf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
intlog.go 2.12 KB
一键复制 编辑 原始数据 按行查看 历史
545403892 提交于 2023-09-27 22:16 . 升级go-ole
// Package intlog provides internal logging for GoFrame development usage only.
package intlog
import (
"fmt"
"gitee.com/micro-tools/wf/debug/gdebug"
"gitee.com/micro-tools/wf/internal/utils"
"path/filepath"
"time"
)
const (
stackFilterKey = "/internal/intlog"
)
var (
// isGFDebug marks whether printing GoFrame debug information.
isGFDebug = false
)
func init() {
isGFDebug = utils.IsDebugEnabled()
}
// SetEnabled enables/disables the internal logging manually.
// Note that this function is not concurrent safe, be aware of the DATA RACE.
func SetEnabled(enabled bool) {
// If they're the same, it does not write the `isGFDebug` but only reading operation.
if isGFDebug != enabled {
isGFDebug = enabled
}
}
// Print prints `v` with newline using fmt.Println.
// The parameter `v` can be multiple variables.
func Print(v ...interface{}) {
if !isGFDebug {
return
}
fmt.Println(append([]interface{}{now(), "[INTE]", file()}, v...)...)
}
// Printf prints `v` with format `format` using fmt.Printf.
// The parameter `v` can be multiple variables.
func Printf(format string, v ...interface{}) {
if !isGFDebug {
return
}
fmt.Printf(now()+" [INTE] "+file()+" "+format+"\n", v...)
}
// Error prints `v` with newline using fmt.Println.
// The parameter `v` can be multiple variables.
func Error(v ...interface{}) {
if !isGFDebug {
return
}
array := append([]interface{}{now(), "[INTE]", file()}, v...)
array = append(array, "\n"+gdebug.StackWithFilter(stackFilterKey))
fmt.Println(array...)
}
// Errorf prints `v` with format `format` using fmt.Printf.
func Errorf(format string, v ...interface{}) {
if !isGFDebug {
return
}
fmt.Printf(
now()+" [INTE] "+file()+" "+format+"\n%s\n",
append(v, gdebug.StackWithFilter(stackFilterKey))...,
)
}
// now returns current time string.
func now() string {
return time.Now().Format("2006-01-02 15:04:05.000")
}
// file returns caller file name along with its line number.
func file() string {
_, p, l := gdebug.CallerWithFilter(stackFilterKey)
return fmt.Sprintf(`%s:%d`, filepath.Base(p), l)
}
Go
1
https://gitee.com/micro-tools/wf.git
git@gitee.com:micro-tools/wf.git
micro-tools
wf
wf
v1.0.2

搜索帮助