Module: ArMailerRevised::Helpers::General
- Included in:
- Mailman
- Defined in:
- lib/ar_mailer_revised/helpers/general.rb
Instance Method Summary collapse
-
#log_file ⇒ String
Determines the correct log file location It defaults to the current environment’s log file.
-
#log_level ⇒ Int
Determines the correct log level from the given script arguments Defaults to
INFO
. -
#logger ⇒ Log4r::Logger
Generates a logger object using Log4r The output file is determined by
#log_file
. -
#rails_environment ⇒ String
The currently active rails environment.
-
#rails_environment?(env) ⇒ Bool
Checks if the given environment is currently active Works like Rails.env.env?.
Instance Method Details
#log_file ⇒ String
Check if that interferes with Rails’ logging process
Determines the correct log file location It defaults to the current environment’s log file
47 48 49 |
# File 'lib/ar_mailer_revised/helpers/general.rb', line 47 def log_file @log_file ||= @options[:log_file] ? File.(@options[:log_file]) : File.join(Rails.root, 'log', "#{rails_environment}.log") end |
#log_level ⇒ Int
Determines the correct log level from the given script arguments Defaults to INFO
57 58 59 |
# File 'lib/ar_mailer_revised/helpers/general.rb', line 57 def log_level @log_level ||= "Log4r::#{@options[:log_level].upcase}".constantize end |
#logger ⇒ Log4r::Logger
Generates a logger object using Log4r The output file is determined by #log_file
If the custom log file path is set to stdout
or stderr
, these are used instead of a log file.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ar_mailer_revised/helpers/general.rb', line 22 def logger unless @logger @logger = Log4r::Logger.new 'ar_mailer' if %w[stdout stderr].include?(@options[:log_file]) outputter = Log4r::Outputter.send(@options[:log_file]) else outputter = Log4r::FileOutputter.new('ar_mailer_log', :filename => log_file) end outputter.formatter = Log4r::PatternFormatter.new(:pattern => '[%5l - %c] %d :: %m') @logger.outputters = outputter @logger.level = log_level end @logger end |
#rails_environment ⇒ String
Returns the currently active rails environment.
64 65 66 |
# File 'lib/ar_mailer_revised/helpers/general.rb', line 64 def rails_environment ENV['RAILS_ENV'] end |
#rails_environment?(env) ⇒ Bool
Checks if the given environment is currently active Works like Rails.env.env?
76 77 78 |
# File 'lib/ar_mailer_revised/helpers/general.rb', line 76 def rails_environment?(env) rails_environment.to_s == env.to_s end |