diff --git a/SimDynamics/DynamicsEngine/BulletEngine/BulletRobotLogger.h b/SimDynamics/DynamicsEngine/BulletEngine/BulletRobotLogger.h
index ecabd5af2c29031bd0cc7bc68a0ccfc80ae3a2c9..0482600ef9dd6b9acc03586738fd486c24263bcb 100644
--- a/SimDynamics/DynamicsEngine/BulletEngine/BulletRobotLogger.h
+++ b/SimDynamics/DynamicsEngine/BulletEngine/BulletRobotLogger.h
@@ -7,7 +7,7 @@
 #include "BulletRobot.h"
 
 /*
- * Wrapper for a BulletRobot that logs target/actual position/velocity to a file.
+ * Logger for a BulletRobot that logs target/actual position/velocity to a file.
  */
 namespace SimDynamics
 {
@@ -25,10 +25,24 @@ public:
 	, bodyNodes(bodyNodes)
 	, max_samples(1024 * 1024)
 	, timestamp(0.0f)
+	, logPath("")
 	{
 		engine->addExternalCallback(logCB, (void*) this);
 	}
 
+	~BulletRobotLogger()
+	{
+		if (logPath.size() > 0)
+		{
+			writeToFile(logPath);
+		}
+	}
+
+	void setLogPath(const std::string& path)
+	{
+		logPath = path;
+	}
+
 	void writeToFile(const std::string& path);
 	void startLogging();
 	void stopLogging();
@@ -49,6 +63,7 @@ private:
 	double timestamp;
 	bool running;
 	int max_samples;
+	std::string logPath;
 
 	static void logCB(void* data, btScalar dt);
 	void log(btScalar dt);