Unable to generate logs after running rails s - ruby-on-rails

After running the rails s i cannot see logs on the terminal the code is working properly without any issue. The logs are getting generated logs/development.log file As there are no logs i am unable to use debugger
=> Booting Puma
=> Rails 5.2.3 application starting in development
=> Run `rails server -h` for more startup options
[95163] Puma starting in cluster mode...
[95163] * Version 4.1.1 (ruby 2.4.6-p354), codename: Fourth and One
[95163] * Min threads: 2, max threads: 2
[95163] * Environment: development
[95163] * Process workers: 2
[95163] * Phased restart available
[95163] * Listening on tcp://localhost:3000
[95163] Use Ctrl-C to stop
config/dvelopment.log file
Rails.application.configure do
config.active_storage.service = :local
config.action_mailer.perform_caching = false
config.assets.debug = true
config.assets.quiet = true
config.assets.raise_runtime_errors = true
config.action_mailer.default_url_options = {
host: Rails.application.secrets[:mailer_options][:host],
port: Rails.application.secrets[:mailer_options][:port],
}
# ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
config.lograge.enabled = true
config.log_level = :debug
config.lograge.formatter = Lograge::Formatters::Logstash.new
config.lograge.custom_options = lambda do |event|
{
:time => Time.now.in_time_zone(Time.zone),
:params => event.payload[:params].reject { |k| %w(controller action).include? k },
:subdomain => event.payload[:subdomain],
:remote_ip => event.payload[:remote_ip],
:user_agent => event.payload[:user_agent],
:uuid => event.payload[:uuid],
:current_user => (event.payload[:current_user])? event.payload[:current_user][:id] : nil,
:current_appuser => (event.payload[:current_appuser])? event.payload[:current_appuser][:id] : nil
}
end
config.lograge.ignore_actions = ['PublicPagesController#status_check']
config.logger = ActiveSupport::Logger.new(config.paths['log'].first, 7, 204857600)
require "awesome_print"
end

When you want to log to STDOUT in development environment instead of into a log file, then change this line in your config/environments/development.rb
config.logger = ActiveSupport::Logger.new(config.paths['log'].first, 7, 204857600)
to
config.logger = Logger.new(STDOUT)

Related

NoMethodError in Solidus when using external storage service

