2012-01-24 10 views
4

Sinatraの設定ブロックをDRY方法に設定する適切な方法は何ですか?私が欲しいのです:Sinatra + DataMapperの適切なロギング設定

  • 生産で、インメモリのSQLiteのDBを使用し、テストでDB
  • にクエリをログに記録し、例外やエラー
  • 開発では表示されません。

私は次のようにこれを設定しました:

configure :production do 
    set :show_exceptions, false 
    set :raise_errors, false 
end 

configure :development do 
    DataMapper::Logger.new($stdout, :debug) 
end 

configure :test do 
    DataMapper.setup(:default, "sqlite::memory:") 
end 

しかし、どのようなベースconfigurationブロックに入れるには?これは適切なアプローチですか?また、Sinatraの設定ブロックの正しい実行順序がわからない。

答えて

0

プロダクション設定は既定の設定であるため、設定する必要はありません。そうでなければ、これは大丈夫です。すべての環境で設定が真であれば、それを一般的な構成ブロックに入れます。それが1つの環境に特有のものであれば、それは特別なブロックになります。すべての詳細については、Sinatra Readmeを参照してください。

0
class App < Sinatra::Base 

    configure :development do 
    enable :logging, :dump_errors, :raise_errors 
    disable :show_exceptions 
    DataMapper::Logger.new(STDOUT, :debug, '[DataMapper] ') 
    DataMapper::Model.raise_on_save_failure = true 
    end 

    configure :test do 
    enable :dump_errors, :raise_errors 
    disable :run, :logging, :show_exceptions 
    end 

    ## Log to file 
    # FileUtils.mkdir_p 'log' unless File.exists?('log') 
    # log_file = File.new('log/development.log', 'a') 

    # $stdout.reopen(log_file) 
    # $stderr.reopen(log_file) 
    # $stderr.sync = true 
    # $stdout.sync = true 
関連する問題