Logging in Sinatra?

前端 未结 4 1620
囚心锁ツ
囚心锁ツ 2020-12-02 10:49

I\'m having trouble figuring out how to log messages with Sinatra. I\'m not looking to log requests, but rather custom messages at certain points in my app. For example, whe

4条回答
  •  遥遥无期
    2020-12-02 10:50

    If you are using something like unicorn logging or other middleware that tails IO streams, you can easily set up a logger to STDOUT or STDERR

    # unicorn.rb
    stderr_path "#{app_root}/shared/log/unicorn.stderr.log"
    stdout_path "#{app_root}/shared/log/unicorn.stdout.log"
    
    # sinatra_app.rb
    set :logger, Logger.new(STDOUT) # STDOUT & STDERR is captured by unicorn
    logger.info('some info') # also accessible as App.settings.logger
    

    this allows you to intercept messages at application scope, rather than just having access to logger as request helper

提交回复
热议问题