Moved data directory creation up before opening the log file
Backed up to C99 standard