I am trying to make a custom logger. I read elsewhere that I can define my logger in environment.rb and use it in other files.
I have in environment.rb:
# Load the rails application
require File.expand_path('../application', __FILE__)
my_logger = Logger.new("#{Rails.root}/log/my.log")
my_logger.formatter = Logger::Formatter.new
# Initialize the rails application
MyApp::Application.initialize!
And I call the logger from, for example, a controller:
my_logger.info "got here"
However, I obtain the error:
Undefined local variable or method `my_logger’ for
Any clues as to why this could be happening? Thanks!
Open file into writing/appending mode :
Try :