Added logAppend function, reorganised some code in log.[ch].