Skip to content

Commit

Permalink
logger: add simple logger (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
julesvirallinen authored Sep 30, 2023
1 parent 680dc88 commit 736c866
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { DigitalGardenSettingTab } from "./src/ui/DigitalGardenSettingTab";
import { generateGardenSnapshot } from "./src/test/snapshot/generateGardenSnapshot";
import { FRONTMATTER_KEYS } from "./src/models/frontMatter";
import dotenv from "dotenv";
import Logger from "js-logger";
dotenv.config();

const DEFAULT_SETTINGS: DigitalGardenSettings = {
Expand Down Expand Up @@ -58,8 +59,16 @@ const DEFAULT_SETTINGS: DigitalGardenSettings = {
dgLinkPreview: false,
dgShowTags: false,
},
logLevel: undefined,
};

Logger.useDefaults({
defaultLevel: Logger.WARN,
formatter: function (messages, _context) {
messages.unshift(new Date().toUTCString());
messages.unshift("DG: ");
},
});
export default class DigitalGarden extends Plugin {
settings!: DigitalGardenSettings;
appVersion!: string;
Expand All @@ -72,6 +81,11 @@ export default class DigitalGarden extends Plugin {
console.log("Initializing DigitalGarden plugin v" + this.appVersion);
await this.loadSettings();

this.settings.logLevel && Logger.setLevel(this.settings.logLevel);

Logger.info(
"Digital garden log level set to " + Logger.getLevel().name,
);
this.addSettingTab(new DigitalGardenSettingTab(this.app, this));

await this.addCommands();
Expand Down Expand Up @@ -141,6 +155,8 @@ export default class DigitalGarden extends Plugin {
});

if (this.settings["ENABLE_DEVELOPER_TOOLS"]) {
Logger.info("Developer tools enabled");

const publisher = new Publisher(
this.app.vault,
this.app.metadataCache,
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"diff": "^5.1.0",
"eslint-plugin-svelte": "^2.33.2",
"js-base64": "^3.7.5",
"js-logger": "^1.6.1",
"luxon": "^3.4.3",
"lz-string": "^1.5.0",
"obsidian-dataview": "^0.5.56"
Expand Down
2 changes: 2 additions & 0 deletions scripts/generateGardenSettings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import dotevnt from "dotenv";
import fs from "fs";
dotevnt.config();
import copyfiles from "copyfiles";
import Logger from "js-logger";

const gardenSettings = {
githubRepo:
Expand Down Expand Up @@ -58,6 +59,7 @@ Path Rewriting/Subfolder:this-will-never-hit`,
},
ENABLE_DEVELOPER_TOOLS: true,
devPluginPath: `${process.cwd()}`,
logLevel: Logger.DEBUG,
};

const TEST_VAULT_PATH =
Expand Down
3 changes: 3 additions & 0 deletions src/models/settings.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ILogLevel } from "js-logger";

/** Saved to data.json, changing requires a migration */
export default interface DigitalGardenSettings {
githubToken: string;
Expand Down Expand Up @@ -50,4 +52,5 @@ export default interface DigitalGardenSettings {
};
ENABLE_DEVELOPER_TOOLS?: boolean;
devPluginPath?: string;
logLevel?: ILogLevel;
}

0 comments on commit 736c866

Please sign in to comment.