I have a vanilla Solidus installation (ruby 3.0 | rails 6.1.5)
I'm using the edge guide to test a deployment on Heroku. I get the following error on my local machine if I configure active storage to use :amazon in my storage.yml file.
The remote deployment also results in an error. Running heroku logs --tail gives the following error in my Terminal:
from /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
2022-03-24T21:23:47.656577+00:00 app[web.1]: from bin/rails:5:in `<main>'
2022-03-24T21:23:47.825835+00:00 heroku[web.1]: Process exited with status 1
2022-03-24T21:23:47.876809+00:00 heroku[web.1]: State changed from starting to crashed
2022-03-24T21:23:47.885875+00:00 heroku[web.1]: State changed from crashed to starting
2022-03-24T21:23:54.753814+00:00 heroku[web.1]: Starting process with command `bin/rails server -p ${PORT:-5000} -e production`
2022-03-24T21:23:59.021982+00:00 app[web.1]: => Booting Puma
2022-03-24T21:23:59.022013+00:00 app[web.1]: => Rails 6.1.5 application starting in production
2022-03-24T21:23:59.022013+00:00 app[web.1]: => Run `bin/rails server --help` for more startup options
2022-03-24T21:24:00.921589+00:00 app[web.1]: Exiting
2022-03-24T21:24:00.922353+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/activestorage-6.1.5/lib/active_storage/service/configurator.rb:17:in `build': undefined method `fetch' for nil:NilClass (NoMethodError)
2022-03-24T21:24:00.922355+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.0.0/gems/activestorage-6.1.5/lib/active_storage/service/registry.rb:13:in `block in fetch'
There are no errors if I configure active storage to use the local disk. Appreciate any assistance or insight.
Update:
Storage.ymltest:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
local:
service: Disk
root: <%= Rails.root.join("storage") %>
amazon:
service:S3
access_key_id: ""
secret_access_key:
region:
bucket:
Config/environment/production.rb
require "active_support/core_ext/integer/time"
Rails.application.configure do
config.cache_classes = true
config.active_storage.service = :amazon
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.compile = false
config.log_level = :info
config.log_tags = [ :request_id ]
config.action_mailer.perform_caching = false
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.active_support.disallowed_deprecation = :log
config.active_support.disallowed_deprecation_warnings = []
config.log_formatter = ::Logger::Formatter.new
ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter=config.log_formatter
config.logger=ActiveSupport::TaggedLogging.new(logger)
end
config.active_record.dump_schema_after_migration = false

Setting up database for the first time in ruby on rails

I am very much fresh in using Ruby on rails. I have cloned a git repo and trying to set up a PostgreSQL database in my local machine(Win 10).
Ruby version- 2.4.10
Rails - 5.2.0
I am using the below command
rake db:setup RAILS_ENV=development
Error Output -
rake aborted!
NoMethodError: undefined method `[]' for nil:NilClass
D:/ruby/reserves/config/environments/development.rb:41:in `block in <top (required)>'
D:/ruby/reserves/config/environments/development.rb:1:in `<top (required)>'
D:/ruby/reserves/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:setup => db:schema:load_if_ruby => db:create => db:load_config => environment
(See full trace by running task with --trace)
In database.yml file there are three environments has been declared - Development/Production/test
development:
<<: *default
database: reserves-dev
username:****
password:****
host: localhost
/config/environments/development.rb:
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
if Rails.root.join('tmp', 'caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{2.days.to_i}"
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
# Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local
# Email
config.action_mailer.perform_caching = false
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.smtp_settings = {
address: Rails.application.credentials[Rails.env.to_sym][:mailer][:address],
port: Rails.application.credentials[Rails.env.to_sym][:mailer][:port],
user_name: Rails.application.credentials[Rails.env.to_sym][:mailer][:username],
password: Rails.application.credentials[Rails.env.to_sym][:mailer][:password],
domain: Rails.application.credentials[Rails.env.to_sym][:mailer][:domain],
authentication: :plain
}
# NOTE: For email need to have authentication :login (instead of :plain) and
# the tls: true param, otherwise the server times out on password reset request.
Rails.application.config.middleware.use ExceptionNotification::Rack,
:ignore_crawlers => %w{Googlebot bingbot},
:ignore_exceptions => ['ActionController::InvalidCrossOriginRequest'] + ExceptionNotifier.ignored_exceptions,
:email => {
:email_prefix => "[ERROR] ",
:sender_address => %{"Arc Reserves" <noreply#*****.com>},
:exception_recipients => %w{info#****.com}
}
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Suppress logger output for asset requests.
config.assets.quiet = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end
How can I set the environment variable to development for setting the database in my local.
Any help is highly appreciated.
Thank you in advance.
Most likely this is because of the lines like:
Rails.application.credentials[Rails.env.to_sym][:mailer][:address]
Could you change it to something like that?
Rails.application.credentials.dig(:mailer, :address)

Rails 5.2 and Sidekiq 5: Errno::EADDRNOTAVAIL: Cannot assign requested address - connect(2) for "localhost" port 25

I'm trying to deliver e-mails with Sidekiq and deliver_later.
In my config/sidekiq.yml I have:
:verbose: true
:concurrency: 25
:queues:
- [mailers, 7]
- [critical, 6]
- [default, 5]
- [low, 4]
In my worker I try do do it with:
Buyer::OffersMailer.instant_for_published_offer(info_to_deliver).deliver_later
I see in Sidekiq admin panel my mailer job is stuck in "Retries" with this error:
Errno::EADDRNOTAVAIL: Cannot assign requested address - connect(2) for "localhost" port 25
My app can send deliver_now e-mails, which I believe rejects assumption that something could be wrong with SMPTP Any ideas, what could be wrong?
Update
In addition emails are not delivered in Production, where my config looks like this:
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_url_options = { host: "https://myapp.com" }
config.action_mailer.asset_host = "https://myapp.com"
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => 'myval',
:port => '587',
:authentication => :plain,
:user_name => 'myval',
:password => Rails.application.credentials.mailgun_smtp_pass,
:enable_starttls_auto => true
}
Since your emails are sent correctly using #deliver_now method, this means that your Mailer config is just fine. Now that aside you should have this in your application.rb config file:
config.active_job.queue_adapter = :sidekiq
and in config\initializers\sidekiq.rb you need to have Redis URL to be configured:
Sidekiq.configure_server do |config|
config.redis = { url: (ENV["REDIS_URL"] || 'redis://localhost:6379/0') }
end
Sidekiq.configure_client do |config|
config.redis = { url: (ENV["REDIS_URL"] || 'redis://localhost:6379/0') }
end
Error in production was due to environment settings in Procfile. As of Sidekiq docs in my case worked RAILS_ENV=production
So my working procfile looks like this:
main_worker: bundle exec sidekiq RAILS_ENV=production
Don't forget to scale your worker if you're using Heroku or Dokku.

Postmark mailing on localhost and staging problem

After I configure to use postmark service to post emails I'm facing some troubles with development and staging envs.
Short explanation: portmark is working nice in the below situations with 'ok', and when there is DeserializationError it seems that the active job is failing because it is looking to see if the user id exists on production database.
Development env:
devise mailing -> ActiveJob::DeserializationError
deliver_later -> ActiveJob::DeserializationError
delover_now -> ok
Staging env
devise mailing -> ActiveJob::DeserializationError
deliver_later -> ActiveJob::DeserializationError
delover_now -> ok
production env
devise mailing -> ok
deliver_later -> ok
deliver_now -> ok
Long explanation:
When I'm on these two envs and requests with devise the confirmation instructions, it sends a link to this email with a production url with the token attached to it which points to wrong page.
The most intriguing thing is that after I send an email from development or staging envs console, and I opened up sidekiq dashboard and I found out that when there is no user id on production associated with the id that this email was requested to send (from the other envs), this mailing fails with this message:
Console:
> Rails.env
"development"
> #user.id
22
> UserMailer.welcome(#user).deliver_later
Sidekiq error:
ActiveJob::DeserializationError: Error while trying to deserialize
arguments: Couldn't find User with 'id'=22
Console:
> Rails.env
"staging"
> #user.id
15
> UserMailer.welcome(#user).deliver_later
Sidekiq error:
ActiveJob::DeserializationError: Error while trying to deserialize
arguments: Couldn't find User with 'id'=15
Some configs:
Rails 5.0.1
postmark (1.14.0)
postmark-rails (0.18.0)
production.rb
...
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_token => ENV["POSTMARK_API_KEY"] }
config.action_mailer.default_url_options = { host: "www.mywebsite.com" }
...
development.rb
...
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_token => ENV["POSTMARK_API_KEY"] }
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
...
staging.rb
...
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_token => ENV["POSTMARK_API_KEY"] }
config.action_mailer.default_url_options = { host: "website.herokuapp.com" }
...
sidekiq.yml
:concurrency: 3
:timeout: 60
:verbose: true
:queues:
- default
- mailers
Obs: all the three environments uses different postmark api key.
UPDATE 1
Here is the development:
development.rb
Rails.application.configure do
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_token => ENV["POSTMARK_API_KEY"] }
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.cache_classes = false
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800'
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
config.assets.precompile += %w( '.svg' )
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Suppress logger output for asset requests.
config.assets.quiet = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end
I changed to the old configuration with gmail and the problem persists...
development.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.action_mailer.delivery_method = :letter_opener
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800'
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
config.assets.precompile += %w( '.svg' )
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Suppress logger output for asset requests.
config.assets.quiet = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: 'gmail.com',
user_name: ENV['GMAIL_ADDRESS'],
password: ENV['GMAIL_APP_PASSWORD'],
authentication: "plain",
enable_starttls_auto: true
}
config.action_mailer.default_url_options = {host: "localhost:3000"}
end
UPDATE 2:
I also tried to go to past branches which the mailing was working and nothing (I restarted the server)...
This is a partial solution to make possible to use mailing on test envs in my case.
On this rails mailing documentation on topic 10.2 Deserialization says:
If a passed record is deleted after the job is enqueued but before the #perform method is called Active Job will raise an ActiveJob::DeserializationError exception.
So I realized that somehow the record has being deleted from cache before the sending method (deliver_later) takes action. If this is going only on development and staging environments, then I attached on:
production.rb
config.active_job.queue_adapter = :sidekiq
development.rb / staging.rb
config.active_job.queue_adapter = :inline

