Skip to content

Commit

Permalink
Use logger handlers in examples, closes #23
Browse files Browse the repository at this point in the history
  • Loading branch information
fuelen committed Mar 16, 2024
1 parent 365db38 commit 8affa78
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
9 changes: 8 additions & 1 deletion examples/emulate_compilation.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
require Logger
Logger.configure_backend(:console, device: Owl.LiveScreen)

:ok = :logger.remove_handler(:default)

:ok =
:logger.add_handler(:default, :logger_std_h, %{
config: %{type: {:device, Owl.LiveScreen}},
formatter: Logger.Formatter.new()
})

["ecto", "phoenix", "ex_doc", "broadway"]
|> Enum.map(fn dependency ->
Expand Down
10 changes: 8 additions & 2 deletions lib/owl/live_screen.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ defmodule Owl.LiveScreen do
A server that handles live updates in terminal.
It partially implements [The Erlang I/O Protocol](https://www.erlang.org/doc/apps/stdlib/io_protocol.html),
so it is possible to use `Owl.LiveScreen` as an I/O-device in `Logger.Backends.Console`
so it is possible to use `Owl.LiveScreen` as an I/O-device in `Logger`
and functions like `Owl.IO.puts/2`, `IO.puts/2`. When used as I/O-device, then output is printed above dynamic blocks.
## Example
require Logger
Logger.configure_backend(:console, device: Owl.LiveScreen)
:ok = :logger.remove_handler(:default)
:ok =
:logger.add_handler(:default, :logger_std_h, %{
config: %{type: {:device, Owl.LiveScreen}},
formatter: Logger.Formatter.new()
})
Owl.LiveScreen.add_block(:dependency,
state: :init,
Expand Down

0 comments on commit 8affa78

Please sign in to comment.