class Rsg::Generators::Logging::CommonGenerator

Public Instance Methods

adjust_prod() click to toggle source
# File lib/rsg/generators/logging/common_generator.rb, line 28
def adjust_prod
  comment_lines "config/environments/production.rb", /^(\s*)(config\.log_level .+)$/
  gsub_file "config/environments/production.rb",
    'ENV["RAILS_LOG_TO_STDOUT"].present?',
    "config.x.log_to_stdout"
end
banner() click to toggle source
log_level_env_var() click to toggle source
# File lib/rsg/generators/logging/common_generator.rb, line 6
  def log_level_env_var
    inject_into_file "config/application.rb", <<-CODE, before: /^  end$/
\n    # Sane default log levels per env, but able to tweak with env var
    # NOTE: Settings on config/environments/*.rb take precedence over this
    config.log_level = ENV.fetch('LOG_LEVEL') { Rails.env.development? ? 'debug' : 'info' }.to_sym

    # Log to stdout most of the time and allow use of JSON logs in dev by using an env var
    config.x.log_to_stdout = %w[1 true yes].include?(ENV.fetch('RAILS_LOG_TO_STDOUT', '1'))
    CODE
  end
stdout_logging_in_dev() click to toggle source
# File lib/rsg/generators/logging/common_generator.rb, line 17
  def stdout_logging_in_dev
    inject_into_file "config/environments/development.rb", <<-CODE, before: /^end$/
\n  # Configure stdout logging in dev as well
  if config.x.log_to_stdout
    logger = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger = ActiveSupport::TaggedLogging.new(logger)
  end
    CODE
  end