Extract logging helpers from K.py to log.py.