Re: Erlang (OTP 21+) Logger Console Output Question (Garbled Prompt)

Lukas Larsson <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <CAP3zBqOh58FrbfSg2Cp5bdE+e0aN7tOL6kFQNawBOUFGtoOG2w@mail.gmail.com>
On Mon, May 10, 2021 at 8:08 AM Nicolas Martyanoff <[email protected]>
wrote:

> Lukas Larsson <[email protected]> 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.
>

I'm not really familiar with how eunit handles input/output during
testcases, but this together with the fact that applications log to `user`
will make it hard for eunit to get the output it needs.


> 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.
>

There is no need to write another log system, you only need to write a
logger backend that outputs to the group_leader of the calling process
instead of `user`.

Similar functionality is already available in common_test as
cth_log_redirect,
http://erlang.org/doc/apps/common_test/ct_hooks_chapter.html#built-in-cths.
I believe that rebar3 does something similar for their common_test logs.

I suppose that the big question is whether we can change the default
behaviour of logger to be that it should output to the `standard_io` of the
calling process instead of `user`.

Lukas
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.