mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
add more inernal logging points for core components
This commit is contained in:
@ -1,13 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/util/grand"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := "我爱GoFrame"
|
||||
for i := 0; i <= 10; i++ {
|
||||
fmt.Println(grand.Str(s, 10))
|
||||
}
|
||||
g.Cfg().Dump()
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ package gdb
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -35,6 +36,7 @@ func (db *dbMssql) Open(config *ConfigNode) (*sql.DB, error) {
|
||||
config.User, config.Pass, config.Host, config.Port, config.Name,
|
||||
)
|
||||
}
|
||||
intlog.Printf("Open: %s", source)
|
||||
if db, err := sql.Open("sqlserver", source); err == nil {
|
||||
return db, nil
|
||||
} else {
|
||||
|
||||
@ -9,6 +9,7 @@ package gdb
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
|
||||
_ "github.com/gf-third/mysql"
|
||||
)
|
||||
@ -28,6 +29,7 @@ func (db *dbMysql) Open(config *ConfigNode) (*sql.DB, error) {
|
||||
config.User, config.Pass, config.Host, config.Port, config.Name, config.Charset,
|
||||
)
|
||||
}
|
||||
intlog.Printf("Open: %s", source)
|
||||
if db, err := sql.Open("gf-mysql", source); err == nil {
|
||||
return db, nil
|
||||
} else {
|
||||
|
||||
@ -15,6 +15,7 @@ import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
"reflect"
|
||||
"strconv"
|
||||
@ -39,6 +40,7 @@ func (db *dbOracle) Open(config *ConfigNode) (*sql.DB, error) {
|
||||
} else {
|
||||
source = fmt.Sprintf("%s/%s@%s", config.User, config.Pass, config.Name)
|
||||
}
|
||||
intlog.Printf("Open: %s", source)
|
||||
if db, err := sql.Open("oci8", source); err == nil {
|
||||
return db, nil
|
||||
} else {
|
||||
|
||||
@ -14,6 +14,7 @@ package gdb
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
"strings"
|
||||
|
||||
@ -34,6 +35,7 @@ func (db *dbPgsql) Open(config *ConfigNode) (*sql.DB, error) {
|
||||
config.User, config.Pass, config.Host, config.Port, config.Name,
|
||||
)
|
||||
}
|
||||
intlog.Printf("Open: %s", source)
|
||||
if db, err := sql.Open("postgres", source); err == nil {
|
||||
return db, nil
|
||||
} else {
|
||||
|
||||
@ -12,6 +12,7 @@ package gdb
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
)
|
||||
|
||||
@ -26,6 +27,7 @@ func (db *dbSqlite) Open(config *ConfigNode) (*sql.DB, error) {
|
||||
} else {
|
||||
source = config.Name
|
||||
}
|
||||
intlog.Printf("Open: %s", source)
|
||||
if db, err := sql.Open("sqlite3", source); err == nil {
|
||||
return db, nil
|
||||
} else {
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
package gredis
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
@ -36,6 +37,8 @@ func SetConfig(config Config, name ...string) {
|
||||
}
|
||||
configs.Set(group, config)
|
||||
instances.Remove(group)
|
||||
|
||||
intlog.Printf(`SetConfig for group "%s": %+v`, group, config)
|
||||
}
|
||||
|
||||
// SetConfigByStr sets the global configuration for specified group with string.
|
||||
@ -76,6 +79,8 @@ func RemoveConfig(name ...string) {
|
||||
}
|
||||
configs.Remove(group)
|
||||
instances.Remove(group)
|
||||
|
||||
intlog.Printf(`RemoveConfig: %s`, group)
|
||||
}
|
||||
|
||||
// ConfigFromStr parses and returns config from given str.
|
||||
|
||||
@ -11,17 +11,17 @@ import (
|
||||
"github.com/gogf/gf/net/ghttp"
|
||||
)
|
||||
|
||||
// 控制器基类
|
||||
// Controller is used for controller register of ghttp.Server.
|
||||
type Controller struct {
|
||||
Request *ghttp.Request // 请求数据对象
|
||||
Response *ghttp.Response // 返回数据对象(r.Response)
|
||||
Server *ghttp.Server // Web Server对象(r.Server)
|
||||
Cookie *ghttp.Cookie // COOKIE操作对象(r.Cookie)
|
||||
Session *ghttp.Session // SESSION操作对象
|
||||
View *View // 视图对象
|
||||
Request *ghttp.Request
|
||||
Response *ghttp.Response
|
||||
Server *ghttp.Server
|
||||
Cookie *ghttp.Cookie
|
||||
Session *ghttp.Session
|
||||
View *View
|
||||
}
|
||||
|
||||
// 控制器初始化接口方法
|
||||
// Init is the callback function for each request initialization.
|
||||
func (c *Controller) Init(r *ghttp.Request) {
|
||||
c.Request = r
|
||||
c.Response = r.Response
|
||||
@ -31,12 +31,12 @@ func (c *Controller) Init(r *ghttp.Request) {
|
||||
c.Session = r.Session
|
||||
}
|
||||
|
||||
// 控制器结束请求接口方法
|
||||
// Shut is the callback function for each request close.
|
||||
func (c *Controller) Shut() {
|
||||
|
||||
}
|
||||
|
||||
// 退出请求执行
|
||||
// Exit equals to function Request.Exit().
|
||||
func (c *Controller) Exit() {
|
||||
c.Request.Exit()
|
||||
}
|
||||
|
||||
@ -7,5 +7,4 @@
|
||||
package gmvc
|
||||
|
||||
// Model is the base struct for model.
|
||||
type Model struct {
|
||||
}
|
||||
type Model struct{}
|
||||
|
||||
@ -16,15 +16,17 @@ import (
|
||||
"github.com/gogf/gf/os/gview"
|
||||
)
|
||||
|
||||
// 基于控制器注册的MVC视图基类(一个请求一个视图对象,用完即销毁)
|
||||
// View is the view object for controller.
|
||||
// It's initialized when controller request initializes and destroyed
|
||||
// when the controller request closes.
|
||||
type View struct {
|
||||
mu sync.RWMutex // 并发互斥锁
|
||||
view *gview.View // 底层视图对象
|
||||
data gview.Params // 视图数据/模板变量
|
||||
response *ghttp.Response // 数据返回对象
|
||||
mu sync.RWMutex
|
||||
view *gview.View
|
||||
data gview.Params
|
||||
response *ghttp.Response
|
||||
}
|
||||
|
||||
// 创建一个MVC请求中使用的视图对象
|
||||
// NewView creates and returns a controller view object.
|
||||
func NewView(w *ghttp.Response) *View {
|
||||
return &View{
|
||||
view: gins.View(),
|
||||
@ -33,7 +35,7 @@ func NewView(w *ghttp.Response) *View {
|
||||
}
|
||||
}
|
||||
|
||||
// 批量绑定模板变量,即调用之后每个线程都会生效,因此有并发安全控制
|
||||
// Assigns assigns template variables to this view object.
|
||||
func (view *View) Assigns(data gview.Params) {
|
||||
view.mu.Lock()
|
||||
for k, v := range data {
|
||||
@ -42,14 +44,15 @@ func (view *View) Assigns(data gview.Params) {
|
||||
view.mu.Unlock()
|
||||
}
|
||||
|
||||
// 绑定模板变量,即调用之后每个线程都会生效,因此有并发安全控制
|
||||
// Assign assigns one template variable to this view object.
|
||||
func (view *View) Assign(key string, value interface{}) {
|
||||
view.mu.Lock()
|
||||
view.data[key] = value
|
||||
view.mu.Unlock()
|
||||
}
|
||||
|
||||
// 解析模板,并返回解析后的内容
|
||||
// Parse parses given template file <tpl> with assigned template variables
|
||||
// and returns the parsed template content.
|
||||
func (view *View) Parse(file string) (string, error) {
|
||||
view.mu.RLock()
|
||||
defer view.mu.RUnlock()
|
||||
@ -57,7 +60,8 @@ func (view *View) Parse(file string) (string, error) {
|
||||
return buffer, err
|
||||
}
|
||||
|
||||
// 直接解析模板内容,并返回解析后的内容
|
||||
// ParseContent parses given template file <file> with assigned template variables
|
||||
// and returns the parsed template content.
|
||||
func (view *View) ParseContent(content string) (string, error) {
|
||||
view.mu.RLock()
|
||||
defer view.mu.RUnlock()
|
||||
@ -65,14 +69,14 @@ func (view *View) ParseContent(content string) (string, error) {
|
||||
return buffer, err
|
||||
}
|
||||
|
||||
// 使用自定义方法对模板变量执行加锁修改操作
|
||||
// LockFunc locks writing for template variables by callback function <f>.
|
||||
func (view *View) LockFunc(f func(data gview.Params)) {
|
||||
view.mu.Lock()
|
||||
defer view.mu.Unlock()
|
||||
f(view.data)
|
||||
}
|
||||
|
||||
// 使用自定义方法对模板变量执行加锁读取操作
|
||||
// LockFunc locks reading for template variables by callback function <f>.
|
||||
func (view *View) RLockFunc(f func(data gview.Params)) {
|
||||
view.mu.RLock()
|
||||
defer view.mu.RUnlock()
|
||||
@ -93,7 +97,7 @@ func (view *View) BindFuncMap(funcMap gview.FuncMap) {
|
||||
view.view.BindFuncMap(funcMap)
|
||||
}
|
||||
|
||||
// 解析并显示指定模板
|
||||
// Display parses and writes the parsed template file content to http response.
|
||||
func (view *View) Display(file ...string) error {
|
||||
name := "index.tpl"
|
||||
if len(file) > 0 {
|
||||
@ -110,7 +114,7 @@ func (view *View) Display(file ...string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 解析并显示模板内容
|
||||
// DisplayContent parses and writes the parsed content to http response.
|
||||
func (view *View) DisplayContent(content string) error {
|
||||
if content, err := view.ParseContent(content); err != nil {
|
||||
if !gmode.IsProduct() {
|
||||
|
||||
@ -11,8 +11,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/debug/gdebug"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"github.com/gogf/gf/util/gutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"reflect"
|
||||
@ -340,10 +338,6 @@ func (s *Server) Start() error {
|
||||
}
|
||||
})
|
||||
}
|
||||
if intlog.IsGFDebug() {
|
||||
intlog.Print("server configuration:")
|
||||
gutil.Dump(s.config)
|
||||
}
|
||||
s.dumpRouterMap()
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ package ghttp
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
@ -151,6 +152,8 @@ func (s *Server) SetConfig(c ServerConfig) error {
|
||||
s.EnableHTTPS(c.HTTPSCertPath, c.HTTPSKeyPath)
|
||||
}
|
||||
SetGraceful(c.Graceful)
|
||||
|
||||
intlog.Printf("SetConfig: %+v", s.config)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -30,6 +30,9 @@ func init() {
|
||||
}
|
||||
builtInVarMap["gfVersion"] = gf.VERSION
|
||||
builtInVarMap["goVersion"] = runtime.Version()
|
||||
intlog.Printf("build variables: %+v", builtInVarMap)
|
||||
} else {
|
||||
intlog.Print("no build variables")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,10 @@
|
||||
|
||||
package gcfg
|
||||
|
||||
import "github.com/gogf/gf/container/gmap"
|
||||
import (
|
||||
"github.com/gogf/gf/container/gmap"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
)
|
||||
|
||||
var (
|
||||
// Customized configuration content.
|
||||
@ -41,9 +44,9 @@ func GetContent(file ...string) string {
|
||||
return configs.Get(name)
|
||||
}
|
||||
|
||||
// RemoveConfig removes the global configuration with specified <file>.
|
||||
// RemoveContent removes the global configuration with specified <file>.
|
||||
// If <name> is not passed, it removes configuration of the default group name.
|
||||
func RemoveConfig(file ...string) {
|
||||
func RemoveContent(file ...string) {
|
||||
name := DEFAULT_CONFIG_FILE
|
||||
if len(file) > 0 {
|
||||
name = file[0]
|
||||
@ -57,6 +60,8 @@ func RemoveConfig(file ...string) {
|
||||
configs.Remove(name)
|
||||
}
|
||||
})
|
||||
|
||||
intlog.Printf(`RemoveContent: %s`, name)
|
||||
}
|
||||
|
||||
// ClearContent removes all global configuration contents.
|
||||
@ -68,4 +73,6 @@ func ClearContent() {
|
||||
v.(*Config).jsons.Clear()
|
||||
}
|
||||
})
|
||||
|
||||
intlog.Print(`RemoveConfig`)
|
||||
}
|
||||
|
||||
@ -428,7 +428,7 @@ func TestCfg_Config(t *testing.T) {
|
||||
gtest.Assert(gcfg.GetContent("config.yml"), "gf")
|
||||
gcfg.SetContent("gf1", "config.yml")
|
||||
gtest.Assert(gcfg.GetContent("config.yml"), "gf1")
|
||||
gcfg.RemoveConfig("config.yml")
|
||||
gcfg.RemoveContent("config.yml")
|
||||
gcfg.ClearContent()
|
||||
gtest.Assert(gcfg.GetContent("name"), "")
|
||||
})
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/container/gset"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"time"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
@ -94,6 +95,7 @@ func New() (*Watcher, error) {
|
||||
if watcher, err := fsnotify.NewWatcher(); err == nil {
|
||||
w.watcher = watcher
|
||||
} else {
|
||||
intlog.Printf("New watcher failed: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
w.startWatchLoop()
|
||||
|
||||
@ -43,6 +43,8 @@ func (w *Watcher) AddOnce(name, path string, callbackFunc func(event *Event), re
|
||||
if fileIsDir(subPath) {
|
||||
if err := w.watcher.Add(subPath); err != nil {
|
||||
intlog.Error(err)
|
||||
} else {
|
||||
intlog.Printf("watcher adds monitor for: %s", subPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -85,6 +87,8 @@ func (w *Watcher) addWithCallbackFunc(name, path string, callbackFunc func(event
|
||||
// Add the path to underlying monitor.
|
||||
if err := w.watcher.Add(path); err != nil {
|
||||
intlog.Error(err)
|
||||
} else {
|
||||
intlog.Printf("watcher adds monitor for: %s", path)
|
||||
}
|
||||
// Add the callback to global callback map.
|
||||
callbackIdMap.Set(callback.Id, callback)
|
||||
|
||||
@ -100,6 +100,8 @@ func (w *Watcher) startEventLoop() {
|
||||
// We need no worry about the repeat adding.
|
||||
if err := w.watcher.Add(event.Path); err != nil {
|
||||
intlog.Error(err)
|
||||
} else {
|
||||
intlog.Printf("fake remove event, watcher re-adds monitor for: %s", event.Path)
|
||||
}
|
||||
// Change the event to RENAME, which means it renames itself to its origin name.
|
||||
event.Op = RENAME
|
||||
@ -114,6 +116,8 @@ func (w *Watcher) startEventLoop() {
|
||||
// We need no worry about the repeat adding.
|
||||
if err := w.watcher.Add(event.Path); err != nil {
|
||||
intlog.Error(err)
|
||||
} else {
|
||||
intlog.Printf("fake rename event, watcher re-adds monitor for: %s", event.Path)
|
||||
}
|
||||
// Change the event to CHMOD.
|
||||
event.Op = CHMOD
|
||||
@ -130,6 +134,8 @@ func (w *Watcher) startEventLoop() {
|
||||
if fileIsDir(subPath) {
|
||||
if err := w.watcher.Add(subPath); err != nil {
|
||||
intlog.Error(err)
|
||||
} else {
|
||||
intlog.Printf("folder creation event, watcher adds monitor for: %s", subPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -137,6 +143,8 @@ func (w *Watcher) startEventLoop() {
|
||||
// If it's a file, it directly adds it to monitor.
|
||||
if err := w.watcher.Add(event.Path); err != nil {
|
||||
intlog.Error(err)
|
||||
} else {
|
||||
intlog.Printf("file creation event, watcher adds monitor for: %s", event.Path)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -57,7 +57,7 @@ func (l *Logger) SetConfig(config Config) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
intlog.Print(l.config)
|
||||
intlog.Printf("SetConfig: %+v", l.config)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ package gres
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -41,6 +42,7 @@ func New() *Resource {
|
||||
func (r *Resource) Add(content string, prefix ...string) error {
|
||||
files, err := UnpackContent(content)
|
||||
if err != nil {
|
||||
intlog.Printf("Add resource files failed: %v", err)
|
||||
return err
|
||||
}
|
||||
namePrefix := ""
|
||||
@ -51,6 +53,7 @@ func (r *Resource) Add(content string, prefix ...string) error {
|
||||
files[i].resource = r
|
||||
r.tree.Set(namePrefix+files[i].file.Name, files[i])
|
||||
}
|
||||
intlog.Printf("Add %d files to resource manager", r.tree.Size())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,6 @@ type Config struct {
|
||||
|
||||
// SetConfig sets the configuration for view.
|
||||
func (view *View) SetConfig(config Config) error {
|
||||
intlog.Printf("%+v", config)
|
||||
var err error
|
||||
if len(config.Paths) > 0 {
|
||||
for _, v := range config.Paths {
|
||||
@ -52,6 +51,8 @@ func (view *View) SetConfig(config Config) error {
|
||||
// Clear global template object cache.
|
||||
// It's just cache, do not hesitate clearing it.
|
||||
templates.Clear()
|
||||
|
||||
intlog.Printf("SetConfig: %+v", view.config)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user