Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of logrus as logging library #6

Open
jvaca92 opened this issue Feb 5, 2020 · 3 comments
Open

Implementation of logrus as logging library #6

jvaca92 opened this issue Feb 5, 2020 · 3 comments

Comments

@jvaca92
Copy link

jvaca92 commented Feb 5, 2020

Implementation of logrus as logging library instead of custom logger.

@vetcher
Copy link
Contributor

vetcher commented Feb 10, 2020

Its a bad idea, because logrus is huge, slow, complicated and most of the time useless lib. Also it conflicts with modern methodologies, like https://12factor.net/ and specially https://12factor.net/logs. Moreover making logging lib as dependency for transport lib is also not best idea.

So you can do it yourself: just write this piece of code somewhere and use Adapter as logger for github.com/devimteam/amqp.

import (
	"github.com/sirupsen/logrus"
)

type Adapter struct {
	*logrus.Logger
}

func (a *Adapter) Log(v ...interface{}) error {
	// log how you want, e.g.
	a.Logger.Error(v...)
	return nil
}

Usage:

func main() {
	lg := Adapter{Logger: logrus.New()}
	_ = lg.Log("")
	cl := amqp.NewClient(..., amqp.WithLogger{lg})
}

@jvaca92
Copy link
Author

jvaca92 commented Feb 11, 2020

I agree with you that the logrus it huge and more complex but on the other hands provide hooks for other systems such as ELK or other monitoring systems.
Anyway just be sure the solution which you provide here means that everywhere the logger is used just for logging of errors ? If not then how to detect levels of the logging.

@vetcher
Copy link
Contributor

vetcher commented Feb 11, 2020

Logger need for log only errors that happens in goroutines (so cant be returned to caller).
There are 2 types: connection/transport or amqp schema out of sync. So I recommend to use lvl Error or higher.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants