fix bug in partial writes (use rv)
stdout_buf -> log_buf
more structural comments
log_buf_nul_term() macro for clarity and safety