Why do we use blocks instead of lines in rails logger?

In Rails

When we use the Logger class, we always define in blocks instead of String -

Rails.logger.error { error.message }

Not as follows -

Rails.logger.error "error.message"

What is the reason for this?

+4
source share
1 answer

Take a look at the documentation here:

Performance Impact of Logs

Another potential error is that if you have a lot of calls to Logger like this in your code:

logger.debug "Person attributes hash: #{@person.attributes.inspect}"

, , . , Ruby , String , . , , (.. ).

- string block. , ( , ), Rails , .

+9
source

All Articles