Skip to content

Commit f7b3248

Browse files
fishcakezJosé Valim
authored andcommitted
Flush error_logger before capturing (#5280)
Signed-off-by: José Valim <[email protected]>
1 parent eedc9bc commit f7b3248

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/ex_unit/lib/ex_unit/capture_log.ex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ defmodule ExUnit.CaptureLog do
3737
Returns the binary which is the captured output.
3838
3939
This function mutes the `:console` backend
40-
and captures any log messages sent to Logger.
40+
and captures any log messages sent to Logger from the calling
41+
processes. It is possible to ensure explicit log messages from other
42+
processes are captured by waiting for their exit or monitor
43+
signal. This does not guarantee to capture VM generated log messages
44+
when a process that is spawned using a low level `Kernel` spawn function
45+
(e.g. `Kernel.spawn/1`) raises an exception that isn't rescued or a throw
46+
that isn't caught. A `Task`, or other OTP process, will send explicit logs
47+
that are sent before its exit or monitor signal and will not cause VM
48+
generated log messages.
4149
4250
Note that when the `async` is set to `true`,
4351
the messages from another test might be captured.
@@ -59,6 +67,7 @@ defmodule ExUnit.CaptureLog do
5967
{:ok, string_io} = StringIO.open("")
6068

6169
try do
70+
_ = :gen_event.which_handlers(:error_logger)
6271
:ok = add_capture(string_io, opts)
6372
ref = ExUnit.CaptureServer.log_capture_on(self())
6473

0 commit comments

Comments
 (0)