Think my question is more about scoping in a sinatra app, but here goes. When hitting /bad, we get a NameError that logger is undefined inside Work.do_work. Which I suppose makes sense, we didn't pass logger in to the do_work method.
I've tried the likes of defining a global logger var $logger = Logger.new(STDOUT) and passing that to sensible_logging -- and the using $logger inside my Work class - but then I don't get the benefits of sensible_logging. That just produces raw, untagged logging.
So my question is - any way to allow logger to be globally available AND have the benefits of sensible logging?
Cheers - thanks!
class Work
def self.do_work
logger.info 'whatever'
end
end
class App < Sinatra::Base
register Sinatra::SensibleLogging
sensible_logging(logger: Logger.new($stdout))
configure :production do
set :log_level, Logger::INFO
end
get '/bad' do
Work.do_work
'tldr'
end
get '/good' do
logger.info 'works fine'
end
end
Think my question is more about scoping in a sinatra app, but here goes. When hitting
/bad, we get a NameError that logger is undefined inside Work.do_work. Which I suppose makes sense, we didn't passloggerin to the do_work method.I've tried the likes of defining a global logger var
$logger = Logger.new(STDOUT)and passing that to sensible_logging -- and the using$loggerinside myWorkclass - but then I don't get the benefits of sensible_logging. That just produces raw, untagged logging.So my question is - any way to allow
loggerto be globally available AND have the benefits of sensible logging?Cheers - thanks!