mirror of
https://github.com/czhu12/canine.git
synced 2025-12-20 10:19:50 -06:00
29 lines
514 B
Ruby
29 lines
514 B
Ruby
module Loggable
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
has_many :log_outputs, as: :loggable, dependent: :delete_all
|
|
end
|
|
|
|
def info(line, color: nil)
|
|
color = LogColorsHelper::FRIENDLY_COLORS[color]
|
|
output = "\e[#{color}m#{line}\e[0m"
|
|
Rails.logger.info(line)
|
|
self.log_outputs.create(output: output)
|
|
end
|
|
|
|
def error(line)
|
|
info(line, color: :red)
|
|
end
|
|
|
|
def success(line)
|
|
info(line, color: :green)
|
|
end
|
|
|
|
def warn(line)
|
|
info(line, color: :orange)
|
|
end
|
|
|
|
private
|
|
end
|