Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j logs decreases application performance?

Does logging decreases application performance? and how to restrict display-tags logs to be printed in log files?

eg. my log file has below logs

[2012-06-20 15:52:06,290] org.displaytag.tags.TableTag isFirstIteration 684 - [data] first iteration=true (row number=1)
[2012-06-20 15:52:06,290] org.displaytag.tags.TableTag isFirstIteration 684 - [data] first iteration=true (row number=1)
[2012-06-20 15:52:06,290] org.displaytag.tags.TableTag isFirstIteration 684 - [data] first iteration=true (row number=1)
[2012-06-20 15:52:06,290] org.displaytag.tags.TableTag isFirstIteration 684 - [data] first iteration=true (row number=1)

why the above is in log file?

log.properties file

# Log4j configuration file.
 log4j.rootCategory=DEBUG, A1
 # Available levels are DEBUG, INFO, WARN, ERROR, FATAL

 #
 # A1 is a ConsoleAppender 
 #

log4j.appender.A1 = org.apache.log4j.RollingFileAppender
log4j.appender.A1.File = C:/LogInfo/logfile.log
log4j.appender.A1.MaxFileSize = 100MB
log4j.appender.A1.MaxBackupIndex=50
log4j.appender.A1.layout = org.apache.log4j.PatternLayout
log4j.appender.A1.append = true
log4j.appender.A1.layout.ConversionPattern = [%d] %C %M %L - %m%n
log4j.appender.A1.Threshold = DEBUG

how to stop (org.displaytag.tags.TableTag) these kind of logs to be printed in log files

like image 615
happy Avatar asked Jun 20 '12 10:06

happy


2 Answers

Does logging decreases application performance?

Yes. How much it does depends on a number of factors; see below.

and how to restrict display-tags logs to be printed in log files?

By changing the ConversionPattern in the logging properties

why the above is in log file?

Because:

  1. somewhere in the code is a call to a Logger method (probably debug(String)) with that message, and
  2. your logging properties set the logging Threshold to DEBUG for the appender.

To improve performance:

  1. change the ConversionPattern to use less expensive date/time formatting, and (more importantly) avoid 'C', 'F', 'L' and 'M' because they are particularly expensive.
  2. change the logging Threshold to INFO or WARNING or ERROR to reduce the amount of logging,
  3. put the Logger.debug(...) call inside an if statement that checks that debug logging is enabled. This saves the cost of assembling the log message in cases where it won't be needed; see In log4j, does checking isDebugEnabled before logging improve performance?.
  4. with log4j version 2 (log4j2), there are overloads that on the logging methods that take a format and parameters. These reduce the overhead when a logging at a level that is disabled.
  5. look also at logback and log4j 2.0.

You can also throttle logging at the Logger level ... as described in the log4j documentation. In fact, the documentation answers most of the questions that you asked, and has a lot of detail on the topics of logging performance and logging configuration.

like image 59
Stephen C Avatar answered Oct 10 '22 20:10

Stephen C


Short answer: yes, it decreases application performance as it uses some CPU cycles and other resources (memory, etc).

See also this question : log4j performance

like image 32
Guido Avatar answered Oct 10 '22 20:10

Guido