mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-11-06 08:18:18 +00:00
Keep Commonlib CLI diagnostics behind debug mode
This commit is contained in:
1 parent
a0f1483891
commit
e7124eda98
4 files changed
+28
-24
No files matched your search
@@ -116,6 +116,11 @@ saved. After correcting the cause, run `sync` again with the same database and
|
||||
settings to retry it. Existing partial writes are retained. `fetch --force`
|
||||
replaces the local database instead and follows the reconstruction rules below.
|
||||
|
||||
A failed `sync` prints `[Error] Command 'sync' failed` and exits with code `1`.
|
||||
To inspect the Journal key, failure stage, and diagnostic details, retry with
|
||||
`--debug`, for example `livesync-cli ./my-db --debug sync`, retaining the same
|
||||
database and settings. Debug diagnostics are written to standard error.
|
||||
|
||||
If the Journal cannot be recovered and missing content or history is
|
||||
acceptable, run `journal-skip <journal-key>`. The CLI first performs normal
|
||||
replication with the retained local database. It skips only when that attempt
|
||||
|
||||
@@ -79,15 +79,6 @@ describe("CLI log handler", () => {
|
||||
it.each([
|
||||
["NOTICE", LOG_LEVEL_NOTICE],
|
||||
["URGENT", LOG_LEVEL_URGENT],
|
||||
] as const)("writes Commonlib %s diagnostics to stderr by default", async (name, level) => {
|
||||
const message = `Commonlib ${name} diagnostic`;
|
||||
const standardIo = await invokeGlobalLogger(databasePath, message, level);
|
||||
|
||||
expect(standardIo.writeStderr).toHaveBeenCalledWith(expect.stringContaining(`[${level}] ${message}\n`));
|
||||
expect(standardIo.writeStdout).not.toHaveBeenCalledWith(expect.stringContaining(message));
|
||||
});
|
||||
|
||||
it.each([
|
||||
["DEBUG", LOG_LEVEL_DEBUG],
|
||||
["INFO", LOG_LEVEL_INFO],
|
||||
["VERBOSE", LOG_LEVEL_VERBOSE],
|
||||
@@ -101,6 +92,8 @@ describe("CLI log handler", () => {
|
||||
|
||||
it("writes detailed Commonlib diagnostics to stderr in debug mode", async () => {
|
||||
const messages = [
|
||||
["NOTICE", LOG_LEVEL_NOTICE],
|
||||
["URGENT", LOG_LEVEL_URGENT],
|
||||
["DEBUG", LOG_LEVEL_DEBUG],
|
||||
["INFO", LOG_LEVEL_INFO],
|
||||
["VERBOSE", LOG_LEVEL_VERBOSE],
|
||||
|
||||
@@ -378,10 +378,15 @@ export async function main(
|
||||
const writeLine = avoidStdoutNoise ? writeStderrLine : writeStdoutLine;
|
||||
writeLine(standardIo, ...values);
|
||||
};
|
||||
setGlobalLogFunction((msg, level) => {
|
||||
if (!options.debug && level !== LOG_LEVEL_NOTICE && level !== LOG_LEVEL_URGENT) return;
|
||||
writeStderrLine(standardIo, `[${level}]`, msg);
|
||||
});
|
||||
if (options.debug) {
|
||||
setGlobalLogFunction((msg, level) => {
|
||||
writeStderrLine(standardIo, `[${level}]`, msg);
|
||||
});
|
||||
} else {
|
||||
setGlobalLogFunction((msg, level) => {
|
||||
// NO OP, leave it to logFunction
|
||||
});
|
||||
}
|
||||
if (options.command === "init-settings") {
|
||||
await createDefaultSettingsFile(options, standardIo);
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user