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!
This commit is contained in:
Jed Fox
2023-04-06 13:24:46 -04:00
committed by GitHub
parent c3d89b6509
commit bf4319d978
5 changed files with 59 additions and 2 deletions

View File

@@ -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",

View File

@@ -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}'`);
}
}

View File

@@ -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;

View File

@@ -0,0 +1,6 @@
---
category: Features
authors: [j-f1]
---
Add some optional logging to help troubleshoot configuration issues

View File

@@ -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