如何启用除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 }}
并且日志文件中没有写入日志。
有什么想法吗?
TKZ
答案 0 :(得分:2)
这就是我们在暂存环境中启用它的方式。
config/boot.rb
PADRINO_LOGGER = { :staging => { :log_level => :debug, :stream => :to_file }} if PADRINO_ENV == 'staging'
答案 1 :(得分:1)
您可以在config/boot.rb
Padrino::Logger::Config[:stage][:stream] = :to_file
Padrino::Logger::Config[:stage][:log_level] = :devel
请参阅API Doc
答案 2 :(得分:0)
我的解决方案是使用哈希,否则我会在日志中获得ascii颜色:
Padrino::Logger::Config[:development] = { :log_level => :debug, :stream => :to_file }