Skip to content

Commit

Permalink
added log_level option; using debug log level by default
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianopol committed May 2, 2024
1 parent 83db6e4 commit 830db18
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions lib/paperclip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class << self
# an uploaded image. Defaults to true.
# * log: Logs progress to the Rails log. Uses ActiveRecord's logger, so honors
# log levels, etc. Defaults to true.
# * log_level: Log level according to ActiveRecord's logger. Possible values: :debug,
# :info, :warn, :error, :fatal. Defaults to :debug.
# * command_path: Defines the path at which to find the command line
# programs if they are not visible to Rails the system's search path. Defaults to
# nil, which uses the first executable found in the user's search path.
Expand All @@ -74,6 +76,7 @@ def options
:image_magick_path => nil,
:command_path => nil,
:log => true,
:log_level => :debug,
:log_command => false,
:swallow_stderr => true
}
Expand Down Expand Up @@ -128,18 +131,10 @@ def processor name #:nodoc:
processor
end

# Log a paperclip-specific line. Uses ActiveRecord::Base.logger
# Log a paperclip-specific line with a given log level. Uses ActiveRecord::Base.logger
# by default. Set Paperclip.options[:log] to false to turn off.
def log message
logger.info("[paperclip] #{message}") if logging?
end

def logger #:nodoc:
ActiveRecord::Base.logger
end

def logging? #:nodoc:
options[:log]
def log(message)
ActiveRecord::Base.logger.send(options[:log_level], "[paperclip] #{message}") if options[:log]
end
end

Expand Down Expand Up @@ -315,7 +310,7 @@ def each_attachment
end

def save_attached_files
logger.info("[paperclip] Saving attachments.")
log("saving attachments")
each_attachment do |name, attachment|
attachment.send(:save)
# переехало сюда из delayed_paperclip process_in_background. нужно чтобы порядок загрузки - обработки
Expand All @@ -325,16 +320,16 @@ def save_attached_files
end

def destroy_attached_files
logger.info("[paperclip] Deleting attachments.")
log("deleting attachments")
each_attachment do |_name, attachment|
attachment.send(:queue_existing_for_delete)
attachment.send(:flush_deletes)
end
logger.info("[paperclip] Finish deleting attachments.")
log("finish deleting attachments")
end

def flush_attachment_jobs
logger.info("[paperclip] flushing jobs.")
log("flushing jobs")
each_attachment do |_name, attachment|
attachment.try(:flush_jobs)
end
Expand Down

0 comments on commit 830db18

Please sign in to comment.