Factorize some code in logger