mirror of
https://github.com/skyle1995/NetworkAuth.git
synced 2026-05-25 02:24:05 +08:00
Optimize the output of sensitive log information
This commit is contained in:
14
cmd/root.go
14
cmd/root.go
@@ -81,8 +81,16 @@ func setupLogrusForNonHTTP() {
|
||||
// 使用命令行指定的配置文件
|
||||
config.Init(cfgFile)
|
||||
} else {
|
||||
// 使用默认配置文件路径
|
||||
config.Init("./config.json")
|
||||
// 使用默认配置文件路径,基于可执行文件所在目录
|
||||
execPath, err := os.Executable()
|
||||
if err != nil {
|
||||
// 如果获取可执行文件路径失败,使用当前工作目录
|
||||
config.Init("./config.json")
|
||||
} else {
|
||||
execDir := filepath.Dir(execPath)
|
||||
configPath := filepath.Join(execDir, "config.json")
|
||||
config.Init(configPath)
|
||||
}
|
||||
}
|
||||
|
||||
// 根据配置文件进一步配置logrus
|
||||
@@ -92,7 +100,7 @@ func setupLogrusForNonHTTP() {
|
||||
logger.InitLogger()
|
||||
|
||||
// 记录配置加载完成
|
||||
logrus.WithField("config_file", viper.ConfigFileUsed()).Info("配置文件加载完成")
|
||||
logrus.Info("配置文件加载完成")
|
||||
}
|
||||
|
||||
// initConfig 读取配置文件和环境变量
|
||||
|
||||
@@ -174,6 +174,8 @@ func startServer(server *http.Server) {
|
||||
|
||||
// 等待中断信号
|
||||
<-sigChan
|
||||
// 清除终端上的 ^C 字符并移动光标到行首
|
||||
fmt.Print("\r\033[K")
|
||||
logger.Info("收到关闭信号,正在优雅关闭服务器...")
|
||||
|
||||
// 创建一个带超时的上下文
|
||||
|
||||
Reference in New Issue
Block a user