I'd like to change the logger filename. The default, say, on production, is production.log.
I'd like it be customized, for example, to production.mymachine.log.
How can I do this? I can't find any obvious way.
You can change this application wide in config/application.rb or for each environment in their dedicated files in config/environments
# e.g. in config/environments/development.rb
config.logger = Logger.new(Rails.root.join('log', 'development.my_machine.log'))
Related
I am using the web_console gem and I would like to add some IPs to the whitelist. For reasons that would probably go to far to explain, can't simply add something to the config/application.rb or config/environments/development.rb. However I can create an initializer config/initializers/.
I simple tried this in config/initializers/99-webconsole.rb, but while the file is loaded (--> debug message is shown), the web console does not seem to pick up my settings.
Rails.application.configure do
config.web_console.whitelisted_ips = '10.10.0.0/16'
p "Debug: this is loaded."
end
I assume it's related to some kind of race condition? Providing the same line in config/environments/development.rb works, but as said, I sadly can not change that file.
Based on this code https://github.com/rails/web-console/blob/e3dcf4c588af526eafcf1ce9413e62d846599538/lib/web_console/railtie.rb#L59
maybe there is a code in your initializer that configuring config.web_console.permissions, so your whitelisted_ips config is ignored
whitelisted_ips is also deprecated
and have you checked that you are using v4.2.0, the permissions was buggy and fixed by this commit https://github.com/rails/web-console/commit/6336c89385b58e88b2661ea3dc42fe28651d6296
I'm trying to set config.public_file_server.headers on many different apps (using a gem), some of which may already have this setting in production.rb. My initial thought is that I may be able to do it in a custom initializer, however I am unsure of whether or not initializers have the ability to overwrite configuration settings in this file. Any and all help is much appreciated.
It looks like initializers run after environment.rb as well as the specific environment files.
1. config/preinitializer.rb
2. config/environment.rb
3. config/environments/#{RAILS_ENV}.rb
4. plugin initialization
5. gem initialization
6. config/initializer/*.rb
7. all after_initialize blocks, in the order they were defined in (so same order as above)
8. any junk left below the Rails::Initializer.run call/block in environment.rb
source: http://willbryant.net/rails_initialization_and_configuration_order
I've normally put settings like the below in config/application.rb
config.generators.stylesheets = false
config.time_zone = 'Berlin'
But in Rails 5 the message below is found in config/application.rb
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
What does this mean? Am I supposed to add an initializer-file for every config setting? And in that case, what should such a file contain?
You should still be able to put the configuration in your config/application.rb, however the message is informing you that your environment specific configurations take precedence over those specified there, so if you have another configuration overriding any of such values in your config/environments those in the environment specific would be used.
If you're using the initializers approach, in your config/initializers/stylesheet_generator.rb, you'd have:
Rails.application.config.generators.stylesheets = false
and in your config/initializers/time_zone.rb, you'd have:
Rails.application.config.time_zone = 'Berlin'
I have many yaml files in config/ And I want to load all yaml files.
EX: I have two .yml files name is: application.yml and linkedin.yml. I want to load both files with application.rb.
To achieve this goal I Have written code in application.rb:
ENV.update YAML.load_file('config/application.yml')[Rails.env] rescue {}
ENV.update YAML.load_file('config/linkedin.yml')[Rails.env] rescue {}
But this is not appropriate way, Please suggest me how can I load all yaml files access with ENV variable that.
Assuming that your YAML files are placed in the config folder, in your application.rb you can do this right under the requires (before the module definition)
APP_YAML = YAML::load_file(File.join(File.dirname(File.expand_path(__FILE__)), 'application.yml'))
LINKED_IN = YAML::load_file(File.join(File.dirname(File.expand_path(__FILE__)), 'linked_in.yml'))
This way, you can then access the contents of the file in a constant that is available everywhere in the app ie. LINKED_IN["secret"]
This is a great way to handle constants that you don't want to check in to source control, but actually I've found that using Figaro is the best way to handle constants. Essentially, Figaro will autogenerate/load an application.yml and all you have to do is put your constants in there.
After this, you can access with ENV["LINKED_IN_SECRET"] - as a plus, this emulates how Heroku would do it with their config:set variable system so you don't have to worry about environment changes :)
I'm storing configuration variables for different environments in the production.rb and development.rb
production.rb
ENV['my_variable'] = 'val1'
development.rb
ENV['my_variable'] = 'val2'
Maybe exists another way to store variables for different environments. What is the best way?
I've been pointing people towards the settingsgem lately. Settings Gem