only show log if in debug mode

This commit is contained in:
千住柱間 2024-05-30 13:24:46 -04:00
parent 34fb696599
commit a7cadd0036
Signed by: hashirama
GPG key ID: 53E62470A86BC185

View file

@ -20,6 +20,7 @@
#include <ctime> #include <ctime>
bool debug_mode = false;
struct Entry { struct Entry {
const std::string_view decoded_view; const std::string_view decoded_view;
@ -125,6 +126,7 @@ inline void print_debug_info(const std::vector<std::string>& substrings, const s
void log_execution(const int argc, char* argv[], const std::string& search_string, const std::string& dict_file, bool debug_mode, bool goldendict_mode) { void log_execution(const int argc, char* argv[], const std::string& search_string, const std::string& dict_file, bool debug_mode, bool goldendict_mode) {
if (!debug_mode) return;
std::ofstream log_file; std::ofstream log_file;
log_file.open("/tmp/hakurei.log", std::ios_base::app); log_file.open("/tmp/hakurei.log", std::ios_base::app);
if (!log_file) { if (!log_file) {
@ -149,6 +151,12 @@ void log_execution(const int argc, char* argv[], const std::string& search_strin
void log_internal(const std::string& message) { void log_internal(const std::string& message) {
extern bool debug_mode; // Declare the external debug_mode variable
if (!debug_mode) {
return;
}
std::ofstream log_file; std::ofstream log_file;
log_file.open("/tmp/hakurei.log", std::ios_base::app); log_file.open("/tmp/hakurei.log", std::ios_base::app);
if (!log_file) { if (!log_file) {
@ -160,7 +168,6 @@ void log_internal(const std::string& message) {
log_file.close(); log_file.close();
} }
inline void wrap_html_output( inline void wrap_html_output(
const std::vector<std::string>& substrings, const std::vector<std::string>& substrings,
const std::map<std::string, std::set<std::string>>& alternatives_map, const std::map<std::string, std::set<std::string>>& alternatives_map,
@ -234,7 +241,7 @@ int main(const int argc, char* argv[]) {
log_internal("Trie loaded from dictionary file"); log_internal("Trie loaded from dictionary file");
bool debug_mode = false;
bool goldendict_mode = false; bool goldendict_mode = false;
std::string word, sentence; std::string word, sentence;