@@ -16,7 +16,6 @@ package main
1616
1717import (
1818 "hash/fnv"
19- "strconv"
2019
2120 "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
2221 "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types"
@@ -42,19 +41,19 @@ func newContext(contextID uint32) proxywasm.HttpContext {
4241func (ctx * httpHeaders ) OnHttpRequestHeaders (int , bool ) types.Action {
4342 hs , err := proxywasm .HostCallGetHttpRequestHeaders ()
4443 if err != nil {
45- proxywasm .LogCritical ("failed to get request headers: " , err . Error () )
44+ proxywasm .LogCriticalf ("failed to get request headers: %v " , err )
4645 return types .ActionContinue
4746 }
4847 for _ , h := range hs {
49- proxywasm .LogInfo ("request header: " , h [0 ], ": " , h [1 ])
48+ proxywasm .LogInfof ("request header from: %s: %s " , h [0 ], h [1 ])
5049 }
5150
5251 if _ , err := proxywasm .HostCallDispatchHttpCall (
5352 clusterName , hs , "" , [][2 ]string {}, 50000 ); err != nil {
54- proxywasm .LogCritical ("dipatch httpcall failed: " , err . Error () )
53+ proxywasm .LogCriticalf ("dipatch httpcall failed: %v " , err )
5554 }
5655
57- proxywasm .LogInfo ("http call dispatched to " , clusterName )
56+ proxywasm .LogInfof ("http call dispatched to %s " , clusterName )
5857
5958 return types .ActionPause
6059}
@@ -63,24 +62,25 @@ func (ctx *httpHeaders) OnHttpRequestHeaders(int, bool) types.Action {
6362func (ctx * httpHeaders ) OnHttpCallResponse (_ int , bodySize int , _ int ) {
6463 hs , err := proxywasm .HostCallGetHttpCallResponseHeaders ()
6564 if err != nil {
66- proxywasm .LogCritical ("failed to get response body: " , err .Error ())
65+
66+ proxywasm .LogCriticalf ("failed to get response body: %v" , err )
6767 return
6868 }
6969
7070 for _ , h := range hs {
71- proxywasm .LogInfo ("response header from httpbin: " , h [0 ], ": " , h [1 ])
71+ proxywasm .LogInfof ("response header from %s: %s: %s " , clusterName , h [0 ], h [1 ])
7272 }
7373
7474 b , err := proxywasm .HostCallGetHttpCallResponseBody (0 , bodySize )
7575 if err != nil {
76- proxywasm .LogCritical ("failed to get response body: " , err . Error () )
76+ proxywasm .LogCriticalf ("failed to get response body: %v " , err )
7777 proxywasm .HostCallResumeHttpRequest ()
7878 return
7979 }
8080
8181 s := fnv .New32a ()
8282 if _ , err := s .Write (b ); err != nil {
83- proxywasm .LogCritical ("failed to calculate hash: " , err . Error () )
83+ proxywasm .LogCriticalf ("failed to calculate hash: %v " , err )
8484 proxywasm .HostCallResumeHttpRequest ()
8585 return
8686 }
@@ -100,5 +100,5 @@ func (ctx *httpHeaders) OnHttpCallResponse(_ int, bodySize int, _ int) {
100100
101101// override default
102102func (ctx * httpHeaders ) OnLog () {
103- proxywasm .LogInfo ( strconv . FormatUint ( uint64 ( ctx . contextID ), 10 ), " finished" )
103+ proxywasm .LogInfof ( "%d finished", ctx . contextID )
104104}
0 commit comments