Ruby on Rails Webrick server on HTTPS protocol stopped after few hours

I am using the below environments:
Server: Webrick
Rails: 3.2.6
Ruby: 1.9.3p555
I have added the below code in /script/rails :
require 'rails/commands/server'
require 'rack'
require 'webrick'
require 'webrick/https'
if ENV['SSL'] == "true"
module Rails
class Server < ::Rack::Server
def default_options
super.merge({
:Port => 443,
:environment => (ENV['RAILS_ENV'] || "production").dup,
:daemonize => false,
:debugger => false,
:pid => File.expand_path("tmp/pids/server.pid"),
:config => File.expand_path("config.ru"),
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLPrivateKey => OpenSSL::PKey::RSA.new(
File.open("certs/project.key").read),
:SSLCertificate => OpenSSL::X509::Certificate.new(
File.open("certs/project.crt").read),
:SSLCertName => [["CN", WEBrick::Utils::getservername]],
})
end
end
end
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
I have added the below line in /config/environments/production.rb:
config.force_ssl = true
Start rails on 80 and 443 both using two different pid:
SSL=true rails s -p 443 -e production
rails s -p 80 -P SERVER2 -e production
Everything is working fine however after 10-12 hours https protocol stop to respond to the browser and even there is nothing add in the log file.
Could you please confirm what is the issue and how could it be corrected?

Resources