简体   繁体   中英

Does much debug logging slow my (grails) web application down?

My grails web application currently logs a lot of debugging information into a file, for almost every request.

From your experience, should I turn this off before moving it to production (which will make it harder to trace bugs of course), or is there almost no effect on the performance of my application even when there are many users at the same time?

Logging definitely slows things down. Writing to files especially is extremely slow. Even the process of creating the strings to log will have an negative affect on performance. I'd strongly advise you turn this logging off. If you have problems with you application, then you're better off debugging in a development environment than production.

I agree with @tzhx. I will add only 2 points:

1) You probably want to divide your log statements according to their importance, using log.info, .warn, .error, and then in your configuration make adjustments so in production you are using the appropriate level for varying packages. You will probably want some baseline level of logging, even in prod.

2) Definitely do not log sql in prod. If you have an issue, log sql in dev or your qa environment to determine the problem.

Agreed with both previous answers. Typically I'm setting log level to WARN or ERROR in production. If you have the need to adjust logging levels at runtime you might use the http://www.grails.org/plugin/runtime-logging plugin. This allows you to increase logging to track down problems occuring only in production. After error analysis you can revert logging level to their normal level.

If your use case requires extensive logging (eg for audit trail reasons etc.) you should have seperate discs for logging or log to some dedicated remote device.

As said before, it can affect badly performances if you log a lot of information to your file. I recommend you to do the following:

  1. Most of debugging information should be enclosed in statement like if (log.debugEnabled) log.debug "This is a debug log line" . Note the usage of if (log.debugEnabled) that is important if you don't want to have your debug messages being evaluated even in production
  2. Install plugin app-info . This plugin allows you to change logging levels (from INFO to DEBUG for instance) at runtime and unlike runtime-logging plugin, it gives you other information useful for debugging (configuration properties, memory consuption...)

Logging by itself carries a performance cost.

But do you know what can REALLY ruin your application peformance? Console logging

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM