Rails.logger is not overriden - ruby-on-rails

I have 2 envs: test, and production
in both I have the following under enviroments/*.rb:
config.logger = LogStashLogger.new(port: 5228)
Problem is , that only on test env i have Rails.logger pointing to this logger and working, and in production env, the Rails.logger is still STDOUT.
I looked and searched for another override, but found nothing.
I even tried to put it on the config/enviroment.rb, but without any luck. Production insists on being STDOUT...
Is this related to nginx/passenger in any way?
Please assist
Tnx!

it was rails_12factor in my gemfile (Heroku's gem) that includes
rails_stdout_logging !!!!!
i removed it completely and it solved my problem.

Related

Why are my gem 'dotenv-rails' variables not loading?

gem 'dotenv-rails' is required in gemfile test and development environments.
.env file is saved in root
I believe variables use correct syntax; USERNAME=username
I am using Rails 5.0.4
I have not required 'dotenv-rails' anywhere, as the docs do not suggest that I need to.
When playing in the console, the only way I can access the variables is by calling, Dotenv.load in each session. Suggesting that Dotenv.load should be called somewhere in config of my app.
Add Dotenv::Railtie.load to your config/application.rb
You may also need to restart Spring.
bin/spring stop
It will restart once you run another rails command.
In case this helps anyone else:
This happened to me once. As it turns out, I was mistakenly passing RAILS_ENV=production in the environment variables, disabling it.
For me the bin/spring stop fixed the issue and I am using ruby 3.1.2 and rails 7.0.4.

Why is Rails not writing to development.log

Suddenly my Rails 4.2 app is writing nothing to development.log.
Absolutely nothing!
I have tried checking the correct environment is being used, restarting the server, checking for gems that might interact with logger, checking permissions, logger.flush, and rake log:clean.
The log file is now completely empty, and nothing is being written.
Running rails s gives:
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-03-14 18:49:57] INFO WEBrick 1.3.1
[2015-03-14 18:49:57] INFO ruby 2.1.5 (2014-11-13) [x86_64-darwin14.0]
[2015-03-14 18:49:57] INFO WEBrick::HTTPServer#start: pid=3963 port=3000
There are quite a few similar questions on Stackoverflow, but none provide an answer that has worked in my case.
I have no idea what would cause this or how to systematically debug.
What steps should I take?
OK, after much going round in circles, I finally found the culprit.
The rails_12factor is apparently overwriting config.logger.
See: https://github.com/heroku/rails_stdout_logging/blob/master/lib/rails_stdout_logging/rails3.rb#L7
I removed this gem from the development environment (I really only need it in the deployed environment) and everything is now working.
To put a gem in production only, it needs to be in a gem environment group like this:
# This is override development.log output and should only go in production.
group :production do
gem 'rails_12factor'
end
Thanks #maxd for helping to get me thinking in the right direction.
I think your problem can be caused by the following things:
You set to high log level. Check your application.rb and environments\*.rb files:
# Set to :debug to see everything in the log.
config.log_level = :error
You set custom logging. Check your application.rb, environments/*.rb and all files in initializers/*.rb:
# Use a different logger for distributed setups.
config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
These two steps should help you to investigate problem and fix it.
Add the following line to config/environments/development.rb
config.log_level = :debug
restart server
If in AWS (or similar) you have to make sure that your log directory has write access.

production.log empty on Rails 4 / Capistrano / Passenger / Nginx server (digital ocean)

I have set up a rails 4 server on Ubuntu 12.04 using Capistrano, Nginx, Passenger, Postgres, Redis/Resque
Everything is working great, except that the production.log file is always empty.
I have tried a variety of configuration changes in production.rb to no avail.
It's definitely not a permissions issue, as the permissions on both the log dir and each of the logs are wide open (777)
Can anyone hep me figure out how to get basic logging working?
The culprit was Heroku's rails_12factor gem
Removing that gem from the Gemfile, now the logs are working as expected.
# group :production do
# gem 'rails_12factor'
# end
To clarify, the rails_12factor gem was responsible, but that's only because it includes rails_stdout_logging, which is the real culprit, however, due to it's intended behavior to "ensure that your logs will be sent to standard out."
Check with the log levels in production.rb file, config.log_level = :debug will display it's errors. Also make sure the server is running production mode, in case you have not made any changes any configuration files for rails env, production mode is by default.

running rails app on heroku, can't see static pages in /public folder

I have a couple static pages which when running locally work as localhost:3000/foo.html, but this doesn't work once uploaded to heroku.
I tried adding the following to the routes.rb file:
match '/foo', :to => redirect('/public/foo.html')
but that doesn't seem to work, it redirects me to foobar.com/public/foo.html, but still finds nothing there.
Per this article, you will need to tell Rails to serve static assets itself with:
config.serve_static_assets = true
in your config/environments/production.rb
Alternatively you can add the rails_12factor gem to the production group:
gem 'rails_12factor', group: :production
according to Heroku. This will also redirect log to stdout as also required by Heroku.
This baffled me for hours, but here's another potential solution. For some reason, I could generate documentation into /public/docs, but the documentation would not load, even immediately after I generated it. I would run a Heroku bash console, generate the documentation, exit, then re-run Heroku bash only to find that /public no longer contained my docs folder.
So, the only solution I found was to include the documentation in the Git repository. That was the only way that Heroku persisted /public/docs across deploys and bash instances.
I have no idea why this is... I opened a support ticket with Heroku and am awaiting a response.

Does Rails 2.3.4 by default hinder exceptions related to gems in development mode?

I have an app that I run in three different environments, so sometimes when I pull it from github, I'll get the default rails "Oops, there was a problem with the server" page instead of the stack trace page. This seems to only happen when there's a problem related to a gem.
I remember maybe 6 months or a year ago when developing, if I had a missing gem, it'd show me the no such file to load -- mysql stack trace page.
This is mostly out of curiosity, but this actually does slow me down a bit as I have to tail the log to find what's broke on me.
You should add your gems in your environment.rb file.
For example if your application requires redcloth, you add in the environment file (the global one or any environment specific one).
config.gem 'RedCloth',
:lib => 'redcloth',
:version => '>= 4.2.2'
Your application won't load until you install that gem. And it'll display you a message asking you to install it.
You'll find more informations here.
Which server are you using to run your app?
Passenger runs in production mode unless explicitly told otherwise in the passenger configuration.
Any chance either of these lines appear uncommented in config/environemnt.rb?
ENV['RAILS_ENV'] ||= 'production'
ENV['RAILS_ENV'] = 'production'

Resources