Skip to content

Commit f126e9f

Browse files
whatyouhideJosé Valim
authored and
José Valim
committed
Fix indentation in Logger.Translator
Signed-off-by: José Valim <[email protected]>
1 parent ca06fbf commit f126e9f

File tree

1 file changed

+54
-52
lines changed

1 file changed

+54
-52
lines changed

lib/logger/lib/logger/translator.ex

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ defmodule Logger.Translator do
9797
[supervisor: sup, errorContext: context,
9898
reason: reason,
9999
offender: [{:pid, pid}, {name_or_id, name} | offender]])
100-
when is_pid(pid) and context !== :shutdown and name_or_id in [:name, :id] do
100+
when is_pid(pid) and context !== :shutdown and name_or_id in [:name, :id] do
101101
{:ok, ["Child ", inspect(name), " of Supervisor ",
102102
sup_name(sup), ?\s, sup_context(context),
103103
"\n** (exit) ", offender_reason(reason, context),
@@ -106,37 +106,37 @@ defmodule Logger.Translator do
106106
end
107107

108108
defp translate_supervisor(min_level,
109-
[supervisor: sup, errorContext: context,
109+
[supervisor: sup, errorContext: context,
110110
reason: reason,
111111
offender: [{:pid, _pid},
112112
{name_or_id, name} | offender]]) when name_or_id in [:name, :id] do
113113
{:ok, ["Child ", inspect(name), " of Supervisor ",
114-
sup_name(sup), ?\s, sup_context(context),
115-
"\n** (exit) ", offender_reason(reason, context) |
116-
child_info(min_level, offender)]}
114+
sup_name(sup), ?\s, sup_context(context),
115+
"\n** (exit) ", offender_reason(reason, context) |
116+
child_info(min_level, offender)]}
117117
end
118118

119119
defp translate_supervisor(min_level,
120-
[supervisor: sup, errorContext: context,
120+
[supervisor: sup, errorContext: context,
121121
reason: reason,
122122
offender: [{:pid, pid} | offender]]) do
123123
{:ok, ["Child of Supervisor ",
124-
sup_name(sup), ?\s, sup_context(context),
125-
"\n** (exit) ", offender_reason(reason, context),
126-
"\nPid: ", inspect(pid) |
127-
child_info(min_level, offender)]}
124+
sup_name(sup), ?\s, sup_context(context),
125+
"\n** (exit) ", offender_reason(reason, context),
126+
"\nPid: ", inspect(pid) |
127+
child_info(min_level, offender)]}
128128
end
129129

130130
defp translate_supervisor(min_level,
131-
[supervisor: sup, errorContext: context,
131+
[supervisor: sup, errorContext: context,
132132
reason: reason,
133133
offender: [{:nb_children, n},
134134
{name_or_id, name} | offender]]) when name_or_id in [:name, :id] do
135135
{:ok, ["Children ", inspect(name), " of Supervisor ",
136-
sup_name(sup), ?\s, sup_context(context),
137-
"\n** (exit) ", offender_reason(reason, context),
138-
"\nNumber: ", inspect(n) |
139-
child_info(min_level, offender)]}
136+
sup_name(sup), ?\s, sup_context(context),
137+
"\n** (exit) ", offender_reason(reason, context),
138+
"\nNumber: ", inspect(n) |
139+
child_info(min_level, offender)]}
140140
end
141141

142142
defp translate_supervisor(_min_level, _other), do: :none
@@ -148,19 +148,19 @@ defmodule Logger.Translator do
148148

149149
defp translate_progress(min_level,
150150
[supervisor: sup,
151-
started: [{:pid, pid}, {name_or_id, name} | started]]) when name_or_id in [:name, :id] do
151+
started: [{:pid, pid}, {name_or_id, name} | started]]) when name_or_id in [:name, :id] do
152152
{:ok, ["Child ", inspect(name), " of Supervisor ",
153-
sup_name(sup), " started",
154-
"\nPid: ", inspect(pid) |
155-
child_info(min_level, started)]}
153+
sup_name(sup), " started",
154+
"\nPid: ", inspect(pid) |
155+
child_info(min_level, started)]}
156156
end
157157

