@@ -175,7 +175,8 @@ defmodule Logger.Formatter do
175175 warning: Keyword . get ( colors , :warning , :yellow ) ,
176176 notice: Keyword . get ( colors , :info , :normal ) ,
177177 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 )
179180 }
180181 end
181182
@@ -221,12 +222,14 @@ defmodule Logger.Formatter do
221222
222223 defp format_fa ( fun , arity ) , do: [ Atom . to_string ( fun ) , "/" , Integer . to_string ( arity ) ]
223224
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
230233 end
231234 end
232235
0 commit comments