kotlinx.coroutines
kotlinx.coroutines copied to clipboard
Support user-defined thread or dispatcher name
Thread names in logs output by modules that use coroutines are not consistent with other modules.
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
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.
Could you please elaborate on for what purpose do you need a configurable Dispatchers.Default name?
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.
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
This was also requested in IJ team
As proposed, customization through kotlinx.coroutines.scheduler.default.name system property has been implemented in #3465
(to be closed automatically when the changes enter master)