158158
defp translate_progress(min_level,
159159
[supervisor: sup,
160-
started: [{:pid, pid} | started]]) do
160+
started: [{:pid, pid} | started]]) do
161161
{:ok, ["Child of Supervisor ", sup_name(sup), " started",
162-
"\nPid: ", inspect(pid) |
163-
child_info(min_level, started)]}
162+
"\nPid: ", inspect(pid) |
163+
child_info(min_level, started)]}
164164
end
165165

166166
defp translate_progress(_min_level, _other), do: :none
@@ -177,17 +177,17 @@ defmodule Logger.Translator do
177177

178178
defp child_info(min_level, [{:mfargs, {mod, fun, args}} | debug]) do
179179
["\nStart Call: ", format_mfa(mod, fun, args) |
180-
child_debug(min_level, debug)]
180+
child_debug(min_level, debug)]
181181
end
182182

183183
defp child_info(min_level, [{:mfa, {mod, fun, args}} | debug]) do
184184
["\nStart Call: ", format_mfa(mod, fun, args) |
185-
child_debug(min_level, debug)]
185+
child_debug(min_level, debug)]
186186
end
187187

188188
defp child_info(min_level, [{:mod, mod} | debug]) do
189189
["\nStart Module: ", inspect(mod) |
190-
child_debug(min_level, debug)]
190+
child_debug(min_level, debug)]
191191
end
192192

193193
defp child_debug(:debug,
@@ -217,9 +217,9 @@ defmodule Logger.Translator do
217217
{:error_info, {kind, exception, stack}} | crashed],
218218
linked]) do
219219
{:ok, ["Process ", crash_name(pid, name), " terminating",
220-
format(kind, exception, stack),
221-
crash_info(min_level, [initial_call | crashed]) |
222-
crash_linked(min_level, linked)]}
220+
format(kind, exception, stack),
221+
crash_info(min_level, [initial_call | crashed]) |
222+
crash_linked(min_level, linked)]}
223223
end
224224

225225
defp translate_crash(min_level,
@@ -228,9 +228,9 @@ defmodule Logger.Translator do
228228
{:error_info, {kind, exception, stack}} | crashed],
229229
linked]) do
230230
{:ok, ["Process ", crash_name(pid, name), " terminating",
231-
format(kind, exception, stack),
232-
crash_info(min_level, crashed),
233-
crash_linked(min_level, linked)]}
231+
format(kind, exception, stack),
232+
crash_info(min_level, crashed),
233+
crash_linked(min_level, linked)]}
234234
end
235235

236236
defp crash_name(pid, []), do: inspect(pid)
@@ -241,13 +241,13 @@ defmodule Logger.Translator do
241241
defp crash_info(min_level,
242242
[{:initial_call, {mod, fun, args}} | info], prefix) do
243243
[prefix, "Initial Call: ", crash_call(mod, fun, args) |
244-
crash_info(min_level, info, prefix)]
244+
crash_info(min_level, info, prefix)]
245245
end
246246

247247
defp crash_info(min_level,
248248
[{:current_function, {mod, fun, args}} | info], prefix) do
249249
[prefix, "Current Call: ", crash_call(mod, fun, args) |
250-
crash_info(min_level, info, prefix)]
250+
crash_info(min_level, info, prefix)]
251251
end
252252

253253
defp crash_info(min_level, [{:current_function, []} | info], prefix) do
@@ -257,7 +257,7 @@ defmodule Logger.Translator do
257257
defp crash_info(min_level,
258258
[{:ancestors, ancestors} | debug], prefix) do
259259
[prefix, "Ancestors: ", inspect(ancestors) |
260-
crash_debug(min_level, debug, prefix)]
260+
crash_debug(min_level, debug, prefix)]
261261
end
262262

263263
defp crash_call(mod, fun, arity) when is_integer(arity) do
@@ -270,16 +270,16 @@ defmodule Logger.Translator do
270270

