Logrus: Is logrus capable of logging async?

Created on 9 Mar 2018  路  8Comments  路  Source: sirupsen/logrus

If so, how can I achieve that?

question

All 8 comments

I think currently Logrus doesn't support async logging.

Some hooks, however, have implemented their own version. You can create your own hook based on the logrus-graylog-hook for further information.

PS.- If additionally you would like the standard error output to be async as well then the solution gets more complicated.

I used logrus and implemented simply a custom hook that logged the messages asynchronously by writing them to a channel. A goroutine then reads this messages from the channel and writes them to the log.

The standard output of logrus could then be simply discarded

@RenathoAzevedo did the previous comments answer your question ?

Is there any desire on the maintainers side to support async natively in logrus? Seems like this could be implemented as part of the logger itself rather than having to implement it outside.

What are the perceived benefits of async logging? What are the use cases for async logging?

What are the perceived benefits of async logging? What are the use cases for async logging?

Perceived benefit is avoiding the performance penalty from synchronous logging due to IO bottlenecks or any internal computation (i.e. when SetReportCaller is set to true)

Use case: I have an application serving very bursty traffic. To lower the work on the main thread and increase performance, I would like to log asynchronously.

I agree that it's solvable with a wrapper over the logger, but I think it's too valuable to omit from logrus

As commented above the primary benefit is reducing time taken per transaction/request. It鈥檚 not uncommon for a service to log messages for each request to a service. When using synchronous logging the time taken to perform the I/O operations are included in the response time.

If using asynchronous logging applications can reply back to a request while the I/O operations happen in the background.

This is a very common practice in high volume and low latency applications.

My primary question is. Is this something that the maintainers have specifically chosen not to do, or is there appetite but it just hasn鈥檛 been contributed yet?

I know from experience that async APIs are hard to support well and often come with a set of trades offs that end up surprising users of them, so it's not something I'm personally interested in adding. That doesn't mean these use cases are invalid or bad either, just that I'm not personally convinced the trade off is worth it. Maybe one of the other maintainers are though.

I'd wager, but can't prove, that the time spent logging is minuscule compared to the time spent communicating with network services like down stream APIs and/or databases.

That doesn't mean it's not a problem for certain types of applications, but there are ways to deal with at least some of that already. For instance "async logging" is possible now by making a Hook that takes a copy of the entry and processes it in an async fashion. We have at least one instances of such a hook in use inside of Heroku (if I'm not mistaken).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kaushikchaubal picture kaushikchaubal  路  5Comments

demizer picture demizer  路  4Comments

kubistika picture kubistika  路  3Comments

drewwells picture drewwells  路  3Comments

psmason picture psmason  路  4Comments