Skip to content

Commit

Permalink
feat: support set log dir by json file, issue: #310
Browse files Browse the repository at this point in the history
  • Loading branch information
tbs60 committed Oct 23, 2024
1 parent 9f3c86d commit 1615cdf
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/backend/booster/bk_dist/shadertool/command/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

// mainProcess do the make process:
func mainProcess(c *commandCli.Context) error {
common.FreshEnvFromProjectSetting()
initialLogDir(getLogDir(c.String(FlagLogDir)))
common.SetLogLevel(c.String(FlagLog))

Expand Down
54 changes: 54 additions & 0 deletions src/backend/booster/bk_dist/shadertool/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@
package common

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/TencentBlueKing/bk-turbo/src/backend/booster/bk_dist/common/env"
dcFile "github.com/TencentBlueKing/bk-turbo/src/backend/booster/bk_dist/common/file"
dcSDK "github.com/TencentBlueKing/bk-turbo/src/backend/booster/bk_dist/common/sdk"
dcUtil "github.com/TencentBlueKing/bk-turbo/src/backend/booster/bk_dist/common/util"
"github.com/TencentBlueKing/bk-turbo/src/backend/booster/common/blog"
"github.com/TencentBlueKing/bk-turbo/src/backend/booster/common/codec"
)

// define const vars
Expand Down Expand Up @@ -176,3 +183,50 @@ func SetLogLevel(level string) {
blog.SetStderrLevel(blog.StderrLevelInfo)
}
}

// ++ 增加公共函数,用于从配置文件获取环境变量变设置到当前
func getProjectSettingFile() (string, error) {
exepath := dcUtil.GetExcPath()
if exepath != "" {
jsonfile := filepath.Join(exepath, "bk_project_setting.json")
if dcFile.Stat(jsonfile).Exist() {
return jsonfile, nil
}
}

return "", fmt.Errorf("not found project setting file")
}

func resolveApplyJSON(filename string) (*ApplyParameters, error) {
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}

var t ApplyParameters
if err = codec.DecJSON(data, &t); err != nil {
return nil, err
}

return &t, nil
}

func FreshEnvFromProjectSetting() error {
projectSettingFile, err := getProjectSettingFile()
if err != nil {
return err
}

settings, err := resolveApplyJSON(projectSettingFile)
if err != nil {
return err
}

for k, v := range settings.Env {
os.Setenv(k, v)
}

return nil
}

// --
2 changes: 2 additions & 0 deletions src/backend/booster/bk_dist/ubttool/command/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import (
"github.com/TencentBlueKing/bk-turbo/src/backend/booster/common/blog"
"github.com/TencentBlueKing/bk-turbo/src/backend/booster/common/conf"

shaderToolComm "github.com/TencentBlueKing/bk-turbo/src/backend/booster/bk_dist/shadertool/common"
commandCli "github.com/urfave/cli"
)

// mainProcess do the make process:
func mainProcess(c *commandCli.Context) error {
shaderToolComm.FreshEnvFromProjectSetting()
initialLogDir(getLogDir(c.String(FlagLogDir)))
setLogLevel(c.String(FlagLog))

Expand Down

0 comments on commit 1615cdf

Please sign in to comment.