Commit 35dec2c3 authored by Stan Hu's avatar Stan Hu

Use a custom GrapeLogging formatter to get the timestamp

parent c304dfd4
......@@ -5,8 +5,8 @@ module API
LOG_FILENAME = Rails.root.join("log", "api_json.log")
use GrapeLogging::Middleware::RequestLogger,
logger: ::Gitlab::ApiLogger.new(LOG_FILENAME),
formatter: GrapeLogging::Formatters::Json.new,
logger: Logger.new(LOG_FILENAME),
formatter: Gitlab::GrapeLogging::Formatters::LogrageWithTimestamp.new,
include: [
GrapeLogging::Loggers::Response.new,
GrapeLogging::Loggers::FilterParameters.new,
......
module Gitlab
class ApiLogger < ::Logger
def format_message(severity, timestamp, progname, message)
super + "\n"
end
end
end
module Gitlab
module GrapeLogging
module Formatters
class LogrageWithTimestamp
def call(severity, datetime, _, data)
time = data.delete :time
attributes = {
time: datetime.utc.iso8601(3),
severity: severity,
duration: time[:total],
db: time[:db],
view: time[:view]
}.merge(data)
::Lograge.formatter.call(attributes) + "\n"
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment