+
+std::unique_ptr<std::ofstream> openLogfile( const std::string &name ) {
+ struct stat buffer;
+ std::string tname = name;
+ int ctr = 2;
+
+ while( stat( tname.c_str(), &buffer ) == 0 ) {
+ tname = name + "_" + std::to_string( ctr++ );
+ }
+
+ auto res = std::make_unique<std::ofstream>( tname );
+
+ if( ! res->good() ) {
+ throw std::string( "Failed to open file for logging: " ) + name;
+ }
+
+ return res;
+}
+
+std::string timestamp(){
+ time_t c_time;
+ if( time( &c_time ) == -1 ) {
+ throw std::runtime_error( "Error while fetching time?" );
+ }
+ return std::to_string( c_time );
+}