flush logs when exit with errors