Skip to content

Commit bc2cb15

Browse files
author
José Valim
committed
Add Logger.flush/0
1 parent dbf205b commit bc2cb15

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/logger/lib/logger.ex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,20 @@ defmodule Logger do
343343
Logger.Config.configure(Dict.take(options, @valid_options))
344344
end
345345

346+
@doc """
347+
Flushes the Logger.
348+
349+
This basically guarantees all messages sent to the
350+
Logger prior to this call will be processed. This is useful
351+
for testing and it should not be called in production code.
352+
"""
353+
@spec flush :: :ok
354+
def flush do
355+
_ = GenEvent.which_handlers(:error_logger)
356+
_ = GenEvent.which_handlers(Logger)
357+
:ok
358+
end
359+
346360
@doc """
347361
Adds a new backend.
348362

lib/logger/test/test_helper.exs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ defmodule Logger.Case do
3939
Logger.configure(level: level)
4040
capture_io(:user, fn ->
4141
fun.()
42-
GenEvent.which_handlers(:error_logger)
43-
GenEvent.which_handlers(Logger)
42+
Logger.flush()
4443
end)
4544
after
4645
Logger.configure(level: :debug)

0 commit comments

Comments
 (0)