LMs // Bind Syslog prints with debug conditions.

This commit is contained in:
ShikiSuen 2022-03-29 10:31:38 +08:00
parent f160ecc71c
commit 511beda3df
5 changed files with 31 additions and 29 deletions

View File

@ -17,6 +17,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
*/
#include "LMConsolidator.h"
#include "vChewing-Swift.h"
namespace vChewing {
@ -31,13 +32,13 @@ bool LMConsolidator::CheckPragma(const char *path)
{
string firstLine;
getline(zfdCheckPragma, firstLine);
syslog(LOG_CONS, "HEADER SEEN ||%s", firstLine.c_str());
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "HEADER SEEN ||%s", firstLine.c_str());
if (firstLine != FORMATTED_PRAGMA_HEADER) {
syslog(LOG_CONS, "HEADER VERIFICATION FAILED. START IN-PLACE CONSOLIDATING PROCESS.");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "HEADER VERIFICATION FAILED. START IN-PLACE CONSOLIDATING PROCESS.");
return false;
}
}
syslog(LOG_CONS, "HEADER VERIFICATION SUCCESSFUL.");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "HEADER VERIFICATION SUCCESSFUL.");
return true;
}
@ -49,22 +50,22 @@ bool LMConsolidator::FixEOF(const char *path)
char z;
zfdEOFFixerIncomingStream.get(z);
if(z!='\n'){
syslog(LOG_CONS, "// REPORT: Data File not ended with a new line.\n");
syslog(LOG_CONS, "// DATA FILE: %s", path);
syslog(LOG_CONS, "// PROCEDURE: Trying to insert a new line as EOF before per-line check process.\n");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// REPORT: Data File not ended with a new line.\n");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// DATA FILE: %s", path);
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// PROCEDURE: Trying to insert a new line as EOF before per-line check process.\n");
std::ofstream zfdEOFFixerOutput(path, std::ios_base::app);
zfdEOFFixerOutput << std::endl;
zfdEOFFixerOutput.close();
if (zfdEOFFixerOutput.fail()) {
syslog(LOG_CONS, "// REPORT: Failed to append a newline to the data file. Insufficient Privileges?\n");
syslog(LOG_CONS, "// DATA FILE: %s", path);
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// REPORT: Failed to append a newline to the data file. Insufficient Privileges?\n");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// DATA FILE: %s", path);
return false;
}
}
zfdEOFFixerIncomingStream.close();
if (zfdEOFFixerIncomingStream.fail()) {
syslog(LOG_CONS, "// REPORT: Failed to read lines through the data file for EOF check. Insufficient Privileges?\n");
syslog(LOG_CONS, "// DATA FILE: %s", path);
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// REPORT: Failed to read lines through the data file for EOF check. Insufficient Privileges?\n");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// DATA FILE: %s", path);
return false;
}
return true;
@ -118,14 +119,14 @@ bool LMConsolidator::ConsolidateContent(const char *path, bool shouldCheckPragma
}
zfdContentConsolidatorOutput.close();
if (zfdContentConsolidatorOutput.fail()) {
syslog(LOG_CONS, "// REPORT: Failed to write content-consolidated data to the file. Insufficient Privileges?\n");
syslog(LOG_CONS, "// DATA FILE: %s", path);
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// REPORT: Failed to write content-consolidated data to the file. Insufficient Privileges?\n");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// DATA FILE: %s", path);
return false;
}
zfdContentConsolidatorIncomingStream.close();
if (zfdContentConsolidatorIncomingStream.fail()) {
syslog(LOG_CONS, "// REPORT: Failed to read lines through the data file for content-consolidation. Insufficient Privileges?\n");
syslog(LOG_CONS, "// DATA FILE: %s", path);
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// REPORT: Failed to read lines through the data file for content-consolidation. Insufficient Privileges?\n");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "// DATA FILE: %s", path);
return false;
}
return true;

View File

@ -90,7 +90,7 @@ bool AssociatedPhrases::open(const char *path)
// 下面這一段或許可以做成開關、來詢問是否對使用者語彙採取寬鬆策略(哪怕有行內容寫錯也會放行)
if (state == KeyValueBlobReader::State::ERROR) {
// close();
syslog(LOG_CONS, "AssociatedPhrases: Failed at Open Step 5. On Error Resume Next.\n");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "AssociatedPhrases: Failed at Open Step 5. On Error Resume Next.\n");
// return false;
}
return true;

