Print Instead Of Logger (ARCH6157)
Ce contenu n’est pas encore disponible dans votre langue.
Key ruby.logging.puts-instead-of-logger · Severity warning · Category logging
Writing to stdout with puts or print lacks log levels, timestamps, and a configurable sink. Production code should use the framework logger.
Incorrect
Section titled “Incorrect”def charge(order) puts "Processing order #{order.id}" gateway.charge(order)endCorrect
Section titled “Correct”def charge(order) Rails.logger.info("Processing order", order_id: order.id) gateway.charge(order)endUse Rails.logger or a configured Logger instance instead of puts/print.