271271
defp crash_debug(:debug,
272272
[messages: msgs, links: links, dictionary: dict,
273-
trap_exit: trap, status: status, heap_size: heap_size,
274-
stack_size: stack_size, reductions: reductions], prefix) do
273+
trap_exit: trap, status: status, heap_size: heap_size,
274+
stack_size: stack_size, reductions: reductions], prefix) do
275275
[prefix, "Messages: ", inspect(msgs),
276-
prefix, "Links: ", inspect(links),
277-
prefix, "Dictionary: ", inspect(dict),
278-
prefix, "Trapping Exits: ", inspect(trap),
279-
prefix, "Status: ", inspect(status),
280-
prefix, "Heap Size: ", inspect(heap_size),
281-
prefix, "Stack Size: ", inspect(stack_size),
282-
prefix, "Reductions: ", inspect(reductions)]
276+
prefix, "Links: ", inspect(links),
277+
prefix, "Dictionary: ", inspect(dict),
278+
prefix, "Trapping Exits: ", inspect(trap),
279+
prefix, "Status: ", inspect(status),
280+
prefix, "Heap Size: ", inspect(heap_size),
281+
prefix, "Stack Size: ", inspect(stack_size),
282+
prefix, "Reductions: ", inspect(reductions)]
283283
end
284284

285285
defp crash_debug(_min_level, _info, _prefix) do
@@ -298,14 +298,14 @@ defmodule Logger.Translator do
298298
[{:pid, pid}, {:registered_name, []} | info]) do
299299
indent = " "
300300
[?\n, indent, inspect(pid) |
301-
crash_info(min_level, info, [?\n, indent | indent])]
301+
crash_info(min_level, info, [?\n, indent | indent])]
302302
end
303303

304304
defp crash_neighbour(min_level,
305305
[{:pid, pid}, {:registered_name, name} | info]) do
306306
indent = " "
307307
[?\n, indent, inspect(name), " (", inspect(pid), ")" |
308-
crash_info(min_level, info, [?\n, indent | indent])]
308+
crash_info(min_level, info, [?\n, indent | indent])]
309309
end
310310

311311
defp format_stop({maybe_exception, [_ | _] = maybe_stacktrace} = reason) do
@@ -316,8 +316,7 @@ defmodule Logger.Translator do
316316
format_stop_banner(reason)
317317
else
318318
formatted_stacktrace ->
319-
[format_stop_banner(maybe_exception, maybe_stacktrace) |
320-
formatted_stacktrace]
319+
[format_stop_banner(maybe_exception, maybe_stacktrace) | formatted_stacktrace]
321320
end
322321
end
323322

@@ -333,7 +332,7 @@ defmodule Logger.Translator do
333332
@gen_undef [:"module could not be loaded", :"function not exported"]
334333

335334
defp format_stop_banner(undef, [{mod, fun, args, _info} | _] = stacktrace)
336-
when undef in @gen_undef and is_atom(mod) and is_atom(fun) do
335+
when undef in @gen_undef and is_atom(mod) and is_atom(fun) do
337336
cond do
338337
is_list(args) ->
339338
format_undef(mod, fun, length(args), undef, stacktrace)
@@ -345,8 +344,11 @@ defmodule Logger.Translator do
345344
end
346345

347346
defp format_stop_banner(reason, stacktrace) do
347+
# If this is already an exception (even an ErlangError), we format it as an
348+
# exception. Otherwise, we try to normalize it, and if it's normalized as an
349+
# ErlangError we instead format it as an exit.
348350
if Exception.exception?(reason) do
349-
[?\n | Exception.format_banner(:error, reason, stacktrace)]
351+
[?\n | Exception.format_banner(:error, reason, stacktrace)]
350352
else
351353
case Exception.normalize(:error, reason, stacktrace) do
352354
%ErlangError{} ->
@@ -369,9 +371,9 @@ defmodule Logger.Translator do
369371
end
370372

371373
defp format_stacktrace(stacktrace) do
372-
for entry <- stacktrace do
373-
[<<"\n ">> | Exception.format_stacktrace_entry(entry)]
374-
end
374+
for entry <- stacktrace do
375+
[<<"\n ">> | Exception.format_stacktrace_entry(entry)]
376+
end
375377
end
376378

377379
defp format_mfa(mod, fun, :undefined), do: [inspect(mod), ?., to_string(fun) | "/?"]

0 commit comments

Comments
 (0)