Skip to content

Commit 8cff816

Browse files
committed
Update log file save location
1 parent 472357d commit 8cff816

2 files changed

Lines changed: 27 additions & 19 deletions

File tree

Source/MainWindow.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,18 @@ MainWindow::MainWindow(const File& fileToLoad)
3333
Colour(Colours::black),
3434
DocumentWindow::allButtons)
3535
{
36-
37-
File activityLog = File::getCurrentWorkingDirectory().getChildFile("activity.log");
36+
configsDir = CoreServices::getSavedStateDirectory();
37+
if(!configsDir.getFullPathName().contains("plugin-GUI" + File::getSeparatorString() + "Build"))
38+
configsDir = configsDir.getChildFile("configs-api" + String(PLUGIN_API_VER));
39+
40+
if(!configsDir.isDirectory())
41+
configsDir.createDirectory();
42+
43+
File activityLog = configsDir.getChildFile("activity.log");
3844
if (activityLog.exists())
3945
activityLog.deleteFile();
46+
47+
OELogger::instance().createLogFile(activityLog.getFullPathName().toStdString());
4048

4149
std::cout << "Session Start Time: " << Time::getCurrentTime().toString(true, true, true, true) << std::endl;
4250
std::cout << std::endl;
@@ -53,13 +61,6 @@ MainWindow::MainWindow(const File& fileToLoad)
5361
shouldEnableHttpServer = true;
5462
openDefaultConfigWindow = false;
5563

56-
configsDir = CoreServices::getSavedStateDirectory();
57-
if(!configsDir.getFullPathName().contains("plugin-GUI" + File::getSeparatorString() + "Build"))
58-
configsDir = configsDir.getChildFile("configs-api" + String(PLUGIN_API_VER));
59-
60-
if(!configsDir.isDirectory())
61-
configsDir.createDirectory();
62-
6364
// Create ProcessorGraph and AudioComponent, and connect them.
6465
// Callbacks will be set by the play button in the control panel
6566

@@ -229,9 +230,13 @@ void MainWindow::handleCrash(void* input)
229230
LOGD("\n", backtrace);
230231
std::flush(std::cout);
231232

232-
File activityLog = File::getCurrentWorkingDirectory().getChildFile("activity.log");
233+
File crashLogDir = CoreServices::getSavedStateDirectory();
234+
if(!crashLogDir.getFullPathName().contains("plugin-GUI" + File::getSeparatorString() + "Build"))
235+
crashLogDir = crashLogDir.getChildFile("configs-api" + String(PLUGIN_API_VER));
236+
237+
File activityLog = crashLogDir.getChildFile("activity.log");
233238
String dt = AccessClass::getControlPanel()->generateDatetimeFromFormat("MM-DD-YYYY_HH_MM_SS");
234-
File crashLog = File::getCurrentWorkingDirectory().getChildFile("activity_" + dt + ".log");
239+
File crashLog = crashLogDir.getChildFile("activity_" + dt + ".log");
235240

236241
if (activityLog.exists())
237242
{
@@ -240,7 +245,7 @@ void MainWindow::handleCrash(void* input)
240245
activityLog.deleteFile();
241246
}
242247

243-
String recoveryFileLocation = CoreServices::getSavedStateDirectory().getChildFile("recoveryConfig.xml").getFullPathName();
248+
String recoveryFileLocation = crashLogDir.getChildFile("recoveryConfig.xml").getFullPathName();
244249

245250
AlertWindow::showMessageBox(AlertWindow::NoIcon,
246251
"Open Ephys has stopped working",

Source/Utils/Utils.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,7 @@ std::ofstream logFile;
5555

5656
protected:
5757

58-
OELogger() {
59-
// Each time the GUI is launched, a new error log is generated.
60-
// In case of a crash, the most recent file is appended with a datestring
61-
logFile.open("activity.log", std::ios::out | std::ios::app);
62-
time_t now = time(0);
63-
logFile << "[open-ephys] Session start time: " << ctime(&now);
64-
}
58+
OELogger() { }
6559
public:
6660
static OELogger& instance()
6761
{
@@ -101,6 +95,15 @@ std::ofstream logFile;
10195
logFile << std::endl;
10296
}
10397

98+
void createLogFile(std::string const& filePath)
99+
{
100+
// Each time the GUI is launched, a new error log is generated.
101+
// In case of a crash, the most recent file is appended with a datestring
102+
logFile.open(filePath, std::ios::out | std::ios::app);
103+
time_t now = time(0);
104+
logFile << "[open-ephys] Session start time: " << ctime(&now);
105+
}
106+
104107
private:
105108
std::mutex mt;
106109
};

0 commit comments

Comments
 (0)