xLog icon indicating copy to clipboard operation
xLog copied to clipboard

enableThreadInfo() resets the thread interrupted flag

Open LightWeek opened this issue 2 years ago • 1 comments

If you have a thread and logs anything withing the run method using XLog.d("you message here") and the configs have enableThreadInfo(), the interrupted flag will be reset right after the first logged message. The test code:

class LogTestThread : Thread() {
    override fun run() {
        XLog.d("before interruption")
        interrupt()
        var isInterruptedBeforeLog = isInterrupted()
        XLog.d("after interruption")
        var isInterruptedAfterLog = isInterrupted()
    }
}

fun main(){
    val thread = LogTestThread()
    thread.start()
}

In the code above isInterruptedBeforeLog should be true and isInterruptedAfterLog should be true

but isInterruptedAfterLog will be false

But, if you don't enable LogConfiguration.Builder().enableThreadInfo() the code above works as expected.

LightWeek avatar Aug 21 '23 12:08 LightWeek

Well, actually, sometimes, the issue reproduces even if the enableThreadInfo() is not enabled. The library itself messes up with threads. If I replace the log function call with the default logger, the issue goes away, but if I use XLog it reproduces again and again.

LightWeek avatar Aug 21 '23 14:08 LightWeek