From 8d65e7db95ff222c02599807c0d4ba7a970f0ccc Mon Sep 17 00:00:00 2001 From: Sojan Date: Wed, 18 Mar 2020 01:40:34 +0530 Subject: [PATCH] HotFix: Tune the chatwoot logs Fixes : #616 --- .env.example | 4 ++++ config/environments/development.rb | 7 +++++++ config/environments/production.rb | 7 +++---- config/environments/staging.rb | 7 +++---- .../project-setup/environment-variables.md | 12 ++++++++++++ 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index 5bcb4ac9e..566ed8dff 100644 --- a/.env.example +++ b/.env.example @@ -58,6 +58,10 @@ AWS_REGION= #sentry SENTRY_DSN= +#Log settings +LOG_LEVEL= +LOG_SIZE= + # Credentials to access sidekiq dashboard in production SIDEKIQ_AUTH_USERNAME= SIDEKIQ_AUTH_PASSWORD= diff --git a/config/environments/development.rb b/config/environments/development.rb index 5ef763329..a9b30a68f 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -93,6 +93,13 @@ Rails.application.configure do # Disable host check during development config.hosts = nil + # customize using the environment variables + config.log_level = ENV.fetch('LOG_LEVEL', 'debug').to_sym + + # Use a different logger for distributed setups. + # require 'syslog/logger' + config.logger = ActiveSupport::Logger.new(Rails.root.join('log', Rails.env + '.log'), 1, ENV.fetch('LOG_SIZE', '1024').to_i.megabytes) + # Bullet configuration to fix the N+1 queries config.after_initialize do Bullet.enable = true diff --git a/config/environments/production.rb b/config/environments/production.rb index cf3cdca21..21d957588 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -41,9 +41,8 @@ Rails.application.configure do # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. config.force_ssl = ENV.fetch('FORCE_SSL', false) - # Use the lowest log level to ensure availability of diagnostic information - # when problems arise. - config.log_level = :debug + # customize using the environment variables + config.log_level = ENV.fetch('LOG_LEVEL', 'info').to_sym # Prepend all log lines with the following tags. config.log_tags = [:request_id] @@ -85,7 +84,7 @@ Rails.application.configure do # Use a different logger for distributed setups. # require 'syslog/logger' - # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + config.logger = ActiveSupport::Logger.new(Rails.root.join('log', Rails.env + '.log'), 1, ENV.fetch('LOG_SIZE', '1024').to_i.megabytes) if ENV['RAILS_LOG_TO_STDOUT'].present? logger = ActiveSupport::Logger.new(STDOUT) diff --git a/config/environments/staging.rb b/config/environments/staging.rb index e61986459..b0bdc71ec 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -42,9 +42,8 @@ Rails.application.configure do # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. config.force_ssl = ENV.fetch('FORCE_SSL', false) - # Use the lowest log level to ensure availability of diagnostic information - # when problems arise. - config.log_level = :debug + # customize using the environment variables + config.log_level = ENV.fetch('LOG_LEVEL', 'info').to_sym # Prepend all log lines with the following tags. config.log_tags = [:request_id] @@ -85,7 +84,7 @@ Rails.application.configure do # Use a different logger for distributed setups. # require 'syslog/logger' - # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + config.logger = ActiveSupport::Logger.new(Rails.root.join('log', Rails.env + '.log'), 1, ENV.fetch('LOG_SIZE', '1024').to_i.megabytes) if ENV['RAILS_LOG_TO_STDOUT'].present? logger = ActiveSupport::Logger.new(STDOUT) diff --git a/docs/development/project-setup/environment-variables.md b/docs/development/project-setup/environment-variables.md index 0e17c9ba4..3fa4a61cd 100644 --- a/docs/development/project-setup/environment-variables.md +++ b/docs/development/project-setup/environment-variables.md @@ -102,3 +102,15 @@ SECRET_KEY_BASE=replace_with_your_own_secret_string You can generate `SECRET_KEY_BASE` using `rake secret` command from project root folder. +### Rails Logging Variables + +By default chatwoot will capture `info` level logs in production. Ref [rails docs](https://guides.rubyonrails.org/debugging_rails_applications.html#log-levels) for the additional log level options. +We will also retain 1 GB of your recent logs and your last shifted log file. +You can fine tune these settings using the following environment variables + +```bash +# possible values: 'debug', 'info', 'warn', 'error', 'fatal' and 'unknown' +LOG_LEVEL= +# value in megabytes +LOG_SIZE= 1024 +``` \ No newline at end of file