Skip to content

Fix background job logging#6992

Merged
adpi2 merged 3 commits into
sbt:1.8.xfrom
adpi2:fix-bg-logging
Aug 6, 2022
Merged

Fix background job logging#6992
adpi2 merged 3 commits into
sbt:1.8.xfrom
adpi2:fix-bg-logging

Conversation

@adpi2

@adpi2 adpi2 commented Aug 4, 2022

Copy link
Copy Markdown
Member

Fixes #6842

Description

In order of commits

Use BackgroundJobService context instead of MainLoop context

Use the LoggerContext of the BackgroundJobService to create and clean the loggers of the jobs. This is to avoid using the LoggerContext of the MainLoop which is closed after each command: the logger must stay alive after the execution of the command until the job is done.

Don't use ProxyTerminal in background job

Do not use the ProxyTerminal in the ConsoleAppender of a job, so that the logs do not switch from active client to active client. Instead we get the current active terminal at the time the logger is created, and we stick to it until the job is done. So if the job is started by client network 1, the logs will be redirected to client network 1 until the end of the job.

Catch ClosedChannelException in background job logger

If the terminal is closed before the end of the job we catch the ClosedChannelException thrown by the ConsoleOut, otherwise the job would crash.

Results

The logs of a background job are only redirected to the clients that started the job.

bg-run

If a terminal is killed the job keeps running in the background and the logs are not displayed anywhere.

bg-run-exit

Limitation

Getting the log of background job whose terminal is closed

Currently the logs of a job whose terminal is closed are lost. It would be nice to get them back when running bgWait on that job.

Call to println in a background job

A call to println in a background job will always print to the terminal that is active, the ones that is running a task. In particular, if we run the main class of a project without forking, its standard output will move from one active terminal to the other active terminal.

bg-run-println

Unfortunately I don't think there is a solution for this.

RelayAppender

Currently the logger of a background job contains a relay appender and all BSP clients receive all logs of all background jobs.

This kind-of pollutes the logs of BSP clients. For instance in Metals:
bgRun-metals

It would be better if a BSP client only receives the logs of the background jobs that it started.

adpi2 added 3 commits August 4, 2022 16:48
A new context is created and closed for each state of the MainLoop.
But the context of the backgroundJob must stay alive.
So we use a context that is owned by the BackgroundJobService.
It creates a new logger for each background job and cleans it when
the job stops.
If we use the ProxyTerminal in the background jobs, the logs
would be spread across different terminals, switching from active
client to active client. We want the logs to stick
to the client that started the job.
We want the background job to stay alive even if its terminal
has been closed and we cannot write to it anymore
@adpi2 adpi2 marked this pull request as ready for review August 5, 2022 13:23
@adpi2 adpi2 requested a review from eed3si9n August 5, 2022 13:23

@eed3si9n eed3si9n left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bgRun does not forward logs to the client

2 participants