[agent-wdd] 完成自定义log部分;完成info network部分; 项目结构基本完成

This commit is contained in:
zeaslity
2025-02-11 17:27:41 +08:00
parent 66dca6a080
commit e826b55240
38 changed files with 39009 additions and 33930 deletions

View File

@@ -49,9 +49,15 @@ func AppendOverwriteContentToFile(content string, targetFile string) bool {
return AppendContentToFile(content, targetFile)
}
// AppendContentToFile 向目标文件中追加写入一些内容
// AppendContentToFile 向目标文件(targetFile 文件的绝对路径)中追加写入一些内容, 如果文件不存在,那么就创建相应的目录及文件
func AppendContentToFile(content string, targetFile string) bool {
// 创建目标文件的目录(递归创建)
dir := filepath.Dir(targetFile)
if err := os.MkdirAll(dir, 0755); err != nil {
return false
}
// 打开文件用于追加。如果文件不存在,将会创建一个新文件。
file, err := os.OpenFile(targetFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
@@ -61,9 +67,13 @@ func AppendContentToFile(content string, targetFile string) bool {
defer file.Close() // 确保文件最终被关闭
// 写入内容到文件
if _, err := file.WriteString(content); err != nil {
log.ErrorF("[BasicAppendContentToFile] - Error writing to file: %s , error is %s", targetFile, err.Error())
return false
// 内容非空时执行写入操作
if content != "" {
if _, err := file.WriteString(content); err != nil {
log.ErrorF("[BasicAppendContentToFile] - Error writing to file: %s , error is %s", targetFile, err.Error())
return false
}
}
return true