2012-01-24 1 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

프로덕션 구성은 이미 기본 설정이므로 필요하지 않습니다. 그렇지 않으면이 모양이 좋아 보인다. 모든 환경에서 설정이 true이면 일반 구성 블록에 넣습니다. 한 환경에서만 특수한 경우 또는 두 환경에서 특수한 경우 추가 블록으로 만듭니다. 자세한 내용은 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