I have the following Sinatra 1.2.1 application code:
# app.rb
require 'sinatra'
get '/' do
logger.info "COUCOU"
'Hello world!'
end
and start the server with ruby -rubygems app.rb
. When I go to http://localhost:4567 I get the error:
NameError at /
undefined local variable or method `logger' for #<Sinatra::Application:0x00000100d91f88>
file: app.rb location: block in <main> line: 4
Do I need to add or configure something to enable logging in Sinatra? Reading the Sinatra README and documentation, it looks like logging is enabled by default for Sinatra::Application
.
The problem is in the not found write method, just extend the Logger class this way and everything should be ok:
class Logger
# Make Rack::CommonLogger accept a Logger instance
# without raising undefined method `write' for #<Logger:0x007fc12db61778>
# makes a method alias using symbols
alias :write :<<
end
You are probably missing a logger = Logger.new
.
http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With