Skip to content

Commit b73e5e9

Browse files
summeroffeddyStreamlabs
authored and
eddyStreamlabs
committed
enable loging for release preview builds (#29)
1 parent ca4b7c9 commit b73e5e9

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

crash-handler-module/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function startCrashHandler(workingDirectory, version, isDevEnv, cachePath = "")
5555
const processPath = workingDirectory.replace('app.asar', 'app.asar.unpacked') +
5656
'\\node_modules\\crash-handler';
5757

58-
let spawnArguments = [workingDirectory, version, isDevEnv ];
58+
let spawnArguments = [workingDirectory, version, isDevEnv];
5959

6060
if ( cachePath.length > 0 )
6161
spawnArguments.push( cachePath+'\\crash-handler.log' );

crash-handler-process/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ SET(PROJECT_SOURCE
5656
ADD_DEFINITIONS(-DUNICODE)
5757
ADD_EXECUTABLE(crash-handler-process ${PROJECT_SOURCE})
5858

59+
set_property(TARGET crash-handler-process PROPERTY CXX_STANDARD 17)
60+
set_property(TARGET crash-handler-process PROPERTY CXX_STANDARD_REQUIRED ON)
61+
5962
# Include/link crash manager dependencies
6063
target_include_directories(crash-handler-process PUBLIC
6164
"${nlohmannjson_SOURCE_DIR}/single_include"

crash-handler-process/logger.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
#include <chrono>
1919
#include <sstream>
2020
#include <iomanip>
21+
#include <filesystem>
2122

23+
bool log_output_disabled = false;
24+
25+
namespace fs = std::filesystem;
2226
std::ofstream log_output_file;
2327

2428
const std::string getTimeStamp()
@@ -34,12 +38,27 @@ const std::string getTimeStamp()
3438

3539
void logging_start(std::wstring log_path)
3640
{
37-
if( !log_output_disabled && log_path.size() > 0)
41+
if( log_path.size() == 0 )
42+
log_output_disabled = true;
43+
44+
if( !log_output_disabled )
45+
{
46+
try {
47+
fs::path log_file = log_path;
48+
fs::path log_file_old = log_file;
49+
log_file_old.replace_extension("log.old");
50+
51+
fs::remove_all(log_file_old);
52+
fs::rename(log_file, log_file_old);
53+
} catch (...) {
54+
55+
}
3856
log_output_file.open( log_path, std::ios_base::out | std::ios_base::app);
57+
}
3958
}
4059

4160
void logging_end()
4261
{
43-
if( !log_output_disabled)
62+
if( !log_output_disabled )
4463
log_output_file.close();
4564
}

crash-handler-process/logger.hpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
#include <fstream>
55
#include <string>
66

7-
#ifdef NDEBUG
8-
const bool log_output_disabled = true;
9-
#else
10-
const bool log_output_disabled = false;
11-
#endif
127

138
const std::string getTimeStamp();
9+
1410
extern std::ofstream log_output_file;
11+
extern bool log_output_disabled;
1512

1613
#define log_info if (log_output_disabled) {} else log_output_file << "INF:" << getTimeStamp() << ": "
1714
#define log_debug if (log_output_disabled) {} else log_output_file << "DBG:" << getTimeStamp() << ": "

0 commit comments

Comments
 (0)