Skip to content

Better logger for console with direct access #4720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/logger/lib/logger/backends/console.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ defmodule Logger.Backends.Console do
format_event(level, msg, ts, md, state)
|> color_event(level, colors)
try do
IO.write(device, output)
send(device, {:io_request, self(), self(), {:put_chars, :unicode, output}})
rescue
ArgumentError ->
Copy link
Member

@josevalim josevalim May 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! However, this clause will never be raised now. Can you try the following variation instead of the try do:

case :unicode.characters_to_binary(output) do
  {:error, good, bad} ->
    send(device, {:io_request, self(), self(), {:put_chars, :unicode, [good | Logger.Formatter.prune(bad)]}})
  good ->
    send(device, {:io_request, self(), self(), {:put_chars, :unicode, good}})
end

And let us know how it performs CPU and memory wise?

IO.write(device, Logger.Formatter.prune(output))
send(device, {:io_request, self(), self(), {:put_chars, :unicode, Logger.Formatter.prune(output)}})
end
end

Expand Down