mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
disable auto adding temp directory to gview/gcfg search path; disable backtrace feature in normal log print with glog; fix issue caused by fmt.Fprintf in gfsnotify
This commit is contained in:
@ -76,7 +76,8 @@ func View(name...string) *gview.View {
|
||||
if path == "" {
|
||||
path = genv.Get("GF_VIEWPATH")
|
||||
if path == "" {
|
||||
if gfile.SelfDir() != gfile.TempDir() {
|
||||
// gfile.MainPkgPath() 用以判断是否开发环境
|
||||
if gfile.MainPkgPath() == "" {
|
||||
path = gfile.SelfDir()
|
||||
}
|
||||
}
|
||||
@ -105,7 +106,8 @@ func Config(file...string) *gcfg.Config {
|
||||
if path == "" {
|
||||
path = genv.Get("GF_CFGPATH")
|
||||
if path == "" {
|
||||
if gfile.SelfDir() != gfile.TempDir() {
|
||||
// gfile.MainPkgPath() 用以判断是否开发环境
|
||||
if gfile.MainPkgPath() == "" {
|
||||
path = gfile.SelfDir()
|
||||
}
|
||||
}
|
||||
|
||||
@ -257,7 +257,7 @@ func (s *Server) Start() error {
|
||||
}
|
||||
// 是否处于开发环境
|
||||
if gfile.MainPkgPath() != "" {
|
||||
glog.Backtrace(false, 0).Notice("GF notices that you're in develop environment, so error logs are auto enabled to stdout.")
|
||||
glog.Debug("GF notices that you're in develop environment, so error logs are auto enabled to stdout.")
|
||||
}
|
||||
|
||||
// 打印展示路由表
|
||||
|
||||
@ -34,7 +34,7 @@ func (w *Watcher) startWatchLoop() {
|
||||
}, REPEAT_EVENT_FILTER_INTERVAL)
|
||||
|
||||
case err := <- w.watcher.Errors:
|
||||
fmt.Fprintf(os.Stderr, "error: %s\n" + err.Error())
|
||||
fmt.Fprintf(os.Stderr, "[gfsnotify] error: %s\n", err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@ -11,6 +11,7 @@ package glog
|
||||
|
||||
import (
|
||||
"gitee.com/johng/gf/g/container/gtype"
|
||||
"gitee.com/johng/gf/g/os/gfile"
|
||||
"io"
|
||||
)
|
||||
|
||||
@ -32,6 +33,13 @@ var (
|
||||
logger = New()
|
||||
)
|
||||
|
||||
func init() {
|
||||
// 自动识别开发环境
|
||||
if gfile.MainPkgPath() != "" {
|
||||
logger.SetDebug(true)
|
||||
}
|
||||
}
|
||||
|
||||
// 日志日志目录绝对路径
|
||||
func SetPath(path string) {
|
||||
logger.SetPath(path)
|
||||
|
||||
@ -219,9 +219,6 @@ func (l *Logger) doStdLockPrint(std io.Writer, s string) {
|
||||
|
||||
// 核心打印数据方法(标准输出)
|
||||
func (l *Logger) stdPrint(s string) {
|
||||
if l.btStatus.Val() == 1 {
|
||||
s = l.appendBacktrace(s)
|
||||
}
|
||||
l.print(os.Stdout, s)
|
||||
}
|
||||
|
||||
@ -237,14 +234,18 @@ func (l *Logger) errPrint(s string) {
|
||||
}
|
||||
|
||||
// 输出内容中添加回溯信息
|
||||
func (l *Logger) appendBacktrace(s string) string {
|
||||
trace := l.GetBacktrace()
|
||||
func (l *Logger) appendBacktrace(s string, skip...int) string {
|
||||
trace := l.GetBacktrace(skip...)
|
||||
if trace != "" {
|
||||
backtrace := "Backtrace:" + ln + trace
|
||||
if s[len(s) - 1] == byte('\n') {
|
||||
s = s + backtrace + ln
|
||||
if len(s) > 0 {
|
||||
if s[len(s)-1] == byte('\n') {
|
||||
s = s + backtrace + ln
|
||||
} else {
|
||||
s = s + ln + backtrace + ln
|
||||
}
|
||||
} else {
|
||||
s = s + ln + backtrace + ln
|
||||
s = backtrace
|
||||
}
|
||||
}
|
||||
return s
|
||||
@ -252,7 +253,7 @@ func (l *Logger) appendBacktrace(s string) string {
|
||||
|
||||
// 直接打印回溯信息,参数skip表示调用端往上多少级开始回溯
|
||||
func (l *Logger) PrintBacktrace(skip...int) {
|
||||
l.Println(l.GetBacktrace(skip...))
|
||||
l.Println(l.appendBacktrace("", skip...))
|
||||
}
|
||||
|
||||
// 获取文件调用回溯字符串,参数skip表示调用端往上多少级开始回溯
|
||||
|
||||
@ -49,10 +49,12 @@ var viewObj *View
|
||||
// 初始化默认的视图对象
|
||||
func checkAndInitDefaultView() {
|
||||
if viewObj == nil {
|
||||
if gfile.SelfDir() != gfile.TempDir() {
|
||||
// gfile.MainPkgPath() 用以判断是否开发环境
|
||||
mainPkgPath := gfile.MainPkgPath()
|
||||
if gfile.MainPkgPath() == "" {
|
||||
viewObj = New(gfile.SelfDir())
|
||||
} else {
|
||||
viewObj = New()
|
||||
viewObj = New(mainPkgPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,13 +18,15 @@ import (
|
||||
// 断言判断
|
||||
func Assert(value, expect interface{}) {
|
||||
if gconv.String(value) != gconv.String(expect) {
|
||||
glog.Backtrace(true, 1).Printfln(`[ASSERT] VALUE: %v, EXPECT: %v`, value, expect)
|
||||
glog.Printfln(`[ASSERT] VALUE: %v, EXPECT: %v`, value, expect)
|
||||
glog.Header(false).PrintBacktrace(1)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// 提示错误并退出
|
||||
func Fatal(message...interface{}) {
|
||||
glog.Backtrace(true, 1).Println(`[FATAL] `, fmt.Sprint(message...))
|
||||
glog.Println(`[FATAL] `, fmt.Sprint(message...))
|
||||
glog.Header(false).PrintBacktrace(1)
|
||||
os.Exit(1)
|
||||
}
|
||||
@ -1,19 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitee.com/johng/gf/g"
|
||||
"gitee.com/johng/gf/g/util/gregex"
|
||||
)
|
||||
import "gitee.com/johng/gf/g/util/gtest"
|
||||
|
||||
func main() {
|
||||
//s := `1544180795 -- s_has_sess -- 41570504 -decryptSess- 41570504__iuVycRYg9qE3y7CsSgGZH1K2nxTdjPZN4fXot65zHIEmULO0Ow6LweJp5raWl8Ft -postSess- eyJpdiI6IkFwSWZ3eXFMcGxBZE5JcWF4aXh0M3c9PSIsInZhbHVlIjoiV3ZLeGduMnRoRkFZdmxHTzM5ZzdyU1JHWDMycmZlRERvNnFkaUR0SitlRjBrZnlYR1JvS2puTGZNUThSeFR0bWtlT3pza0l0elFqRk5mdXF6XC9FWWpWZnljVjdJbHd3dTRybEhldHZHTk5DQ015dlpYNHljNmxKMWJTRUVpY0E4IiwibWFjIjoiOTkxMzIxOTRhMGUxZWZiODM4NWZjNDZjYmVhNWY2NjhlZDZkNmVlNjY1MTE2N2VhZDAzYzY4NDJmZGFkMjY5YyJ9 -- 0 -- B8105CF2-1588-4753-9F86-9B8C36EB1842 -- iPhone 7 -- 12.1 -- 6.8.7 -- i -- 10.111.153.5 -- medlinker -- service -- unknown
|
||||
//`
|
||||
// s := `[08-Dec-2018 13:35:03 Asia/Shanghai] Medlinker\Services\Message\MessageService|updateUserInfo|用户头像 URI 不能为空 in /var/www/med-d2d/app/Services/Message/RongCloudService.php on line 851`
|
||||
s := `[2018-12-01 13:35:03 Asia/Shanghai] 1544180795 Medlinker\Services\Message\MessageService|updateUserInfo|用户头像 URI 不能为空 in /var/www/med-d2d/app/Services/Message/RongCloudService.php on line 851`
|
||||
//m, e := gregex.MatchString(`/var/log/medlinker/[\w\-\_]+/(.+?)/{0,1}[\d\-\_]*\.log`, `/var/log/medlinker/med-questionnaire/nginx/error/access-20181206.log`)
|
||||
//m, e := gregex.MatchString(`/var/log/medlinker/[\w\-\_]+/(.+?)/{0,1}[\d\-\_]*\.log`, `/var/log/medlinker/med-questionnaire/storagelogs/events/sqlLog/2018-12-06.log`)
|
||||
m, e := gregex.MatchString(`(.*?((\d{4}[-/\.]\d{2}[-/\.]\d{2}|\d{1,2}[-/\.][A-Za-z]{3,}[-/\.]\d{4})[:\sT-]*\d{0,2}:{0,1}\d{0,2}:{0,1}\d{0,2}\.{0,1}\d{0,9}[\sZ]{0,1}[\+-]{0,1}[:\d]*|\d{10}).+)`, s)
|
||||
fmt.Println(e)
|
||||
g.Dump(m)
|
||||
gtest.Assert(1, 2)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user