如何启用除 prod、dev 或 test 之外的其他环境的 padrino 记录器。例如,舞台环境?
我舞台环境中的 padrino 应用程序不写入文件日志。
我试过
Padrino::Logger::Config[:stage][:stream] = :to_file
Padrino::Logger::Config[:stage][:log_level] = :devel
但我收到了错误
$ - > RACK_ENV=homolog bundle exec padrino start
Users/carlospereira/ws/nutri/config/boot.rb:15:in `<top (required)>': undefined method `[]=' for nil:NilClass (NoMethodError)
from /Users/carlospereira/.rvm/gems/ruby-1.9.2-p320@nutri/bundler/gems/padrino-framework-94d09af7573a/padrino-core/lib/padrino-core/cli/base.rb:24:in `require'
from /Users/carlospereira/.rvm/gems/ruby-1.9.2-p320@nutri/bundler/gems/padrino-framework-94d09af7573a/padrino-core/lib/padrino-core/cli/base.rb:24:in `start'
from /Users/carlospereira/.rvm/gems/ruby-1.9.2-p320@nutri/gems/thor-0.15.2/lib/thor/task.rb:27:in `run'
from /Users/carlospereira/.rvm/gems/ruby-1.9.2-p320@nutri/gems/thor-0.15.2/lib/thor/invocation.rb:120:in `invoke_task'
from /Users/carlospereira/.rvm/gems/ruby-1.9.2-p320@nutri/gems/thor-0.15.2/lib/thor.rb:275:in `dispatch'
from /Users/carlospereira/.rvm/gems/ruby-1.9.2-p320@nutri/gems/thor-0.15.2/lib/thor/base.rb:408:in `start'
from /Users/carlospereira/.rvm/gems/ruby-1.9.2-p320@nutri/bundler/gems/padrino-framework-94d09af7573a/padrino-core/bin/padrino:9:in `<top (required)>'
from /Users/carlospereira/.rvm/gems/ruby-1.9.2-p320@nutri/bin/padrino:23:in `load'
from /Users/carlospereira/.rvm/gems/ruby-1.9.2-p320@nutri/bin/padrino:23:in `<main>'
在我的 boot.rb 我有:
PADRINO_ENV = ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= "development" unless defined?(PADRINO_ENV)
PADRINO_ROOT = File.expand_path('../..', __FILE__) unless defined?(PADRINO_ROOT)
require 'rubygems' unless defined?(Gem)
require 'bundler/setup'
Bundler.require(:default, PADRINO_ENV)
Padrino::Logger::Config[:homolog][:stream] = :to_file
Padrino::Logger::Config[:homolog][:log_level] = :devel
Padrino.before_load do
Encoding.default_internal = nil
end
Padrino.after_load do
DataMapper.finalize
end
Padrino.load!
我删了评论,但第 15 行是
Padrino::Logger::Config[:homolog][:stream] = :to_file
我也试过
if PADRINO_ENV == 'homolog'
log_file_name = "#{PADRINO_ROOT}/log/#{PADRINO_ENV}_#{(ENV['APP_PROCESS_NAME'] || File.basename($0))}.log"
log_file = File.new(log_file_name, "a+")
PADRINO_LOGGER = { :homolog => { :log_level => :debug, :stream => log_file }}
end
但我仍然收到消息:
/Users/carlospereira/ws/nutri/config/boot.rb:19: warning: already initialized constant PADRINO_LOGGER
No logging configuration for :homolog found, falling back to :production
第 19 行是
PADRINO_LOGGER = { :homolog => { :log_level => :debug, :stream => log_file }}
并且没有日志写入日志文件。
有任何想法吗?
太极拳