Skip to content

Commit 8978e02

Browse files
logtofile compile option
1 parent 66af0b5 commit 8978e02

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@ project(ChessEngine)
33

44
set(CMAKE_CXX_STANDARD 23)
55
option(WASM "Build Webassembly binary" TRUE)
6+
option(LOGTOFILE "Make a file with a detailed search log" FALSE)
67

78
add_executable(ChessEngine main.cpp)
89

910
set(CMAKE_CXX_FLAGS "-std=c++23")
1011

11-
message("WASM=${WASM}")
1212
if (WASM)
1313
message("Building for Webassembly")
1414
add_compile_definitions(wasm)
1515
set(CMAKE_CXX_FLAGS "-std=c++23 -fexperimental-library")
1616
endif ()
1717

18+
if (LOGTOFILE)
19+
message("Logging to file enabled")
20+
add_compile_definitions(logtofile)
21+
endif ()
22+
1823
include_directories(src)
1924
add_subdirectory(src)
2025

src/Logger.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "Logger.h"
22

33
#include <iostream>
4-
#include <format>
54

65
#ifdef wasm
76
#include "emscripten.h"
@@ -11,13 +10,17 @@
1110
void Logger::start() {
1211
stop = false;
1312
processingThread = std::thread(&Logger::threadFunc, this);
13+
#ifdef logtofile
1414
logFile.open("log.txt");
15+
#endif
1516
}
1617

1718
void Logger::end() {
1819
stop = true;
1920
processingThread.join();
21+
#ifdef logtofile
2022
logFile.close();
23+
#endif
2124
}
2225

2326
void Logger::log(const std::string message) const {
@@ -29,29 +32,38 @@ void Logger::log(const std::string message) const {
2932
}
3033

3134
void Logger::logToFile(std::string message) const {
35+
// Since the function doesn't do anything with the flag disabled the compiler should technically remove it and all the calls to it
36+
#ifdef logtofile
3237
auto* newNode = new MessageNode();
3338
newNode->type = TOFILE;
3439
newNode->msg = message;
3540
tail->next = newNode;
3641
tail = newNode;
42+
#endif
3743
}
3844

3945
void Logger::sendInt(const std::string name, const int value) const {
46+
// Since the function doesn't do anything with the flag disabled the compiler should technically remove it and all the calls to it
47+
#ifdef wasm
4048
auto* newNode = new IntNode();
4149
newNode->type = INT;
4250
newNode->name = name;
4351
newNode->value = value;
4452
tail->next = newNode;
4553
tail = newNode;
54+
#endif
4655
}
4756

4857
void Logger::sendString(const std::string name, const std::string value) const {
58+
// Since the function doesn't do anything with the flag disabled the compiler should technically remove it and all the calls to it
59+
#ifdef wasm
4960
auto* newNode = new StringNode();
5061
newNode->type = STRING;
5162
newNode->name = name;
5263
newNode->value = value;
5364
tail->next = newNode;
5465
tail = newNode;
66+
#endif
5567
}
5668

5769

@@ -83,10 +95,12 @@ bool Logger::processNode() const {
8395
if (newHead->type == LOG) {
8496
std::cout << reinterpret_cast<MessageNode *>(newHead)->msg;
8597
}
98+
#ifdef logtofile
8699
else if (newHead->type == TOFILE) {
87100
logFile << reinterpret_cast<MessageNode *>(newHead)->msg;
88101
}
89102
#endif
103+
#endif
90104

91105
#ifdef wasm
92106
switch (newHead->type) {

0 commit comments

Comments
 (0)