View File

@ -24,6 +24,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
#include <fstream>
#include <unistd.h>
#include <syslog.h>
#include "vChewing-Swift.h"
using namespace Gramambular;
@ -123,7 +124,7 @@ start:
c = *head;
// \s -> error
if (c == ' ') {
syslog(LOG_CONS, "vChewingDebug: CoreLM // Start: \\s -> error");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // Start: \\s -> error");
goto error;
}
// \n -> start
@ -140,14 +141,14 @@ start:
state1:
// EOF -> error
if (head == end) {
syslog(LOG_CONS, "vChewingDebug: CoreLM // state 1: EOF -> error");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 1: EOF -> error");
goto error;
}
c = *head;
// \n -> error
if (c == '\n') {
syslog(LOG_CONS, "vChewingDebug: CoreLM // state 1: \\n -> error");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 1: \\n -> error");
goto error;
}
// \s -> state2 + zero out ending + record column start
@ -165,14 +166,14 @@ state1:
state2:
// eof -> error
if (head == end) {
syslog(LOG_CONS, "vChewingDebug: CoreLM // state 2: EOF -> error");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 2: EOF -> error");
goto error;
}
c = *head;
// \n, \s -> error
if (c == '\n' || c == ' ') {
syslog(LOG_CONS, "vChewingDebug: CoreLM // state 2: \\n \\s -> error");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 2: \\n \\s -> error");
goto error;
}
@ -184,7 +185,7 @@ state2:
state3:
// eof -> error
if (head == end) {
syslog(LOG_CONS, "vChewingDebug: CoreLM // state 3: EOF -> error");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 3: EOF -> error");
goto error;
}
@ -192,7 +193,7 @@ state3:
// \n -> error
if (c == '\n') {
syslog(LOG_CONS, "vChewingDebug: CoreLM // state 3: \\n -> error");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 3: \\n -> error");
goto error;
}
// \s -> state4 + zero out ending + record column start
@ -210,14 +211,14 @@ state3:
state4:
// eof -> error
if (head == end) {
syslog(LOG_CONS, "vChewingDebug: CoreLM // state 4: EOF -> error");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 4: EOF -> error");
goto error;
}
c = *head;
// \n, \s -> error
if (c == '\n' || c == ' ') {
syslog(LOG_CONS, "vChewingDebug: CoreLM // state 4: \\n \\s -> error");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 4: \\n \\s -> error");
goto error;
}
@ -230,14 +231,14 @@ state4:
state5:
// eof -> error
if (head == end) {
syslog(LOG_CONS, "vChewingDebug: CoreLM // state 5: EOF -> error");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 5: EOF -> error");
goto error;
}
c = *head;
// \s -> error
if (c == ' ') {
syslog(LOG_CONS, "vChewingDebug: CoreLM // state 5: \\s -> error");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // state 5: \\s -> error");
goto error;
}
// \n -> start
@ -264,7 +265,7 @@ end:
emptyRow.value = space;
emptyRow.logProbability = zero;
keyRowMap[space].push_back(emptyRow);
syslog(LOG_CONS, "vChewingDebug: CoreLM // File Load Complete.");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "vChewingDebug: CoreLM // File Load Complete.");
return true;
}

View File

@ -85,7 +85,7 @@ bool PhraseReplacementMap::open(const char *path)
// 下面這一段或許可以做成開關、來詢問是否對使用者語彙採取寬鬆策略(哪怕有行內容寫錯也會放行)
if (state == KeyValueBlobReader::State::ERROR) {
// close();
syslog(LOG_CONS, "PhraseReplacementMap: Failed at Open Step 5. On Error Resume Next.\n");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "PhraseReplacementMap: Failed at Open Step 5. On Error Resume Next.\n");
// return false;
}
return true;

View File

@ -94,7 +94,7 @@ bool UserPhrasesLM::open(const char *path)
// 下面這一段或許可以做成開關、來詢問是否對使用者語彙採取寬鬆策略(哪怕有行內容寫錯也會放行)
if (state == KeyValueBlobReader::State::ERROR) {
// close();
syslog(LOG_CONS, "UserPhrasesLM: Failed at Open Step 5. On Error Resume Next.\n");
if (mgrPrefs.isDebugModeEnabled) syslog(LOG_CONS, "UserPhrasesLM: Failed at Open Step 5. On Error Resume Next.\n");
// return false;
}
return true;