@@ -13,7 +13,7 @@ defmodule Logger.Utils do
13
13
def translator ( % { meta: % { domain: [ :supervisor_report | _ ] } } , % { sasl: false } ) , do: :stop
14
14
def translator ( % { msg: { :string , _ } } , _config ) , do: :ignore
15
15
16
- def translator ( % { msg: msg , level: level } = event , % { translators: translators } ) do
16
+ def translator ( % { msg: msg , level: level , meta: meta } = event , % { translators: translators } ) do
17
17
% { level: min_level } = :logger . get_primary_config ( )
18
18
19
19
try do
@@ -40,32 +40,39 @@ defmodule Logger.Utils do
40
40
41
41
% { event | msg: { :string , chardata } }
42
42
else
43
- :none -> :ignore
44
- :skip -> :stop
45
- { :ok , chardata } -> return_translated_event ( event , chardata )
46
- { :ok , char , meta } -> return_translated_event ( event , char , meta )
43
+ :none ->
44
+ :ignore
45
+
46
+ :skip ->
47
+ :stop
48
+
49
+ { :ok , chardata } ->
50
+ return_translated_event ( event , chardata , meta )
51
+
52
+ { :ok , chardata , translation_meta } ->
53
+ return_translated_event ( event , chardata , Enum . into ( translation_meta , meta ) )
47
54
end
48
55
end
49
56
50
57
def translated_cb ( report ) do
51
58
{ ~c" ~ts" , [ report [ :elixir_translation ] ] }
52
59
end
53
60
54
- defp return_translated_event ( event , translated , meta \\ [ ] )
55
-
56
- defp return_translated_event ( % { msg: { :report , report } } = event , translated , meta ) do
57
- report = Enum . into ( [ elixir_translation: translated ] , report )
58
- meta = Enum . into ( meta , event . meta )
61
+ defp return_translated_event ( % { msg: { :report , report } } = event , translation , meta ) do
62
+ report =
63
+ if is_list ( report ) ,
64
+ do: [ elixir_translation: translation ] ++ report ,
65
+ else: Map . put ( report , :elixir_translation , translation )
59
66
60
67
% {
61
68
event
62
69
| msg: { :report , report } ,
63
- meta: Enum . into ( [ report_cb: & __MODULE__ . translated_cb / 1 ] , meta )
70
+ meta: Map . put ( meta , :report_cb , & __MODULE__ . translated_cb / 1 )
64
71
}
65
72
end
66
73
67
- defp return_translated_event ( event , translated , meta ) do
68
- % { event | msg: { :string , translated } , meta: Enum . into ( meta , event . meta ) }
74
+ defp return_translated_event ( event , translation , meta ) do
75
+ % { event | msg: { :string , translation } , meta: meta }
69
76
end
70
77
71
78
defp translate ( [ { mod , fun } | t ] , min_level , level , kind , data ) do
0 commit comments