Class: Rsg::Generators::Logging::CommonGenerator
- Inherits:
-
Base
- Object
- Base
- Rsg::Generators::Logging::CommonGenerator
- Defined in:
- lib/rsg/generators/logging/common_generator.rb
Instance Method Summary collapse
Instance Method Details
#adjust_prod ⇒ Object
28 29 30 31 32 33 |
# 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 ⇒ Object
2 3 4 |
# File 'lib/rsg/generators/logging/common_generator.rb', line 2 def say "Improving basic logging configs" end |
#log_level_env_var ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# 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 ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# 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 |