kotlinx.coroutines icon indicating copy to clipboard operation
kotlinx.coroutines copied to clipboard

Support user-defined thread or dispatcher name

Open mogud opened this issue 3 years ago • 6 comments

Thread names in logs output by modules that use coroutines are not consistent with other modules.

mogud avatar Apr 01 '22 09:04 mogud

Could you please elaborate on what exactly do you mean? You can use Executor.asCoroutineDispatcher and configure the thread factory to set any named you want to the corresponding threads

qwwdfsad avatar Apr 01 '22 16:04 qwwdfsad

First, we use ktor as our network basis, and it also cannot configure dispatcher name or thread name. On the other hand, Dispatchers.Default is exactly what we want except the name. So it may be a little bit over control to create a new Executor only for the name issue.

mogud avatar Apr 06 '22 07:04 mogud

Could you please elaborate on for what purpose do you need a configurable Dispatchers.Default name?

qwwdfsad avatar Apr 06 '22 09:04 qwwdfsad

For consistency.

In our case, we use some standalone threads to process particular light tasks, like commands. It's convenient to filter logs for other purposes if normalized thread names are contained in final ouput. However, dispatchers' names are not consistent with our log conventions. So, we have to customize our logger tool to support something like markers and mark everywhere.

It doesn't mean that it's hard to deal with this case. We can use some builders to make codes not too verbose. But as CORE_POOL_SIZE and MAX_POOL_SIZE already can be configured, maybe to support configure DEFAULT_SCHEDULER_NAME is reasonable enough. Although formating support is better.

mogud avatar Apr 07 '22 06:04 mogud

Thanks for the explanation and also a reminder about scheduler configurability via system props! The system property is indeed can be a way to go here

qwwdfsad avatar Apr 07 '22 16:04 qwwdfsad

This was also requested in IJ team

dovchinnikov avatar Aug 04 '22 12:08 dovchinnikov

As proposed, customization through kotlinx.coroutines.scheduler.default.name system property has been implemented in #3465

IgnatBeresnev avatar Sep 28 '22 15:09 IgnatBeresnev

(to be closed automatically when the changes enter master)

dkhalanskyjb avatar Sep 28 '22 15:09 dkhalanskyjb