fix: do not newline at the start of a log line

This breaks the log file format since it will have a line break directly
after the timestamp
fix: do not use fsync()

We do not need fsync(), the fflush() is enough to avoid concurrent
logs.
more log format fixes
added a chdir() for proper daemonizing
use if instead of switch and avoid a warning
removed not needed arguments to avoid compiler warnings
added an explicit type cast to avoid compiler warnings