adomokos / light-service

Series of Actions with an emphasis on simplicity.
MIT License
837 stars 67 forks source link

Make logging more efficient if it isn't turned on #120

Closed toofishes closed 7 years ago

toofishes commented 7 years ago

The ruby logger class has two forms- one with method params, and one with a block. They are different as the block form is lazy evaulated, and only evaulated if the log level is actually enabled.

We can use this block form logger, as well as the logger.info? guard, to save ourselves from building several log messages if we aren't actually going to send or print them somewhere. This should have no effect whatsoever on the contents of logs, it simply saves the overhead of string operations if we aren't actually logging.

http://brian.pontarelli.com/2006/07/03/ruby-logging-and-performance/

adomokos commented 7 years ago

Real neat! Thank you for it!