Production log not working
In the past I thought I was just crazy. I may be, but my production log is not at all responding to some requests. I am POSTing images to my rails app from a mobile client, then GETting a refreshed view in a web browser. The changed record is plainly visible. None of the above is showing up in my production log, but similar requests were logged an hour ago. I 开发者_C百科haven't changed any config files. I haven't restarted my server. Any suggestions as to why this is happening?
Check what value is set to
config.log_level = :warn
in your
/rails_app/config/enviroments/production.rb
FYI
The available log levels are: :debug, :info, :warn, :error, :fatal.
So if you set the level to fatal only serious errors will be logged. If you set it to debug almost everything will be logged. By default in production it is set to warn. This is with good reason. As you don't want huge log files piling up on your production server for no reason.
In my case first i added config.log_level = :debug
to production.rb
file then i had to create the production.log
file (in the log folder), then giving appropriate permissions with chmod
command.
In my case I had the following gem rails_12factor
in my Gemfile
for production.
So I had to
- Remove
rails_12factor
from my Gemfile gem uninstall rails_12factor
bundle install
And on the next push to production the logs worked for me. FYI: I am using rails 5.2.1, but the rails web app started in rails 3.
Low memory is the most likely cause that I have been able to come up with. I will post here if I can prove it.
I solved the Problem by putting
Rails.logger.instance_variable_get(:@logger).instance_variable_get(:@log_dest).sync = true if Rails.logger
into my config/initializers/...
I was having the same problem. Tried everything out there on this website.
Finally i checked the value of Rails.logger
in console. It gave following output.
#<RailsStdoutLogging::StdoutLogger:0x00007fe3b5bc3540
@default_formatter=#<Logger::Formatter:0x00007fe3b5bc3658 @datetime_format=nil>,
@formatter=#<ActiveSupport::Logger::SimpleFormatter:0x00007fe3b5bc34c8 @datetime_format=nil>,
@level=0,
@logdev=
#<Logger::LogDevice:0x00007fe3b5bc3608
@dev=#<IO:<STDOUT>>,
@filename=nil,
@mon_count=0,
@mon_mutex=#<Thread::Mutex:0x00007fe3b5bc35b8>,
@mon_mutex_owner_object_id=70307991657220,
@mon_owner=nil,
@shift_age=nil,
@shift_period_suffix=nil,
@shift_size=nil>,
@progname=nil>
Then I crosschecked with some other rails project and that gave the below output
#<ActiveSupport::Logger:0x00005566367b77c0 @level=0,
@progname=nil,
@default_formatter=#<Logger::Formatter:0x00005566367b7950 @datetime_format=nil>, @formatter=#<Logger::Formatter:0x00005566367b7770 @datetime_format=nil>,
@logdev=#<Logger::LogDevice:0x00005566367b7900 @shift_period_suffix=nil, @shift_size=nil,
@shift_age=nil, @filename=nil,
@dev=#<File:/home/rajanverma/workspace/aarvy/log/production.log>,
@mon_mutex=#<Thread::Mutex:0x00005566367b7888>, @mon_mutex_owner_object_id=46948744543360,
@mon_owner=nil, @mon_count=0>>
You can clearly see that both projects were using different loggers to show output. I don't want to output log on STDOUT so I changed my logger to ActiveSupport by creating an initializer file.
config/initializer/logger.rb
Rails.logger = ActiveSupport::Logger.new('log/production.log')
Now it started logging on production.log.
EDIT: I tried doing the same in production.rb
, but don't know why it always got overwritten. So i decided to put in initializer. I don't know weather it has any performance issues. Also I don't know how it was changing automatically to #<RailsStdoutLogging::StdoutLogger:0x00007fe3b5bc3540
as writing on production.log should be a default behaviour. Please let me know if you know better reason.
I had the same problem related to production log.
To trace back issue with web server:
tail -f /var/log/apache2/error.log
Message from application: Permission denied - /var/www/APPLICATION-NAME/log/invitation.log (Errno::EACCES)
cd /var/www/APPLICATION-NAME/log
using the comman ll you will get log permissions
total 28
drwxr-sr-x 2 www-data www-data 4096 Sep 18 03:55 ./
drwxrwsr-x 14 www-data www-data 4096 Sep 24 23:52 ../
-rw-r--r-- 1 root www-data 71 Sep 18 03:55 agent_invitation.log
-rwxrwxrwx 1 root www-data 71 Sep 18 03:55 email.log*
-rw-r--r-- 1 root www-data 71 Sep 18 03:55 invitation.log
-rw-r--r-- 1 root www-data 71 Sep 18 03:55 messages.log
-rw-r--r-- 1 root www-data 51 Sep 13 01:32 production.log
Solution: Have to change owner from root to other user:
chown www-data:www-data ./ -R
Now use ll
to see the permissions
total 28
drwxr-sr-x 2 www-data www-data 4096 Sep 18 03:55 ./
drwxrwsr-x 14 www-data www-data 4096 Sep 24 23:52 ../
-rw-r--r-- 1 www-data www-data 71 Sep 18 03:55 agent_invitation.log
-rwxrwxrwx 1 www-data www-data 71 Sep 18 03:55 email.log*
-rw-r--r-- 1 www-data www-data 71 Sep 18 03:55 invitation.log
-rw-r--r-- 1 www-data www-data 71 Sep 18 03:55 messages.log
-rw-r--r-- 1 www-data www-data 51 Sep 13 01:32 production.log
Restart you web server:
sudo service apache2 restart
now check production logs.
精彩评论