caicloud / nirvana

Golang Restful API Framework for Productivity

Home Page:https://caicloud.github.io/nirvana/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Log errors returned by business functions

wutz opened this issue · comments

Is there an elegant way to log errors returned by business functions?

The current plugin reqlog does not meet this requirement. I don't know if this is a bug.

@wutz Could you describe your demands with more details? If my understanding is correct, it seems that you want the reqlog to output the error returns by your api function. The plugin reqlog only outputs the key informations of your requests. If you want to log the error, you could write a plugin to replace reqlog or just output the error with log.Info().

I can't fount a simple way (like write a middleware) to log api function returned error.

The way I can find it is to print the log in each api function, or print it in the result's operator, which looks a bit ugly.

@wutz You can wrap service.ErrorDestinationHandler to log all errors returned by your functions.
It's very easy to register your own DestinationHandler via service.RegisterDestinationHandler.

@kdada Thanks, i will be try to use it.

The problem has been resolved by using service.RegisterDestinationHandler.