For something a bit more heavyweight have you considered a prewritten logging library such as log4cpp for example (
http://log4cpp.sourceforge.net/) which is a c++ imitation of the 'famous' log4j java library?
I would seriously recommend
against opening and closing the file for each line unless your logging is VERY sparse. Doing it this way causes immense CPU and I/O usage for each log line as close() usually invokes a flush to disk, and will make verbose logging infeasible for any larger project (been there, done that!)
If you are rolling your own, keep the file handle open at all times, and close it when the program exits, or on a timer if you want to see up-to-date information and are for example watching the log in another window and want it to update.