Repository: cloudwego/hertz
Pull request #364 (2022-11-11 06:39:51)

fix: add prefix to no-format log print function when use system logger
#### What type of PR is this?
fix

#### Check the PR title.
<!--
The description of the title will be attached in Release Notes, 
so please describe it from user-oriented, what this PR does / why we need it.
Please check your PR title with the below requirements:
-->
- [x] This PR title match the format: \<type\>(optional scope): \<description\>
- [x] The description of this PR title is user-oriented and clear enough for others to understand.


#### (Optional) Translate the PR title into Chinese.
在非 format 日志打印函数中添加前缀

#### Which issue(s) this PR fixes:
<!--
Automatically closes linked issue when PR is merged.
Eg: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->


codecov[bot]: # [Codecov](https://codecov.io/gh/cloudwego/hertz/pull/364?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego) Report
Base: **66.59**% // Head: **66.60**% // Increases project coverage by **`+0.01%`** :tada:
> Coverage data is based on head [(`4c6842d`)](https://codecov.io/gh/cloudwego/hertz/pull/364?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego) compared to base [(`516c123`)](https://codecov.io/gh/cloudwego/hertz/commit/516c123273cd9b59dd9ce11968361412fc8b245b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego).
> Patch coverage: 85.71% of modified lines in pull request are covered.

> :exclamation: Current head 4c6842d differs from pull request most recent head 8aff564. Consider uploading reports for the commit 8aff564 to get more accurate results

<details><summary>Additional details and impacted files</summary>


```diff
@@             Coverage Diff             @@
##           develop     #364      +/-   ##
===========================================
+ Coverage    66.59%   66.60%   +0.01%     
===========================================
  Files           89       89              
  Lines         8507     8514       +7     
===========================================
+ Hits          5665     5671       +6     
- Misses        2480     2481       +1     
  Partials       362      362              
```


| [Impacted Files](https://codecov.io/gh/cloudwego/hertz/pull/364?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego) | Coverage Δ | |
|---|---|---|
| [pkg/common/hlog/system.go](https://codecov.io/gh/cloudwego/hertz/pull/364/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego#diff-cGtnL2NvbW1vbi9obG9nL3N5c3RlbS5nbw==) | `85.93% <85.71%> (-0.03%)` | :arrow_down: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/cloudwego/hertz/pull/364?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego).


Patch:
diff --git a/pkg/common/hlog/system.go b/pkg/common/hlog/system.go
index e931517..cb8a145 100644
--- a/pkg/common/hlog/system.go
+++ b/pkg/common/hlog/system.go
@@ -41,30 +41,37 @@ func (ll *systemLogger) SetLevel(lv Level) {
 }
 
 func (ll *systemLogger) Fatal(v ...interface{}) {
+	v = append([]interface{}{ll.prefix}, v...)
 	ll.logger.Fatal(v...)
 }
 
 func (ll *systemLogger) Error(v ...interface{}) {
+	v = append([]interface{}{ll.prefix}, v...)
 	ll.logger.Error(v...)
 }
 
 func (ll *systemLogger) Warn(v ...interface{}) {
+	v = append([]interface{}{ll.prefix}, v...)
 	ll.logger.Warn(v...)
 }
 
 func (ll *systemLogger) Notice(v ...interface{}) {
+	v = append([]interface{}{ll.prefix}, v...)
 	ll.logger.Notice(v...)
 }
 
 func (ll *systemLogger) Info(v ...interface{}) {
+	v = append([]interface{}{ll.prefix}, v...)
 	ll.logger.Info(v...)
 }
 
 func (ll *systemLogger) Debug(v ...interface{}) {
+	v = append([]interface{}{ll.prefix}, v...)
 	ll.logger.Debug(v...)
 }
 
 func (ll *systemLogger) Trace(v ...interface{}) {
+	v = append([]interface{}{ll.prefix}, v...)
 	ll.logger.Trace(v...)
 }
 
diff --git a/pkg/protocol/http1/client.go b/pkg/protocol/http1/client.go
index cb12bc7..d5d5d03 100644
--- a/pkg/protocol/http1/client.go
+++ b/pkg/protocol/http1/client.go
@@ -919,7 +919,7 @@ func dialAddr(addr string, dial network.Dialer, dialDualStack bool, tlsConfig *t
 	var conn network.Conn
 	var err error
 	if dial == nil {
-		hlog.SystemLogger().Warnf("HostClient: no dialer specified, trying to use default dialer")
+		hlog.SystemLogger().Warn("HostClient: no dialer specified, trying to use default dialer")
 		dial = dialer.DefaultDialer()
 	}
 	dialFunc := dial.DialConnection
diff --git a/pkg/route/engine.go b/pkg/route/engine.go
index 8a272a8..d1fa73b 100644
--- a/pkg/route/engine.go
+++ b/pkg/route/engine.go
@@ -499,7 +499,7 @@ func (engine *Engine) Serve(c context.Context, conn network.Conn) (err error) {
 		if bytes.Equal(buf, bytestr.StrClientPreface) && engine.protocolServers[suite.HTTP2] != nil {
 			return engine.protocolServers[suite.HTTP2].Serve(c, conn)
 		}
-		hlog.SystemLogger().Warnf("HTTP2 server is not loaded, request is going to fallback to HTTP1 server")
+		hlog.SystemLogger().Warn("HTTP2 server is not loaded, request is going to fallback to HTTP1 server")
 	}
 
 	// ALPN path


Test patch:
diff --git a/pkg/common/hlog/system_test.go b/pkg/common/hlog/system_test.go
index 59c5019..b48e96d 100644
--- a/pkg/common/hlog/system_test.go
+++ b/pkg/common/hlog/system_test.go
@@ -47,12 +47,12 @@ func TestSysLogger(t *testing.T) {
 	sysLogger.Warn("work may fail")
 	sysLogger.Error("work failed")
 
-	assert.DeepEqual(t, "[Trace] trace work\n"+
-		"[Debug] received work order\n"+
-		"[Info] starting work\n"+
-		"[Notice] something happens in work\n"+
-		"[Warn] work may fail\n"+
-		"[Error] work failed\n", string(w.b))
+	assert.DeepEqual(t, "[Trace] HERTZ: trace work\n"+
+		"[Debug] HERTZ: received work order\n"+
+		"[Info] HERTZ: starting work\n"+
+		"[Notice] HERTZ: something happens in work\n"+
+		"[Warn] HERTZ: work may fail\n"+
+		"[Error] HERTZ: work failed\n", string(w.b))
 }
 
 func TestSysFormatLogger(t *testing.T) {