I am using this code to enable logging in my Sinatra app:
log_file = File.new('my_log_file.log', "a")
$stdout.reopen(log_file)
$stderr.reopen(log_file)
$stdout.sync=true
$stderr.sync=true
The actual logging is done using:
logger.debug("Starting call. Params = #{params.inspect}")
It turns out that only INFO or higher level log messages are logged and DEBUG messages are not logged. I am looking for a way to set up the log level to DEBUG.
You can set the log level using
configure :development do
set :logging, Logger::DEBUG
end
Sinatra sets you up with Rack::Logger in its default middleware, which can be initialized with a log level (see http://rack.rubyforge.org/doc/Rack/Logger.html). Sinatra initializes it with your logging
setting, so you can put a number (or Logger
constant) there instead of just true
.
FYI, here is the relevant method from the Sinatra::Base
source code that initializes the Rack::Logger middleware (found here)
def setup_custom_logger(builder)
if logging.respond_to? :to_int
builder.use Rack::Logger, logging
else
builder.use Rack::Logger
end
end
This is on Sinatra 1.3.2, I don't know if it was different in earlier versions
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