This is an automated email from the ASF dual-hosted git repository.

jinrongtong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git


The following commit(s) were added to refs/heads/master by this push:
     new 3cc5cdfd fix(log.go): improve log directory retrieval logic (#1220)
3cc5cdfd is described below

commit 3cc5cdfd4b541dfaf034598287bafb07a5cd2fee
Author: Quan <[email protected]>
AuthorDate: Wed Apr 15 15:55:15 2026 +0800

    fix(log.go): improve log directory retrieval logic (#1220)
    
    Fixed an issue where the user home directory could not be correctly 
retrieved in some cases. When `os.UserHomeDir()` fails, a safe fallback path to 
the `/tmp` directory is provided.
    
    Change-Id: I1d4f3835e5f84c15459cef2b5aa7a389c4d1ca44
---
 golang/log.go | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/golang/log.go b/golang/log.go
index a835ac63..c6a4cf43 100644
--- a/golang/log.go
+++ b/golang/log.go
@@ -80,7 +80,11 @@ func getEncoder() zapcore.Encoder {
 }
 
 func getLogWriter() zapcore.WriteSyncer {
-       clientLogRoot := utils.GetenvWithDef(CLIENT_LOG_ROOT, 
os.Getenv("user.home")+"/logs/rocketmqlogs")
+       homeDir, err := os.UserHomeDir()
+       if err != nil {
+               homeDir = "/tmp" // fallback to /tmp if home dir cannot be 
determined
+       }
+       clientLogRoot := utils.GetenvWithDef(CLIENT_LOG_ROOT, 
homeDir+"/logs/rocketmq")
        clientLogMaxIndex := utils.GetenvWithDef(CLIENT_LOG_MAXINDEX, "10")
        clientLogFileName := utils.GetenvWithDef(CLIENT_LOG_FILENAME, 
"rocketmq_client_go.log")
        clientLogMaxFileSize := utils.GetenvWithDef(CLIENT_LOG_FILESIZE, 
"1073741824")

Reply via email to