@@ -21,7 +21,6 @@ import (
2121 "io"
2222 "io/fs"
2323 "net/http"
24- "time"
2524
2625 ouroboros "github.com/blinklabs-io/gouroboros"
2726 "github.com/blinklabs-io/gouroboros/protocol/localtxsubmission"
@@ -31,7 +30,6 @@ import (
3130 "github.com/blinklabs-io/tx-submit-api/submit"
3231 "github.com/fxamacker/cbor/v2"
3332 cors "github.com/gin-contrib/cors"
34- ginzap "github.com/gin-contrib/zap"
3533 "github.com/gin-gonic/gin"
3634 "github.com/penglongli/gin-metrics/ginmetrics"
3735 swaggerFiles "github.com/swaggo/files" // swagger embed files
@@ -55,16 +53,16 @@ func Start(cfg *config.Config) error {
5553 // Standard logging
5654 logger := logging .GetLogger ()
5755 if cfg .Tls .CertFilePath != "" && cfg .Tls .KeyFilePath != "" {
58- logger .Infof (
59- "starting API TLS listener on %s:%d " ,
60- cfg .Api .ListenAddress ,
61- cfg .Api .ListenPort ,
56+ logger .Info (
57+ "starting API TLS listener" ,
58+ "address" , cfg .Api .ListenAddress ,
59+ "port" , cfg .Api .ListenPort ,
6260 )
6361 } else {
64- logger .Infof (
65- "starting API listener on %s:%d " ,
66- cfg .Api .ListenAddress ,
67- cfg .Api .ListenPort ,
62+ logger .Info (
63+ "starting API listener" ,
64+ "address" , cfg .Api .ListenAddress ,
65+ "port" , cfg .Api .ListenPort ,
6866 )
6967 }
7068 // Disable gin debug and color output
@@ -90,14 +88,10 @@ func Start(cfg *config.Config) error {
9088 skipPaths := []string {}
9189 if cfg .Logging .Healthchecks {
9290 skipPaths = append (skipPaths , "/healthcheck" )
93- logger .Infof ("disabling access logs for /healthcheck" )
91+ logger .Info ("disabling access logs for /healthcheck" )
9492 }
95- router .Use (ginzap .GinzapWithConfig (accessLogger , & ginzap.Config {
96- TimeFormat : time .RFC3339 ,
97- UTC : true ,
98- SkipPaths : skipPaths ,
99- }))
100- router .Use (ginzap .RecoveryWithZap (accessLogger , true ))
93+ router .Use (logging .GinLogger (accessLogger , skipPaths ))
94+ router .Use (logging .GinRecovery (accessLogger , true ))
10195
10296 // Configure static route
10397 fsys , err := fs .Sub (staticFS , "static" )
@@ -158,9 +152,9 @@ func Start(cfg *config.Config) error {
158152 // Start metrics listener
159153 go func () {
160154 // TODO: return error if we cannot initialize metrics
161- logger .Infof ("starting metrics listener on %s:%d " ,
162- cfg .Metrics .ListenAddress ,
163- cfg .Metrics .ListenPort )
155+ logger .Info ("starting metrics listener" ,
156+ "address" , cfg .Metrics .ListenAddress ,
157+ "port" , cfg .Metrics .ListenPort )
164158 _ = metricsRouter .Run (fmt .Sprintf ("%s:%d" ,
165159 cfg .Metrics .ListenAddress ,
166160 cfg .Metrics .ListenPort ))
@@ -213,7 +207,7 @@ func handleHasTx(c *gin.Context) {
213207
214208 var uriParams TxHashPathParams
215209 if err := c .ShouldBindUri (& uriParams ); err != nil {
216- logger .Errorf ("failed to bind transaction hash from path: %s " , err )
210+ logger .Error ("failed to bind transaction hash from path" , "err " , err )
217211 c .JSON (400 , fmt .Sprintf ("invalid transaction hash: %s" , err ))
218212 return
219213 }
@@ -222,7 +216,7 @@ func handleHasTx(c *gin.Context) {
222216 // convert to cbor bytes
223217 cborData , err := cbor .Marshal (txHash )
224218 if err != nil {
225- logger .Errorf ("failed to encode transaction hash to CBOR: %s " , err )
219+ logger .Error ("failed to encode transaction hash to CBOR" , "err " , err )
226220 c .JSON (
227221 400 ,
228222 fmt .Sprintf ("failed to encode transaction hash to CBOR: %s" , err ),
@@ -236,19 +230,19 @@ func handleHasTx(c *gin.Context) {
236230 ouroboros .WithNodeToNode (false ),
237231 )
238232 if err != nil {
239- logger .Errorf ("failure creating Ouroboros connection: %s " , err )
233+ logger .Error ("failure creating Ouroboros connection" , "err " , err )
240234 c .JSON (500 , "failure communicating with node" )
241235 return
242236 }
243237 if cfg .Node .Address != "" && cfg .Node .Port > 0 {
244238 if err := oConn .Dial ("tcp" , fmt .Sprintf ("%s:%d" , cfg .Node .Address , cfg .Node .Port )); err != nil {
245- logger .Errorf ("failure connecting to node via TCP: %s " , err )
239+ logger .Error ("failure connecting to node via TCP" , "err " , err )
246240 c .JSON (500 , "failure communicating with node" )
247241 return
248242 }
249243 } else {
250244 if err := oConn .Dial ("unix" , cfg .Node .SocketPath ); err != nil {
251- logger .Errorf ("failure connecting to node via UNIX socket: %s " , err )
245+ logger .Error ("failure connecting to node via UNIX socket" , "err " , err )
252246 c .JSON (500 , "failure communicating with node" )
253247 return
254248 }
@@ -259,7 +253,7 @@ func handleHasTx(c *gin.Context) {
259253 }()
260254 hasTx , err := oConn .LocalTxMonitor ().Client .HasTx (cborData )
261255 if err != nil {
262- logger .Errorf ("failure getting transaction: %s " , err )
256+ logger .Error ("failure getting transaction" , "err " , err )
263257 c .JSON (500 , fmt .Sprintf ("failure getting transaction: %s" , err ))
264258 return
265259 }
@@ -288,7 +282,7 @@ func handleSubmitTx(c *gin.Context) {
288282 // Check our headers for content-type
289283 if c .ContentType () != "application/cbor" {
290284 // Log the error, return an error to the user, and increment failed count
291- logger .Errorf ("invalid request body, should be application/cbor" )
285+ logger .Error ("invalid request body, should be application/cbor" )
292286 c .JSON (415 , "invalid request body, should be application/cbor" )
293287 _ = ginmetrics .GetMonitor ().GetMetric ("tx_submit_fail_count" ).Inc (nil )
294288 return
@@ -297,15 +291,15 @@ func handleSubmitTx(c *gin.Context) {
297291 txRawBytes , err := io .ReadAll (c .Request .Body )
298292 if err != nil {
299293 // Log the error, return an error to the user, and increment failed count
300- logger .Errorf ("failed to read request body: %s " , err )
294+ logger .Error ("failed to read request body" , "err " , err )
301295 c .JSON (500 , "failed to read request body" )
302296 _ = ginmetrics .GetMonitor ().GetMetric ("tx_submit_fail_count" ).Inc (nil )
303297 return
304298 }
305299 // Close request body after read
306300 if c .Request .Body != nil {
307301 if err := c .Request .Body .Close (); err != nil {
308- logger .Errorf ("failed to close request body: %s " , err )
302+ logger .Error ("failed to close request body" , "err " , err )
309303 }
310304 }
311305 // Send TX
@@ -341,7 +335,7 @@ func handleSubmitTx(c *gin.Context) {
341335 go func () {
342336 err , ok := <- errorChan
343337 if ok {
344- logger .Errorf ("failure communicating with node: %s " , err )
338+ logger .Error ("failure communicating with node" , "err " , err )
345339 c .JSON (500 , "failure communicating with node" )
346340 _ = ginmetrics .GetMonitor ().
347341 GetMetric ("tx_submit_fail_count" ).
0 commit comments