Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
6189a117
M
milvus
项目概览
milvus
/
milvus
12 个月 前同步成功
通知
261
Star
22476
Fork
2472
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
6189a117
编写于
6月 24, 2022
作者:
S
SimFG
提交者:
GitHub
6月 24, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove the `WithOptions` for avoiding the log object being cloned continuously (#17746)
Signed-off-by:
N
SimFG
<
bang.fu@zilliz.com
>
上级
73857700
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
67 addition
and
24 deletion
+67
-24
internal/log/global.go
internal/log/global.go
+10
-10
internal/log/log_test.go
internal/log/log_test.go
+12
-1
internal/util/logutil/logutil.go
internal/util/logutil/logutil.go
+13
-13
internal/util/logutil/logutil_test.go
internal/util/logutil/logutil_test.go
+32
-0
未找到文件。
internal/log/global.go
浏览文件 @
6189a117
...
...
@@ -21,25 +21,25 @@ import (
// Debug logs a message at DebugLevel. The message includes any fields passed
// at the log site, as well as any fields accumulated on the logger.
func
Debug
(
msg
string
,
fields
...
zap
.
Field
)
{
L
()
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Debug
(
msg
,
fields
...
)
L
()
.
Debug
(
msg
,
fields
...
)
}
// Info logs a message at InfoLevel. The message includes any fields passed
// at the log site, as well as any fields accumulated on the logger.
func
Info
(
msg
string
,
fields
...
zap
.
Field
)
{
L
()
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Info
(
msg
,
fields
...
)
L
()
.
Info
(
msg
,
fields
...
)
}
// Warn logs a message at WarnLevel. The message includes any fields passed
// at the log site, as well as any fields accumulated on the logger.
func
Warn
(
msg
string
,
fields
...
zap
.
Field
)
{
L
()
.
W
ithOptions
(
zap
.
AddCallerSkip
(
1
))
.
W
arn
(
msg
,
fields
...
)
L
()
.
Warn
(
msg
,
fields
...
)
}
// Error logs a message at ErrorLevel. The message includes any fields passed
// at the log site, as well as any fields accumulated on the logger.
func
Error
(
msg
string
,
fields
...
zap
.
Field
)
{
L
()
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Error
(
msg
,
fields
...
)
L
()
.
Error
(
msg
,
fields
...
)
}
// Panic logs a message at PanicLevel. The message includes any fields passed
...
...
@@ -47,7 +47,7 @@ func Error(msg string, fields ...zap.Field) {
//
// The logger then panics, even if logging at PanicLevel is disabled.
func
Panic
(
msg
string
,
fields
...
zap
.
Field
)
{
L
()
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Panic
(
msg
,
fields
...
)
L
()
.
Panic
(
msg
,
fields
...
)
}
// Fatal logs a message at FatalLevel. The message includes any fields passed
...
...
@@ -56,7 +56,7 @@ func Panic(msg string, fields ...zap.Field) {
// The logger then calls os.Exit(1), even if logging at FatalLevel is
// disabled.
func
Fatal
(
msg
string
,
fields
...
zap
.
Field
)
{
L
()
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Fatal
(
msg
,
fields
...
)
L
()
.
Fatal
(
msg
,
fields
...
)
}
// RatedDebug print logs at debug level
...
...
@@ -64,7 +64,7 @@ func Fatal(msg string, fields ...zap.Field) {
// return true if log successfully
func
RatedDebug
(
cost
float64
,
msg
string
,
fields
...
zap
.
Field
)
bool
{
if
R
()
.
CheckCredit
(
cost
)
{
L
()
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Debug
(
msg
,
fields
...
)
L
()
.
Debug
(
msg
,
fields
...
)
return
true
}
return
false
...
...
@@ -75,7 +75,7 @@ func RatedDebug(cost float64, msg string, fields ...zap.Field) bool {
// return true if log successfully
func
RatedInfo
(
cost
float64
,
msg
string
,
fields
...
zap
.
Field
)
bool
{
if
R
()
.
CheckCredit
(
cost
)
{
L
()
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Info
(
msg
,
fields
...
)
L
()
.
Info
(
msg
,
fields
...
)
return
true
}
return
false
...
...
@@ -86,7 +86,7 @@ func RatedInfo(cost float64, msg string, fields ...zap.Field) bool {
// return true if log successfully
func
RatedWarn
(
cost
float64
,
msg
string
,
fields
...
zap
.
Field
)
bool
{
if
R
()
.
CheckCredit
(
cost
)
{
L
()
.
W
ithOptions
(
zap
.
AddCallerSkip
(
1
))
.
W
arn
(
msg
,
fields
...
)
L
()
.
Warn
(
msg
,
fields
...
)
return
true
}
return
false
...
...
@@ -95,7 +95,7 @@ func RatedWarn(cost float64, msg string, fields ...zap.Field) bool {
// With creates a child logger and adds structured context to it.
// Fields added to the child don't affect the parent, and vice versa.
func
With
(
fields
...
zap
.
Field
)
*
zap
.
Logger
{
return
L
()
.
With
Options
(
zap
.
AddCallerSkip
(
1
))
.
With
(
fields
...
)
return
L
()
.
With
(
fields
...
)
}
// SetLevel alters the logging level.
...
...
internal/log/log_test.go
浏览文件 @
6189a117
...
...
@@ -33,6 +33,7 @@ package log
import
(
"bufio"
"bytes"
"fmt"
"testing"
"time"
...
...
@@ -44,7 +45,7 @@ import (
func
TestExport
(
t
*
testing
.
T
)
{
ts
:=
newTestLogSpy
(
t
)
conf
:=
&
Config
{
Level
:
"debug"
,
DisableTimestamp
:
true
}
logger
,
_
,
_
:=
InitTestLogger
(
ts
,
conf
)
logger
,
_
,
_
:=
InitTestLogger
(
ts
,
conf
,
zap
.
AddCallerSkip
(
1
)
)
ReplaceGlobals
(
logger
,
nil
)
Info
(
"Testing"
)
...
...
@@ -53,6 +54,7 @@ func TestExport(t *testing.T) {
Error
(
"Testing"
)
Sync
()
ts
.
assertMessagesContains
(
"log_test.go:"
)
logPanic
()
ts
=
newTestLogSpy
(
t
)
logger
,
_
,
_
=
InitTestLogger
(
ts
,
conf
)
...
...
@@ -66,6 +68,15 @@ func TestExport(t *testing.T) {
ts
.
assertMessagesContains
(
`age=42`
)
}
func
logPanic
()
{
defer
func
()
{
if
err
:=
recover
();
err
!=
nil
{
fmt
.
Println
(
"logPanic recover"
)
}
}()
Panic
(
"Testing"
)
}
func
TestZapTextEncoder
(
t
*
testing
.
T
)
{
conf
:=
&
Config
{
Level
:
"debug"
,
File
:
FileLogConfig
{},
DisableTimestamp
:
true
}
...
...
internal/util/logutil/logutil.go
浏览文件 @
6189a117
...
...
@@ -46,68 +46,68 @@ type zapWrapper struct {
// Info logs a message at InfoLevel.
func
(
w
*
zapWrapper
)
Info
(
args
...
interface
{})
{
if
infoLog
>=
w
.
logLevel
{
w
.
logger
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Sugar
()
.
Info
(
args
...
)
w
.
logger
.
Sugar
()
.
Info
(
args
...
)
}
}
func
(
w
*
zapWrapper
)
Infoln
(
args
...
interface
{})
{
if
infoLog
>=
w
.
logLevel
{
w
.
logger
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Sugar
()
.
Info
(
args
...
)
w
.
logger
.
Sugar
()
.
Info
(
args
...
)
}
}
func
(
w
zapWrapper
)
Infof
(
format
string
,
args
...
interface
{})
{
if
infoLog
>=
w
.
logLevel
{
w
.
logger
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Sugar
()
.
Infof
(
format
,
args
...
)
w
.
logger
.
Sugar
()
.
Infof
(
format
,
args
...
)
}
}
func
(
w
zapWrapper
)
Warning
(
args
...
interface
{})
{
if
warningLog
>=
w
.
logLevel
{
w
.
logger
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Sugar
()
.
Warn
(
args
...
)
w
.
logger
.
Sugar
()
.
Warn
(
args
...
)
}
}
func
(
w
zapWrapper
)
Warningln
(
args
...
interface
{})
{
if
warningLog
>=
w
.
logLevel
{
w
.
logger
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Sugar
()
.
Warn
(
args
...
)
w
.
logger
.
Sugar
()
.
Warn
(
args
...
)
}
}
func
(
w
*
zapWrapper
)
Warningf
(
format
string
,
args
...
interface
{})
{
if
warningLog
>=
w
.
logLevel
{
w
.
logger
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Sugar
()
.
Warnf
(
format
,
args
...
)
w
.
logger
.
Sugar
()
.
Warnf
(
format
,
args
...
)
}
}
func
(
w
zapWrapper
)
Error
(
args
...
interface
{})
{
if
errorLog
>=
w
.
logLevel
{
w
.
logger
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Sugar
()
.
Error
(
args
...
)
w
.
logger
.
Sugar
()
.
Error
(
args
...
)
}
}
func
(
w
*
zapWrapper
)
Errorln
(
args
...
interface
{})
{
if
errorLog
>=
w
.
logLevel
{
w
.
logger
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Sugar
()
.
Error
(
args
...
)
w
.
logger
.
Sugar
()
.
Error
(
args
...
)
}
}
func
(
w
zapWrapper
)
Errorf
(
format
string
,
args
...
interface
{})
{
if
errorLog
>=
w
.
logLevel
{
w
.
logger
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Sugar
()
.
Errorf
(
format
,
args
...
)
w
.
logger
.
Sugar
()
.
Errorf
(
format
,
args
...
)
}
}
func
(
w
*
zapWrapper
)
Fatal
(
args
...
interface
{})
{
w
.
logger
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Sugar
()
.
Fatal
(
args
...
)
w
.
logger
.
Sugar
()
.
Fatal
(
args
...
)
}
func
(
w
zapWrapper
)
Fatalln
(
args
...
interface
{})
{
w
.
logger
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Sugar
()
.
Fatal
(
args
...
)
w
.
logger
.
Sugar
()
.
Fatal
(
args
...
)
}
func
(
w
*
zapWrapper
)
Fatalf
(
format
string
,
args
...
interface
{})
{
w
.
logger
.
WithOptions
(
zap
.
AddCallerSkip
(
1
))
.
Sugar
()
.
Fatalf
(
format
,
args
...
)
w
.
logger
.
Sugar
()
.
Fatalf
(
format
,
args
...
)
}
// V reports whether verbosity level l is at least the requested verbose level.
...
...
@@ -141,7 +141,7 @@ var once sync.Once
func
SetupLogger
(
cfg
*
log
.
Config
)
{
once
.
Do
(
func
()
{
// Initialize logger.
logger
,
p
,
err
:=
log
.
InitLogger
(
cfg
,
zap
.
AddStacktrace
(
zap
.
ErrorLevel
))
logger
,
p
,
err
:=
log
.
InitLogger
(
cfg
,
zap
.
AddStacktrace
(
zap
.
ErrorLevel
)
,
zap
.
AddCallerSkip
(
1
)
)
if
err
==
nil
{
log
.
ReplaceGlobals
(
logger
,
p
)
}
else
{
...
...
internal/util/logutil/logutil_test.go
0 → 100644
浏览文件 @
6189a117
package
logutil
import
(
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/zap/zapcore"
"github.com/milvus-io/milvus/internal/log"
"go.uber.org/zap"
)
func
TestName
(
t
*
testing
.
T
)
{
conf
:=
&
log
.
Config
{
Level
:
"debug"
,
DisableTimestamp
:
true
}
logger
,
_
,
_
:=
log
.
InitTestLogger
(
t
,
conf
,
zap
.
AddCallerSkip
(
1
),
zap
.
Hooks
(
func
(
entry
zapcore
.
Entry
)
error
{
assert
.
Equal
(
t
,
"Testing"
,
entry
.
Message
)
return
nil
}))
wrapper
:=
&
zapWrapper
{
logger
,
0
}
wrapper
.
Info
(
"Testing"
)
wrapper
.
Infoln
(
"Testing"
)
wrapper
.
Infof
(
"%s"
,
"Testing"
)
wrapper
.
Warning
(
"Testing"
)
wrapper
.
Warningln
(
"Testing"
)
wrapper
.
Warningf
(
"%s"
,
"Testing"
)
wrapper
.
Error
(
"Testing"
)
wrapper
.
Errorln
(
"Testing"
)
wrapper
.
Errorf
(
"%s"
,
"Testing"
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录