@@ -175,7 +175,8 @@ defmodule Logger.Formatter do
175
175
warning: Keyword . get ( colors , :warning , :yellow ) ,
176
176
notice: Keyword . get ( colors , :info , :normal ) ,
177
177
info: Keyword . get ( colors , :info , :normal ) ,
178
- debug: Keyword . get ( colors , :debug , :cyan )
178
+ debug: Keyword . get ( colors , :debug , :cyan ) ,
179
+ enabled: Keyword . get ( colors , :enabled , & IO.ANSI . enabled? / 0 )
179
180
}
180
181
end
181
182
@@ -221,12 +222,14 @@ defmodule Logger.Formatter do
221
222
222
223
defp format_fa ( fun , arity ) , do: [ Atom . to_string ( fun ) , "/" , Integer . to_string ( arity ) ]
223
224
224
- defp colorize ( data , level , colors , md ) do
225
- if Map . get_lazy ( colors , :enabled , & IO.ANSI . enabled? / 0 ) do
226
- color = md [ :ansi_color ] || Map . fetch! ( colors , level )
227
- [ IO.ANSI . format_fragment ( color , true ) , data | IO.ANSI . reset ( ) ]
228
- else
229
- data
225
+ defp colorize ( data , level , % { enabled: enabled } = colors , md ) do
226
+ case if ( is_function ( enabled , 0 ) , do: enabled . ( ) , else: enabled ) do
227
+ true ->
228
+ color = md [ :ansi_color ] || Map . fetch! ( colors , level )
229
+ [ IO.ANSI . format_fragment ( color , true ) , data | IO.ANSI . reset ( ) ]
230
+
231
+ false ->
232
+ data
230
233
end
231
234
end
232
235
0 commit comments