Browse Source

Write logs correctly to host dir when domain is attached

Vova Tkach 5 years ago
parent
commit
c92dd376ff
1 changed files with 12 additions and 1 deletions
  1. 12 1
      logger/logger.go

+ 12 - 1
logger/logger.go

@@ -7,6 +7,7 @@ import (
 	"time"
 	"time"
 
 
 	"golang-fave/consts"
 	"golang-fave/consts"
+	"golang-fave/domains"
 	"golang-fave/utils"
 	"golang-fave/utils"
 )
 )
 
 
@@ -68,7 +69,17 @@ func (this *Logger) write(msg *logMsg) {
 
 
 	// Extract host
 	// Extract host
 	host, _ := utils.ExtractHostPort(msg.host, false)
 	host, _ := utils.ExtractHostPort(msg.host, false)
-	logs_dir := this.wwwDir + string(os.PathSeparator) + host + string(os.PathSeparator) + "logs"
+
+	// --- TODO: optimize this later
+	curr_host := host
+	doms := domains.New(this.wwwDir)
+	if mhost := doms.GetHost(host); mhost != "" {
+		curr_host = mhost
+
+	}
+	// ---
+
+	logs_dir := this.wwwDir + string(os.PathSeparator) + curr_host + string(os.PathSeparator) + "logs"
 
 
 	// Try use localhost folder for logs
 	// Try use localhost folder for logs
 	if !utils.IsDirExists(logs_dir) {
 	if !utils.IsDirExists(logs_dir) {