opt format comment

This commit is contained in:
niuyufu 2018-11-03 13:37:05 +08:00
parent 2d420a6dfd
commit 58544b82c2
3 changed files with 6 additions and 9 deletions

View File

@ -118,7 +118,7 @@ func (logger Logger) Print(values ...interface{}) {
logger.Println(LogFormatter(values...)...)
}
// Print format & print log
// CtxPrint format & print log
func (logger Logger) CtxPrint(s *DB,values ...interface{}) {
ctx,ok:=s.GetCtx()
if ok{

View File

@ -30,8 +30,8 @@ func TestLoggerCtx(t *testing.T) {
//Generating context information
unixTime := fmt.Sprint(time.Now().Unix())
traceId := fmt.Sprintf("%x", md5.Sum([]byte(unixTime)))
ctxInfo:= "\n[context] trace_id="+traceId
traceID := fmt.Sprintf("%x", md5.Sum([]byte(unixTime)))
ctxInfo:= "\n[context] trace_id="+traceID
builder := DB.SetCtx(ctxInfo)
if i > 5 {
builder = builder.Where("Age = ?", i)

View File

@ -149,11 +149,8 @@ func (s *DB) LogMode(enable bool) *DB {
return s
}
// LogMode set log ctx, `true` for get context when printing logs, `false` for no context, default, false
// LogCtx set log ctx, `true` for get context when printing logs, `false` for no context, default, false
func (s *DB) LogCtx(enable bool) *DB {
s.logCtx = 2
return s
fmt.Println(enable)
if enable {
s.logCtx = 2
} else {
@ -162,13 +159,13 @@ func (s *DB) LogCtx(enable bool) *DB {
return s
}
// Set query context
// SetCtx set query context
func (s *DB) SetCtx(v interface{}) *DB {
s=s.Set("trace_context",v)
return s
}
// Get query context
// GetCtx Get query context
func (s *DB) GetCtx() (value interface{}, ok bool) {
return s.Get("trace_context")
}