1

How can I enable padrino logger of other environment other than prod, dev or test. Like, for example, stage env?

My padrino app on my stage env do not write at file log.

I tried

Padrino::Logger::Config[:stage][:stream] = :to_file
Padrino::Logger::Config[:stage][:log_level]  = :devel

but I received the error

$ - > 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>'

In my boot.rb I have:

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!

I cut the comments, but line 15 is

Padrino::Logger::Config[:homolog][:stream] = :to_file

I also tried

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

but I still get the message:

/Users/carlospereira/ws/nutri/config/boot.rb:19: warning: already initialized constant PADRINO_LOGGER
No logging configuration for :homolog found, falling back to :production

line 19 is

PADRINO_LOGGER = { :homolog    => { :log_level => :debug, :stream => log_file }}

And no log is written on logfile.

Any ideas?

Tkz

cpereira
  • 155
  • 9

3 Answers3

3

This is how we enabled it in our staging environment.

The relevant portion of config/boot.rb

PADRINO_LOGGER = { :staging => { :log_level => :debug, :stream => :to_file }} if PADRINO_ENV == 'staging'
Jonathan
  • 1,241
  • 9
  • 16
  • Hi, Jonathan! I did as you say and when I start app in my stage env (homolog) I get an error `/Users/carlospereira/ws/nutri/config/boot.rb:19: warning: already initialized constant PADRINO_LOGGER No logging configuration for :homolog found, falling back to :production` and still don't write to log file. I will update my question with that – cpereira Nov 29 '12 at 13:21
  • That error sounds pretty straight forward, you already have `PADRINO_LOGGER` defined somewhere else... What does your earlier definition look like? – Jonathan Nov 30 '12 at 09:32
  • Ha... Of course! I put the code after `bundle.require(:default, PADRINO_ENV)` and get the error. Now I put in the begin of the file after `PADRINO_ROOT` definition and works! Thanks a lot, Jonathan – cpereira Nov 30 '12 at 13:12
2

You could set this in config/boot.rb

Padrino::Logger::Config[:stage][:stream] = :to_file
Padrino::Logger::Config[:stage][:log_level]  = :devel

Refer to API Doc

ch4nd4n
  • 4,110
  • 2
  • 21
  • 43
  • Hi, Ck-. Thank you for your attention, but I tried this before, and I get: `/config/boot.rb:21:in block in ': undefined method []=' for nil:NilClass (NoMethodError)` – cpereira Nov 28 '12 at 16:02
  • I can't guess why you get that error unless you post `boot.rb` file and the error stacktrace. – ch4nd4n Nov 28 '12 at 16:12
  • I updated my post with my boot.rb and the stacktrace. Am I missing something? maybe I should declare my :homolog env somewhere else? Thank you again, Ck- – cpereira Nov 28 '12 at 22:21
0

My solution was to use a hash otherwise i would get ascii colours in the log:

Padrino::Logger::Config[:development] = { :log_level => :debug, :stream => :to_file }
Gianfranco P.
  • 10,049
  • 6
  • 51
  • 68