mirror of
https://github.com/samsonjs/grape_logging.git
synced 2026-04-14 12:15:46 +00:00
33 lines
614 B
Ruby
33 lines
614 B
Ruby
module GrapeLogging
|
|
module Formatters
|
|
class Json
|
|
def call(severity, datetime, _, data)
|
|
{
|
|
date: datetime,
|
|
severity: severity,
|
|
data: format(data)
|
|
}.to_json
|
|
end
|
|
|
|
private
|
|
|
|
def format(data)
|
|
if data.is_a?(String) || data.is_a?(Hash)
|
|
data
|
|
elsif data.is_a?(Exception)
|
|
format_exception(data)
|
|
else
|
|
data.inspect
|
|
end
|
|
end
|
|
|
|
def format_exception(exception)
|
|
{
|
|
exception: {
|
|
message: exception.message
|
|
}
|
|
}
|
|
end
|
|
end
|
|
end
|
|
end
|