Silence logger in process?

I build async task in a Mix task a little bit like this:

Task.async(fn -> MyApp.work() end)

This work function sometimes uses Mix.shell().info() to print informations, but I can make it silence using Mix.shell(Mix.Shell.Quiet), like this:

Task.async(fn -> 
   Mix.shell(Mix.Shell.Quiet)
   MyApp.work() 
end)

Is there something how I can make also Logger.info() output to not appear? Also maybe sometimes IO.puts ? I want this task to be silent. No logs, no STDOUT. Is this possible?

You can disable logs per process via Logger.disable(self()) (works only with self()). With STDOUT not really, however you can check out how ExUnit.CaptureIO works and maybe copy their solution.

3 Likes