go-resty / resty

Simple HTTP and REST client library for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for go-logr/logr on resty

thapabishwa-plerionaut opened this issue · comments

Currently, the go-resty/resty client does not support go-logr/logr, a popular logging library for Go applications. This issue is created to propose and discuss the addition of go-logr/logr support to the go-resty/resty client.

Motivation:
go-logr/logr provides a flexible and extensible logging framework, allowing applications to use different log sinks and log levels. By adding support for go-logr/logr to the go-resty/resty client, users can have more control and flexibility over logging in their applications.

There are (non-exhaustive list of)implementations for the following logging libraries:

  • a function (can bridge to non-structured libraries): funcr
  • a testing.T (for use in Go tests, with JSON-like output): testr
  • github.com/google/glog: glogr
  • k8s.io/klog (for Kubernetes): klogr
  • a testing.T (with klog-like text output): ktesting
  • go.uber.org/zap: zapr
  • log (the Go standard library logger): stdr
  • github.com/sirupsen/logrus: logrusr
  • github.com/wojas/genericr: genericr (makes it easy to implement your own backend)
  • logfmt (Heroku style logging): logfmtr
  • github.com/rs/zerolog: zerologr
  • github.com/go-kit/log: gokitlogr (also compatible with github.com/go-kit/kit/log since v0.12.0)
  • bytes.Buffer (writing to a buffer): bufrlogr (useful for ensuring values were logged, like during testing)

Proposed Changes:
Example:

package main

import (
    "github.com/go-resty/resty/v2"
    "github.com/go-logr/logr"
)

func main() {
    logger := logr.New() // Initialize a logr logger

    restyClient := resty.New()
    restyClient.SetLogger(logger) // Set the logger for resty

    // Use restyClient for HTTP requests, and it will log using logr
}

Expected Result:
With this feature, users can integrate go-resty/resty seamlessly into their applications that use various implementations ofgo-logr/logr for logging. This provides consistency in the logging framework and allows for better customization and control of log messages.

Additional Context:
Please note that this is just a proposal, and further discussion and development are needed to implement this feature. I encourage the community to share their thoughts, suggestions, or any potential challenges related to this feature request.

+1 for this feature, especially for the kubernetes ecosystem