Re: Erlang (OTP 21+) Logger Console Output Question (Garbled Prompt)
Lukas Larsson <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CAP3zBqP5aw66Bc_uQ4qudpuqikUuijDYhhbWTb2bgbkMXHFCrw@mail.gmail.com> |
Hello! This issue has to do with which group_leader that the process that is writing the output has. When doing `io:format` in a process that either is a shell (or is started by a shell) the group_leader is set to a process that is aware of the shell and can rewrite it when output comes its way. 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. It is not only logger that has this problem, if you do an `io:format` in a process started as part of an application hierarchy you will see the same behaviour. (or by doing `spawn(fun F() -> timer:sleep(1000), io:format(user,"hello hello~n",[]), F() end)`) I'm not sure how easy it is to do anything about this, as it would require different parts of the group_leader hierarchy to interact in ways that I do not think it does today. A possibly short-term solution for you might be hitting "ctrl-l" (ctrl and non-capital L) when the situation happens. That should rewrite the current line so that you can see what you are doing. Lukas On Fri, May 7, 2021 at 9:21 PM Brett Hemes <[email protected]> wrote: > 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 >