Logging in pycharm, the order of output is random

test_code
test.py

import logging
import sys
log = logging.getLogger("test1")
log.addHandler(logging.StreamHandler(stream=sys.stdout))
log.setLevel(logging.DEBUG)
log2 = logging.getLogger("test2")
log2.setLevel(logging.DEBUG)
log.error("test1")
log2.error("test2")

when I run it in cmd, it is normal, but when I run it in pycharm,the output is random. sometimes the info “test1” first, sometimes the info “test2” first.

Does stdout in Pycharm use line buffering (or no buffering)? If not (if it is full buffering) then stderr can show earlier than stdout.

Test your code directly in a terminal, not affected by the Pycharm environment.