diff --git a/config/environments/development.rb b/config/environments/development.rb index 2d28df12..52107cc6 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -3,6 +3,14 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. + # Logging configuration + require "dev_logger" + config.log_formatter = DevLogger.new("soils-ag-wx") + config.log_level = :debug + + # Log error messages when you accidentally call methods on nil. + config.whiny_nils = true + # In the development environment your application's code is reloaded any time # it changes. 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. @@ -38,10 +46,7 @@ # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false - config.action_mailer.perform_caching = false - - # Letter opener config config.action_mailer.delivery_method = :letter_opener config.action_mailer.default_url_options = {host: "localhost:3000"} diff --git a/config/environments/production.rb b/config/environments/production.rb index 8e007510..177e362d 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -70,18 +70,13 @@ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true - # Log to STDOUT by default - config.logger = ActiveSupport::Logger.new($stdout) - .tap { |logger| logger.formatter = ::Logger::Formatter.new } - .then { |logger| ActiveSupport::TaggedLogging.new(logger) } - # Prepend all log lines with the following tags. config.log_tags = [:request_id] # Info include generic and useful information about system operation, but avoids logging too much # information to avoid inadvertent exposure of personally identifiable information (PII). If you # want to log everything, set the level to "debug". - config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") + config.log_level = :info # Use a different cache store in production. # config.cache_store = :mem_cache_store diff --git a/config/environments/staging.rb b/config/environments/staging.rb index e3c154f5..fb51eacb 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -1,10 +1,11 @@ -# Just use the production settings +# Load production defaults require File.expand_path("../production.rb", __FILE__) -# Overwrite production defaults +# Staging settings Rails.application.configure do config.action_mailer.default_url_options = { host: ENV["AG_WEATHER_HOST"] || "dev.agweather.cals.wisc.edu", protocol: "https" } + config.log_level = :debug end diff --git a/lib/dev_logger.rb b/lib/dev_logger.rb new file mode 100644 index 00000000..bdede139 --- /dev/null +++ b/lib/dev_logger.rb @@ -0,0 +1,41 @@ +# custom color-coded logging +class DevLogger < Logger::Formatter + PAL = { + black: "\u001b[30m", + red: "\u001b[31m", + green: "\u001b[32m", + yellow: "\u001b[33m", + blue: "\u001b[34m", + magenta: "\u001b[35m", + cyan: "\u001b[36m", + white: "\u001b[37m", + reset: "\u001b[0m" + } + + SEV = { + debug: "DBG", + info: "NFO", + warn: "WRN", + error: "ERR", + fatal: "FTL", + unknown: "UNK" + } + + CLR = { + debug: PAL[:green], + info: PAL[:white], + warn: PAL[:yellow], + error: PAL[:red], + fatal: PAL[:red] + } + + def initialize(app_name = "dev") + @app = app_name + end + + def call(severity, time, progname, msg) + sev = severity.to_sym.downcase + msg = msg&.truncate(500, omission: "...") + "#{CLR[sev]}[#{@app} #{SEV[sev]}] #{msg}#{PAL[:reset]}\n" + end +end