debian-mirror-gitlab/lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.4 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module Gitlab
module GrapeLogging
module Formatters
class LogrageWithTimestamp
2018-11-08 19:23:39 +05:30
include Gitlab::EncodingHelper
2020-04-08 14:13:33 +05:30
EMPTY_ARRAY = [].freeze
2018-03-17 18:26:18 +05:30
def call(severity, datetime, _, data)
time = data.delete :time
2018-12-13 13:39:08 +05:30
data[:params] = process_params(data)
2018-11-08 19:23:39 +05:30
2018-03-17 18:26:18 +05:30
attributes = {
time: datetime.utc.iso8601(3),
severity: severity,
2020-04-22 19:07:51 +05:30
duration_s: Gitlab::Utils.ms_to_round_sec(time[:total]),
db_duration_s: Gitlab::Utils.ms_to_round_sec(time[:db]),
view_duration_s: Gitlab::Utils.ms_to_round_sec(time[:view])
2020-04-08 14:13:33 +05:30
}.merge!(data)
::Lograge.formatter.call(attributes) << "\n"
2018-03-17 18:26:18 +05:30
end
2018-11-08 19:23:39 +05:30
private
2018-12-13 13:39:08 +05:30
def process_params(data)
2020-04-08 14:13:33 +05:30
return EMPTY_ARRAY unless data.has_key?(:params)
2018-12-13 13:39:08 +05:30
2020-04-08 14:13:33 +05:30
params_array = data[:params].map { |k, v| { key: k, value: utf8_encode_values(v) } }
2020-03-13 15:44:24 +05:30
2020-04-08 14:13:33 +05:30
Gitlab::Utils::LogLimitedArray.log_limited_array(params_array, sentinel: Gitlab::Lograge::CustomOptions::LIMITED_ARRAY_SENTINEL)
2018-12-13 13:39:08 +05:30
end
2018-11-08 19:23:39 +05:30
def utf8_encode_values(data)
case data
when Hash
2020-04-08 14:13:33 +05:30
data.merge!(data) { |k, v| utf8_encode_values(v) }
2018-11-08 19:23:39 +05:30
when Array
2020-04-08 14:13:33 +05:30
data.map! { |v| utf8_encode_values(v) }
2018-11-08 19:23:39 +05:30
when String
encode_utf8(data)
2021-01-29 00:20:46 +05:30
when Integer
data
2018-11-08 19:23:39 +05:30
end
end
2018-03-17 18:26:18 +05:30
end
end
end
end