Giter Site home page Giter Site logo

Comments (4)

halfcrazy avatar halfcrazy commented on May 16, 2024

+1 for this feature, especially for the kubernetes ecosystem

from resty.

jeevatkm avatar jeevatkm commented on May 16, 2024

@thapabishwa-plerionaut @halfcrazy Thanks for reaching out. I'm sorry for the delayed response.

Resty provides a Logger interface for user choice of overriding.

resty/util.go

Lines 31 to 35 in 97187c4

type Logger interface {
Errorf(format string, v ...interface{})
Warnf(format string, v ...interface{})
Debugf(format string, v ...interface{})
}

So you could assign your existing logger instance to it.

client := resty.New().SetLogger(...)

from resty.

thapabishwa avatar thapabishwa commented on May 16, 2024

@jeevatkm

The interface you mentioned doesn't have the ability to interoperate with loggers(like gologr, klog, slog etc) that are used in kubernetes ecosystem.

package main

import (
	"net/http"

	"github.com/go-resty/resty/v2"
	"sigs.k8s.io/controller-runtime/pkg/log"
)

func main() {

	logger := log.Log.WithName("controller").WithName("mylogger")
        /// cannot use logger (variable of type logr.Logger) as resty.Logger value in argument to resty.New().SetLogger: logr.Logger does not implement resty.Logger (missing method Debugf)
	client := resty.New().SetLogger(logger)
	cookies := []*http.Cookie{
		&http.Cookie{
			Name:  "go-resty-1",
			Value: "This is cookie 1 value",
		},
		&http.Cookie{
			Name:  "go-resty-2",
			Value: "This is cookie 2 value",
		},
	}

	client.SetCookies(cookies)

}

from resty.

jeevatkm avatar jeevatkm commented on May 16, 2024

logr.Logger does not implement resty.Logger (missing method Debugf)

@thapabishwa Based on the error message, it seems logr does not have a Debugf implementation. I suggest creating a tiny wrapper for the log library you would like to use.

For example, refer to -

resty/util.go

Lines 37 to 66 in 94e70d3

func createLogger() *logger {
l := &logger{l: log.New(os.Stderr, "", log.Ldate|log.Lmicroseconds)}
return l
}
var _ Logger = (*logger)(nil)
type logger struct {
l *log.Logger
}
func (l *logger) Errorf(format string, v ...interface{}) {
l.output("ERROR RESTY "+format, v...)
}
func (l *logger) Warnf(format string, v ...interface{}) {
l.output("WARN RESTY "+format, v...)
}
func (l *logger) Debugf(format string, v ...interface{}) {
l.output("DEBUG RESTY "+format, v...)
}
func (l *logger) output(format string, v ...interface{}) {
if len(v) == 0 {
l.l.Print(format)
return
}
l.l.Printf(format, v...)
}

from resty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.