devimteam / amqp

Golang AMQP wrapper
MIT License
10 stars 12 forks source link

Implementation of logrus as logging library #6

Open jvaca92 opened 4 years ago

jvaca92 commented 4 years ago

Implementation of logrus as logging library instead of custom logger.

vetcher commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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.