Skip to content

Commit 12e2f7e

Browse files
committed
Use to_yaml for formatting objects in logs
1 parent 48c4cad commit 12e2f7e

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

‎plugin.rb

+29-11
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ def request(env)
5151
warn <<~LOG
5252
OAuth2 Debugging: request #{env.method.upcase} #{env.url.to_s}
5353
54-
Headers: #{env.request_headers}
54+
Headers:
55+
#{env.request_headers.to_yaml}
5556
56-
Body: #{env[:body]}
57+
Body:
58+
#{env[:body].to_yaml}
5759
LOG
5860
end
5961

@@ -63,9 +65,11 @@ def response(env)
6365
6466
From #{env.method.upcase} #{env.url.to_s}
6567
66-
Headers: #{env.response_headers}
68+
Headers:
69+
#{env.request_headers.to_yaml}
6770
68-
Body: #{env[:body]}
71+
Body:
72+
#{env[:body].to_yaml}
6973
LOG
7074
end
7175
end
@@ -223,19 +227,22 @@ def fetch_user_details(token, id)
223227
user_json_url = SiteSetting.oauth2_user_json_url.sub(":token", token.to_s).sub(":id", id.to_s)
224228
user_json_method = SiteSetting.oauth2_user_json_url_method.downcase.to_sym
225229

226-
log("user_json_url: #{user_json_method} #{user_json_url}")
227-
228230
bearer_token = "Bearer #{token}"
229231
connection = Faraday.new { |f| f.adapter FinalDestination::FaradayAdapter }
230232
headers = { "Authorization" => bearer_token, "Accept" => "application/json" }
231233
user_json_response = connection.run_request(user_json_method, user_json_url, nil, headers)
232234

233-
log("user_json_response: #{user_json_response.inspect}")
235+
log <<-LOG
236+
user_json request: #{user_json_method} #{user_json_url}
237+
238+
response:
239+
#{user_json_response.to_yaml}
240+
LOG
234241

235242
if user_json_response.status == 200
236243
user_json = JSON.parse(user_json_response.body)
237244

238-
log("user_json: #{user_json}")
245+
log("user_json:\n#{user_json.to_yaml}")
239246

240247
result = {}
241248
if user_json.present?
@@ -270,9 +277,20 @@ def always_update_user_email?
270277
end
271278

272279
def after_authenticate(auth, existing_account: nil)
273-
log(
274-
"after_authenticate response: \n\ncreds: #{auth["credentials"].to_hash}\nuid: #{auth["uid"]}\ninfo: #{auth["info"].to_hash}\nextra: #{auth["extra"].to_hash}",
275-
)
280+
log <<-LOG
281+
after_authenticate response:
282+
283+
creds:
284+
#{auth["credentials"].to_hash.to_yaml}
285+
286+
uid: #{auth["uid"]}
287+
288+
info:
289+
#{auth["info"].to_hash.to_yaml}
290+
291+
extra:
292+
#{auth["extra"].to_hash.to_yaml}
293+
LOG
276294

277295
if SiteSetting.oauth2_fetch_user_details?
278296
if fetched_user_details = fetch_user_details(auth["credentials"]["token"], auth["uid"])

0 commit comments

Comments
 (0)