Skip to content

Commit af94344

Browse files
refactor: simplify logging to two levels, error and debug
Collapse the five-level scheme (DEBUG/INFO/WARN/ERROR/FEAT) down to just DEBUG and ERROR on both sides of the WASM boundary. warn/info/feat call sites become debug (internal diagnostics, not user-actionable) or error (genuine caught exceptions), matching Obsidian's guideline that only errors should show by default. The Rust side binds directly to src/logger/index.ts's `log` singleton via wasm_bindgen and was calling .info()/.warn() on it — a prior TS-only pass at removing these methods broke at the WASM boundary (`arg0.info is not a function`) since Rust still called them. Fixed by updating the extern binding in wasm/src/utils.rs and every call site, then rebuilding wasm/pkg.
1 parent e388755 commit af94344

16 files changed

Lines changed: 336 additions & 387 deletions

File tree

src/codeblocks/MDRC.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class CodeblockMDRC extends MarkdownRenderChild {
5757
});
5858

5959
if (!parsed) {
60-
log.warn(
60+
log.debug(
6161
"fatal codeblock errors\n" +
6262
errors
6363
.map((e) => ` [${e.code}] ${e.path}: ${e.message}`)
@@ -80,7 +80,7 @@ export class CodeblockMDRC extends MarkdownRenderChild {
8080
);
8181
// Although the postprocessing could also have errors,
8282
// they're not fatal at this point, so we can still render the codeblock (which renders the errors as well)
83-
if (errors.length) log.warn("non-fatal codeblock errors", errors);
83+
if (errors.length) log.debug("non-fatal codeblock errors", errors);
8484

8585
if (options.type === "tree") {
8686
this.component = mount(CodeblockTree, {

src/codeblocks/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function postprocess_options(
111111
}
112112

113113
if (parsed["dataview-from"]) {
114-
log.warn(
114+
log.debug(
115115
"Codeblock field `dataview-from` is deprecated; use `from` instead.",
116116
);
117117
}

src/commands/init.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ export function init_all_commands(plugin: BreadcrumbsPlugin) {
5151
const stats = get_graph_stats(plugin.graph, {
5252
groups: plugin.settings.edge_field_groups,
5353
});
54-
log.feat("Graph stats >", stats);
54+
log.debug("Graph stats >", stats);
5555

5656
await navigator.clipboard.writeText(JSON.stringify(stats, null, 2));
5757

58-
new Notice(
59-
"Graph stats printed to console and copied to clipboard",
60-
);
58+
new Notice("Graph stats copied to clipboard");
6159
},
6260
});
6361

src/graph/builders/explicit/dataview_note.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const _add_explicit_edges_dataview_note: ExplicitEdgeBuilder = (
9595
dataview_api.pages(query, dataview_note_file.path),
9696
) as IDataview.Page[];
9797
} catch (error) {
98-
log.warn(
98+
log.debug(
9999
"dataview-note > DV API error:",
100100
error instanceof Error ? error.message : error,
101101
);

src/graph/builders/explicit/tag_note.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const get_tag_note_info = (
3434
raw_tag = metadata["BC-tag-note"];
3535

3636
if (raw_tag) {
37-
log.warn(
37+
log.debug(
3838
`'BC-tag-note' is deprecated in favor of ${META_ALIAS["tag-note-tag"]}`,
3939
);
4040
}

src/logger/index.ts

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
export const LOG_LEVELS = [
2-
"DEBUG",
3-
"INFO",
4-
"WARN",
5-
"ERROR",
6-
// Some features log data
7-
"FEAT",
8-
] as const;
1+
export const LOG_LEVELS = ["DEBUG", "ERROR"] as const;
92
export type LogLevels = (typeof LOG_LEVELS)[number];
103

114
const LEVEL_COLOURS: Record<LogLevels, string | null> = {
125
DEBUG: "#999",
13-
INFO: null,
14-
WARN: "#f90",
156
ERROR: "#f00",
16-
FEAT: "#0f0",
177
};
188

199
const build_prefix = (level: LogLevels) => {
@@ -41,35 +31,15 @@ class Logger {
4131
}
4232
}
4333

44-
info(...args: unknown[]) {
45-
if (this.level_i <= 1) {
46-
console.log(...build_prefix("INFO"), ...args);
47-
}
48-
}
49-
50-
warn(...args: unknown[]) {
51-
if (this.level_i <= 2) {
52-
// NOTE: Don't actually console.warn
53-
// The user doesn't need a stack trace
54-
console.log(...build_prefix("WARN"), ...args);
55-
}
56-
}
57-
5834
error(...args: unknown[]) {
59-
if (this.level_i <= 3) {
35+
if (this.level_i <= 1) {
6036
console.log(...build_prefix("ERROR"), ...args);
6137
}
6238
}
6339

64-
feat(...args: unknown[]) {
65-
if (this.level_i === 4) {
66-
console.log(...build_prefix("FEAT"), ...args);
67-
}
68-
}
69-
7040
set_level(level: LogLevels) {
7141
this.level_i = LOG_LEVELS.findIndex((l) => l === level);
7242
}
7343
}
7444

75-
export const log = new Logger("INFO");
45+
export const log = new Logger("ERROR");

src/main.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ export default class BreadcrumbsPlugin extends Plugin {
104104
// Logger
105105
log.set_level(this.settings.debug.level);
106106

107-
log.info(
108-
`loading plugin "${this.manifest.name}" plugin v${this.manifest.version}`,
109-
);
110107
log.debug("settings >", this.settings);
111108

112109
// Init event bus
@@ -358,7 +355,6 @@ export default class BreadcrumbsPlugin extends Plugin {
358355
backup_path,
359356
JSON.stringify(this.settings, null, "\t"),
360357
);
361-
log.info(`old settings backed up to ${backup_path}`);
362358
}
363359
}
364360

@@ -386,7 +382,7 @@ export default class BreadcrumbsPlugin extends Plugin {
386382
);
387383

388384
if (Object.keys(explicit_edge_errors).length) {
389-
log.warn("explicit_edge_errors >", explicit_edge_errors);
385+
log.debug("explicit_edge_errors >", explicit_edge_errors);
390386
}
391387

392388
notice?.setMessage(
@@ -433,7 +429,7 @@ export default class BreadcrumbsPlugin extends Plugin {
433429
: workspace.getRightLeaf(false);
434430

435431
if (!leaf) {
436-
log.warn("activate_view > no leaf found");
432+
log.debug("activate_view > no leaf found");
437433
return;
438434
}
439435

src/settings/migration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export function migrate_old_settings(settings: BreadcrumbsSettings) {
281281
) {
282282
if (old.hierarchyNotes.length > 0) {
283283
const msg = `DEPRECATED: The central Hierarchy Notes setting is deprecated in favour of the "${META_ALIAS["list-note-field"]}" field in each hierarchy note.`;
284-
log.warn(msg);
284+
log.debug(msg);
285285
}
286286

287287
delete old.HNUpField;

src/utils/obsidian.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ export const copy_to_clipboard = async (
100100
const resolved = Object.assign({ notify: true, log: true }, options);
101101

102102
if (resolved.log) {
103-
log.feat(text);
103+
log.debug(text);
104104
}
105105

106106
await navigator.clipboard.writeText(text);
107107

108108
if (resolved.notify) {
109-
new Notice("Copied to clipboard and logged to console.");
109+
new Notice("Copied to clipboard.");
110110
}
111111
};

0 commit comments

Comments
 (0)