From bf4319d978381090ecca8f7692bf9f92f9e1f999 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Thu, 6 Apr 2023 13:24:46 -0400 Subject: [PATCH] Add some basic debug logging (#178) This will help people sort out configuration issues. Will open a PR to the docs as well to guide people to troubleshoot using this! --- package.json | 1 + src/account-db.js | 9 ++++++- src/load-config.js | 44 ++++++++++++++++++++++++++++++++++- upcoming-release-notes/178.md | 6 +++++ yarn.lock | 1 + 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 upcoming-release-notes/178.md diff --git a/package.json b/package.json index dba8cd6708..72f95d9842 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "better-sqlite3": "^8.2.0", "body-parser": "^1.20.1", "cors": "^2.8.5", + "debug": "^4.3.4", "express": "4.18.2", "express-actuator": "1.8.4", "express-response-size": "^0.0.3", diff --git a/src/account-db.js b/src/account-db.js index 106d7b3b2b..c210641ec8 100644 --- a/src/account-db.js +++ b/src/account-db.js @@ -2,12 +2,16 @@ import fs from 'node:fs'; import { join } from 'node:path'; import openDatabase from './db.js'; import config, { sqlDir } from './load-config.js'; +import createDebug from 'debug'; + +const debug = createDebug('actual:account-db'); + let accountDb = null; export default function getAccountDb() { if (accountDb == null) { if (!fs.existsSync(config.serverFiles)) { - console.log('MAKING SERVER DIR'); + debug(`creating server files directory: '${config.serverFiles}'`); fs.mkdirSync(config.serverFiles); } @@ -17,8 +21,11 @@ export default function getAccountDb() { accountDb = openDatabase(dbPath); if (needsInit) { + debug(`initializing account database: '${dbPath}'`); let initSql = fs.readFileSync(join(sqlDir, 'account.sql'), 'utf8'); accountDb.exec(initSql); + } else { + debug(`opening account database: '${dbPath}'`); } } diff --git a/src/load-config.js b/src/load-config.js index d72e09e3a7..45fecc262b 100644 --- a/src/load-config.js +++ b/src/load-config.js @@ -1,10 +1,17 @@ import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; +import createDebug from 'debug'; + +const debug = createDebug('actual:config'); +const debugSensitive = createDebug('actual-sensitive:config'); const projectRoot = path.dirname(path.dirname(fileURLToPath(import.meta.url))); +debug(`project root: '${projectRoot}'`); export const sqlDir = path.join(projectRoot, 'src', 'sql'); + let defaultDataDir = fs.existsSync('/data') ? '/data' : projectRoot; +debug(`default data directory: '${defaultDataDir}'`); function parseJSON(path, allowMissing = false) { let text; @@ -12,6 +19,7 @@ function parseJSON(path, allowMissing = false) { text = fs.readFileSync(path, 'utf8'); } catch (e) { if (allowMissing) { + debug(`config file '${path}' not found, ignoring.`); return {}; } throw e; @@ -21,8 +29,12 @@ function parseJSON(path, allowMissing = false) { let userConfig; if (process.env.ACTUAL_CONFIG_PATH) { + debug( + `loading config from ACTUAL_CONFIG_PATH: '${process.env.ACTUAL_CONFIG_PATH}'`, + ); userConfig = parseJSON(process.env.ACTUAL_CONFIG_PATH); } else { + debug(`loading config from default path: '${defaultDataDir}/config.json'`); userConfig = parseJSON(path.join(defaultDataDir, 'config.json'), true); } @@ -58,7 +70,7 @@ if (process.env.NODE_ENV === 'test') { }; } -export default { +const finalConfig = { ...config, port: +process.env.ACTUAL_PORT || +process.env.PORT || config.port, hostname: process.env.ACTUAL_HOSTNAME || config.hostname, @@ -83,3 +95,33 @@ export default { } : config.nordigen, }; + +debug(`using port ${finalConfig.port}`); +debug(`using hostname ${finalConfig.hostname}`); +debug(`using server files directory ${finalConfig.serverFiles}`); +debug(`using user files directory ${finalConfig.userFiles}`); +debug(`using web root directory ${finalConfig.webRoot}`); + +if (finalConfig.https) { + debug(`using https key: ${'*'.repeat(finalConfig.https.key.length)}`); + debugSensitive(`using https key ${finalConfig.https.key}`); + debug(`using https cert: ${'*'.repeat(finalConfig.https.cert.length)}`); + debugSensitive(`using https cert ${finalConfig.https.cert}`); +} + +if (finalConfig.nordigen) { + debug( + `using nordigen secret id: ${'*'.repeat( + finalConfig.nordigen.secretId.length, + )}`, + ); + debugSensitive(`using nordigen secret id ${finalConfig.nordigen.secretId}`); + debug( + `using nordigen secret key: ${'*'.repeat( + finalConfig.nordigen.secretKey.length, + )}`, + ); + debugSensitive(`using nordigen secret key ${finalConfig.nordigen.secretKey}`); +} + +export default finalConfig; diff --git a/upcoming-release-notes/178.md b/upcoming-release-notes/178.md new file mode 100644 index 0000000000..ff760e5b00 --- /dev/null +++ b/upcoming-release-notes/178.md @@ -0,0 +1,6 @@ +--- +category: Features +authors: [j-f1] +--- + +Add some optional logging to help troubleshoot configuration issues diff --git a/yarn.lock b/yarn.lock index 19cf5a2c03..5dfb9ab3ee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1375,6 +1375,7 @@ __metadata: better-sqlite3: ^8.2.0 body-parser: ^1.20.1 cors: ^2.8.5 + debug: ^4.3.4 eslint: ^8.33.0 eslint-plugin-prettier: ^4.2.1 express: 4.18.2