While developing I often use console prints as debugging/verification tools. In the past I have used io:format for this purpose but I would like to use the new OTP logger to do this and then be able to filter based on severity and/or send them to a file instead of the console as the project matures. However, I am having trouble currently preventing logger’s output from destroying my console interactivity. I have logger setup to use the console for output but **the logging prints output AT the current cursor position and thus destroy any input-in-progress** making interaction during busy logging near impossible. In contrast, using io:format performs as desired where the output happens (and scrolls) right ABOVE the cursor line (i.e., without destroying the prompt). Is this known behavior and/or is there any way to fix it (e.g., with some sys.config settings)?
For example,
With io:format:
37> some_intput.
some_info_i_would_like_to_display
some_more_info
info_etc
38> my-next-input.<enter>
39> <enter>
39>
With logger:
37> some_input.
38> some_info_i_would_like_to_display
my-nexsome_more_info
t-input.<enter>
39> info_etc<enter>
39>
I would very much like to figure this out.
Thanks,
Brett
Lukas Larsson <lu...@erlang.org> writes:
> However, since logger does not use the group_leader of the calling process
> to print log messages, those messages get sent directly to the `user`
> process which has no notion of whether a shell is actually running or not,
> so it cannot rewrite the output.
If I'm not mistaken, this is also the reason eunit tests do not capture
logger messages, making it hard to understand what was logged by a
specific failing test.
Is there something on the roadmap to try to address this issue ? It
affects both shell and eunit in non-trivial ways. The only workaround is
to ignore logger in applications and to write another log system which
uses the group leader, so it would make sense to fix logger.
If I'm not mistaken, this is also the reason eunit tests do not capture
logger messages, making it hard to understand what was logged by a
specific failing test.
I tried to work around it with custom log handlers in the past, but
could never make it work, and I remember talking about it on #erlang,
but the conclusion was that it was not fixable without patching eunit
and/or logger.
But logger messages are not directly sent to the group leader, therefore
they are not captured by eunit and are logged in all cases.