Logrus logger pointer to specific log level

447 Views Asked by At

I am using MQTT paho library that has its own logger interface that is implemented by logrus logger, paho library has multiple levels: ERROR, CRITICAL and so on. I tried to do something like this:

    MQTT.ERROR = app.Log.WithField("level","ERROR")
    MQTT.CRITICAL = app.Log.WithField("level","CRITICAL")

but that does not log because you can not have a field named level, and if you do not add level, it always goes to info level because entry.Print is implementation that does log.Info inside, is there a way to pass a pointer to logrus logger with corresponding log level without making a new wrapper around it.

I know that it can be done with new package that will implement mqtt.Logger with functions that will have log.Error calls inside. But I feel that there should be a bit better way of doing this.

1

There are 1 best solutions below

1
aureliar On

I know that it can be done with new package that will implement mqtt.Logger with functions that will have log.Error calls inside. But I feel that there should be a bit better way of doing this.

It doesn't have to be in a new package, you can just define a struct and make it implement mqtt.Logger in the same package.

I'm afraid there is no better way to do it