logger: Fixed segfault

Firstly check variable, then overwrite it