<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-logging</artifactId>
<version>1.8.3</version>
</dependency>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration>
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.ObsoleteCoroutinesApi;
import mu.KotlinLogging;
private val logger = KotlinLogging.logger {};
@ObsoleteCoroutinesApi
fun createFlow(): Flow<Int> = callbackFlow {
for (i in 1..10) {
channel.send(i)
logger.debug { "Sent $i" }
}
awaitClose { logger.debug { "Flow closed" } }
}
10:30:45.678 [DEBUG] com.example.MyClass - Sent 1
10:30:45.686 [DEBUG] com.example.MyClass - Sent 2
10:30:45.693 [DEBUG] com.example.MyClass - Sent 3
...