You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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 passlogger
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 myWork
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!
The text was updated successfully, but these errors were encountered: