Module: Shrine::Plugins::Logging::ClassMethods

Defined in:
lib/shrine/plugins/logging.rb

Instance Method Summary collapse

Instance Method Details

#create_loggerObject



36
37
38
39
40
41
42
# File 'lib/shrine/plugins/logging.rb', line 36

def create_logger
  logger = Logger.new(opts[:logging_stream])
  logger.level = Logger::INFO
  logger.level = Logger::WARN if ENV["RACK_ENV"] == "test"
  logger.formatter = pretty_formatter
  logger
end

#loggerObject



32
33
34
# File 'lib/shrine/plugins/logging.rb', line 32

def logger
  @logger ||= opts[:logging_logger]
end

#logger=(logger) ⇒ Object



28
29
30
# File 'lib/shrine/plugins/logging.rb', line 28

def logger=(logger)
  @logger = logger
end

#pretty_formatterObject

It makes logging preamble simpler than the default logger. Also, it doesn’t output timestamps if on Heroku.



46
47
48
49
50
51
52
# File 'lib/shrine/plugins/logging.rb', line 46

def pretty_formatter
  proc do |severity, time, program_name, message|
    output = "#{Process.pid}: #{message}\n".dup
    output.prepend "#{time.utc.iso8601(3)} " unless ENV["DYNO"]
    output
  end
end