Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dbm-services/common/go-pubpkg/logger/cst.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ const (

// DatetimeUnion TODO
const DatetimeUnion = "20160102150405"

// NotForAi 不做AI分析的日志标签
const NotForAi = "not_for_ai"
7 changes: 7 additions & 0 deletions dbm-services/common/go-pubpkg/logger/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ var (

// Local TODO
Local = std.Local

// InfoNotForAi 不做AI分析的日志输出函数
InfoNotForAi = std.InfoNotForAi
// InfoWithLabel 带标签的Info日志输出函数
InfoWithLabel = std.InfoWithLabel
)

var std = New(os.Stderr, false, InfoLevel)
Expand All @@ -139,6 +144,8 @@ func ResetDefault(l *Logger) {
Fatal = std.Fatal
Debug = std.Debug
Local = std.Local
InfoNotForAi = std.InfoNotForAi
InfoWithLabel = std.InfoWithLabel
}

// Sync TODO
Expand Down
11 changes: 11 additions & 0 deletions dbm-services/common/go-pubpkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ func (l *Logger) Info(format string, args ...interface{}) {
l.Zap.Info(fmt.Sprintf(format, args...), l.Fields...)
}

// InfoWithLabel 输出带标签的日志
func (l *Logger) InfoWithLabel(label string, format string, args ...interface{}) {
fields := append(l.Fields, zap.String("label", label))
l.Zap.Info(fmt.Sprintf(format, args...), fields...)
}

// InfoNotForAi 输出不用于AI分析的日志,避免超过ai模型输入限制
func (l *Logger) InfoNotForAi(format string, args ...interface{}) {
l.InfoWithLabel(NotForAi, format, args...)
}

// Warn TODO
func (l *Logger) Warn(format string, args ...interface{}) {
l.Zap.Warn(fmt.Sprintf(format, args...), l.Fields...)
Expand Down
13 changes: 13 additions & 0 deletions dbm-services/common/go-pubpkg/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,16 @@ func TestDefault(t *testing.T) {

Info("testing default info")
}

func TestNotForAi(t *testing.T) {
file, err := os.OpenFile("./access.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, os.ModePerm)
if err != nil {
panic(err)
}
logger := New(file, false, InfoLevel)
ResetDefault(logger)
defer Sync()
Info("testing default info")
InfoNotForAi("testing info not for ai")
Info("testing default info")
}
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ func (e *ExecutePartitionSQLComp) excuteOne(
for _, partitionSQL := range partitionSQLSet {
_, err = dbw.Exec(partitionSQL)
if err != nil {
errs = append(errs, fmt.Sprintf("%s执行失败,报错:%s", partitionSQL, err.Error()))
logger.InfoNotForAi("%s执行失败,报错:%s", partitionSQL, err.Error())
errs = append(errs, fmt.Sprintf("执行失败报错:%s\n", err.Error()))
}
// c <- struct{}{}
// wg.Add(1)
Expand Down Expand Up @@ -350,7 +351,8 @@ func (e *ExecutePartitionSQLComp) excuteInitSql(
Password: e.GeneralParam.RuntimeAccountParam.PartitionYwPwd,
}.ExecuteInitPartition(command)
if err != nil {
errs = append(errs, fmt.Sprintf("%s执行失败,报错:%s", command, err.Error()))
logger.InfoNotForAi("%s执行失败,报错:%s\n", command, err.Error())
errs = append(errs, fmt.Sprintf("执行失败报错:%s\n", err.Error()))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ func ExecLocalSQLFile(sqlVersion string, dbName string, charsetNO int, filenames
logger.Error("the db [%s] exec sql script failed %s, result: %s ", dbName, err.Error(), ret)
return err
}
logger.Info("exec result: %s", ret)
logger.InfoNotForAi("exec result: %s", ret)
logger.Info("ths db [%s] exec sql script success [%d:%s]", dbName, port, filename)
}

Expand Down Expand Up @@ -661,7 +661,7 @@ func ExecLocalSQLFileForDataExport(sqlVersion string, dbName string, filenames [
logger.Error("the db [%s] exec sql script failed %s, result: %s ", dbName, err.Error(), ret)
return outPutFiles, err
}
logger.Info("exec result: %s", ret)
logger.InfoNotForAi("exec result: %s", ret)
logger.Info("ths db [%s] exec sql select script success [%d:%s]", dbName, port, filename)
}

Expand Down