Sha256: efbea0dc7309ce9742b5af39552c09c04b2d4483aa9af59ce1a8850096fd5c6a

Contents?: true

Size: 931 Bytes

Versions: 9

Compression:

Stored size: 931 Bytes

Contents

# Logger formatter with timestamp and color
# source: https://cbpowell.wordpress.com/2013/08/09/beautiful-logging-for-ruby-on-rails-4
#

class ActiveSupport::Logger::SimpleFormatter
  SEVERITY_TO_COLOR_MAP = { 'DEBUG'=>'0;37', 'INFO'=>'32', 'WARN'=>'33', 'ERROR'=>'31', 'FATAL'=>'31', 'UNKNOWN'=>'37' }

  def call(severity, time, progname, msg)
    formatted_severity = sprintf("%-5s",severity)
    formatted_time = time.strftime("%d.%m.%Y %H:%M:%S.") << time.usec.to_s[0..2].rjust(3)
    color = SEVERITY_TO_COLOR_MAP[severity]
    "\033[0;37m#{formatted_time}\033[0m [\033[#{color}m#{formatted_severity}\033[0m] #{msg.strip} (pid:#{$$})\n"
  end
end

# Use lograge to log single line per request
Rails.application.config.lograge.enabled = true
Rails.application.config.lograge.custom_options = lambda do |event|
  exceptions = %w(controller action format id)
  {
      params: event.payload[:params].except(*exceptions)
  }
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
railman-1.0.6 templates/rails_app/config/initializers/log_formatting.rb
railman-1.0.5 templates/rails_app/config/initializers/log_formatting.rb
railman-1.0.4 templates/rails_app/config/initializers/log_formatting.rb
railman-1.0.3 templates/rails_app/config/initializers/log_formatting.rb
railman-1.0.2 templates/rails_app/config/initializers/log_formatting.rb
railman-1.0.1 templates/rails_app/config/initializers/log_formatting.rb
railman-1.0.0 templates/rails_app/config/initializers/log_formatting.rb
railman-0.6.20 templates/rails_app/config/initializers/log_formatting.rb
railman-0.6.19 templates/rails_app/config/initializers/log_formatting.rb