Skip to content

Commit

Permalink
utils包中添加编译信息
Browse files Browse the repository at this point in the history
*zap中增加是否为调试模式判断,调试模式输出完整路径
  • Loading branch information
nildebug committed May 16, 2024
1 parent 1d41223 commit 336ac4c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
10 changes: 9 additions & 1 deletion log/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package log
import (
"context"
"github.com/nildebug/tools/mcontext"
"github.com/nildebug/tools/utils"
"os"
"path/filepath"

Expand Down Expand Up @@ -188,7 +189,13 @@ func (l *ZapLogger) cores(isStdout bool, isJson bool, logLocation string, rotate

func (l *ZapLogger) customCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder) {
//s := "[file:" + caller.FullPath() + "]"
s := caller.FullPath() //使用完整路径
s := ""
if utils.IsDev() {
s = caller.FullPath() //使用完整路径
} else {
s = caller.TrimmedPath() //使用短路径
}

//caller.Function
// color, ok := _levelToColor[l.level]
// if !ok {
Expand Down Expand Up @@ -259,6 +266,7 @@ func (l *ZapLogger) kvAppend(ctx context.Context, keysAndValues []interface{}) [
if key != "" {
keysAndValues = append([]interface{}{mcontext.CenterKey, key}, keysAndValues...)
}
utils.IsDev()
return keysAndValues
}

Expand Down
17 changes: 17 additions & 0 deletions utils/build_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package utils

import "fmt"

var buildTime string
var buildDev string = "true"

//CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build
//-ldflags="-w -s -X 'github.com/nildebug/tools/utils.buildTime=$(date +"%Y-%m-%d %H:%M:%S")' -X 'github.com/nildebug/tools/utils.buildDev=false'"

func IsDev() bool {
return buildDev == "true"
}

func InputBuildInfo() string {
return fmt.Sprintf("Build Time: %s Build Dev: %s", buildTime, buildDev)
}

0 comments on commit 336ac4c

Please sign in to comment.