Skip to content

Commit b7b70f6

Browse files
committed
chore: enhance logging messages for clarity in baseConnector, codeInjector, and socketBroker modules
1 parent 6b0d3bb commit b7b70f6

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

adminforth/dataConnectors/baseConnector.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
330330
}
331331

332332
async checkUnique(resource: AdminForthResource, column: AdminForthResourceColumn, value: any, record?: any): Promise<boolean> {
333-
afLogger.trace('☝️🪲🪲🪲🪲 checkUnique|||', column, value);
333+
afLogger.trace(`☝️🪲🪲🪲🪲 checkUnique||| ${column.name}, ${value}`);
334334

335335
const primaryKeyField = this.getPrimaryKey(resource);
336336
const existingRecord = await this.getData({
@@ -386,11 +386,11 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
386386
})
387387
);
388388
if (error) {
389-
afLogger.trace('🪲🆕 check unique error', error);
389+
afLogger.trace(`🪲🆕 check unique error, ${error}`);
390390
return { error, ok: false };
391391
}
392392

393-
afLogger.trace('🪲🆕 creating record',JSON.stringify(recordWithOriginalValues));
393+
afLogger.trace(`🪲🆕 creating record, ${JSON.stringify(recordWithOriginalValues)}`);
394394
let pkValue = await this.createRecordOriginalValues({ resource, record: recordWithOriginalValues });
395395
if (recordWithOriginalValues[this.getPrimaryKey(resource)] !== undefined) {
396396
// some data sources always return some value for pk, even if it is was not auto generated
@@ -442,7 +442,7 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
442442
})
443443
);
444444
if (error) {
445-
afLogger.trace('🪲🆕 check unique error', error);
445+
afLogger.trace(`🪲🆕 check unique error, ${error}`);
446446
return { error, ok: false };
447447
}
448448

adminforth/modules/codeInjector.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class CodeInjector implements ICodeInjector {
133133
};
134134

135135
afLogger.trace(`⚙️ exec: npm ${command}`);
136-
afLogger.trace(`🪲 npm ${command} cwd:`, cwd);
136+
afLogger.trace(`🪲 npm ${command} cwd: ${cwd}`);
137137
afLogger.trace(`npm ${command} done in`);
138138

139139
// On Windows, execute npm.cmd directly; on Unix, use node + npm
@@ -163,7 +163,7 @@ class CodeInjector implements ICodeInjector {
163163
afLogger.trace(`npm ${command} done in`);
164164

165165
if (err) {
166-
afLogger.trace(`🪲npm ${command} errors/warnings:`, err);
166+
afLogger.trace(`🪲npm ${command} errors/warnings: ${err}`);
167167
}
168168
}
169169

@@ -243,7 +243,7 @@ class CodeInjector implements ICodeInjector {
243243
dereference: true, // needed to dereference types
244244
// preserveTimestamps: true, // needed to not invalidate any caches
245245
});
246-
afLogger.trace('🪲⚙️ fsExtra.copy copy single file', src, dest);
246+
afLogger.trace(`🪲⚙️ fsExtra.copy copy single file, ${src}, ${dest}`);
247247
}));
248248
}
249249
async migrateLegacyCustomLayout(oldMeta) {
@@ -365,7 +365,7 @@ class CodeInjector implements ICodeInjector {
365365
const filterPasses = !src.includes(`${path.sep}adminforth${path.sep}spa${path.sep}node_modules`) && !src.includes(`${path.sep}adminforth${path.sep}spa${path.sep}dist`)
366366
&& !src.includes(`${path.sep}dist${path.sep}spa${path.sep}node_modules`) && !src.includes(`${path.sep}dist${path.sep}spa${path.sep}dist`);
367367
if (!filterPasses) {
368-
afLogger.trace('🪲⚙️ fsExtra.copy filtered out', src);
368+
afLogger.trace(`🪲⚙️ fsExtra.copy filtered out, ${src}`);
369369
}
370370

371371
return filterPasses
@@ -643,7 +643,7 @@ class CodeInjector implements ICodeInjector {
643643

644644
// for every installed plugin generate packages
645645
for (const plugin of this.adminforth.activatedPlugins) {
646-
afLogger.trace('🔧 Checking packages for plugin', plugin.constructor.name, plugin.customFolderPath);
646+
afLogger.trace(`🔧 Checking packages for plugin, ${plugin.constructor.name}, ${plugin.customFolderPath}`);
647647
const [lockHash, packages] = await this.packagesFromNpm(plugin.customFolderPath);
648648
if (packages.length) {
649649
pluginPackages.push({
@@ -671,7 +671,7 @@ class CodeInjector implements ICodeInjector {
671671
}
672672
} catch (e) {
673673
// ignore
674-
afLogger.trace('🪲Hash file does not exist, proceeding with npm ci/install', e);
674+
afLogger.trace(`🪲Hash file does not exist, proceeding with npm ci/install, ${e}`);
675675
}
676676

677677
await this.runNpmShell({command: 'ci', cwd: this.spaTmpPath(), envOverrides: {
@@ -724,7 +724,7 @@ class CodeInjector implements ICodeInjector {
724724
};
725725
await collectDirectories(spaPath);
726726

727-
afLogger.trace('🪲🔎 Watch for:', directories.join(','));
727+
afLogger.trace(`🪲🔎 Watch for: ${directories.join(',')}`);
728728

729729
const watcher = filewatcher({ debounce: 30 });
730730
directories.forEach((dir) => {
@@ -794,7 +794,7 @@ class CodeInjector implements ICodeInjector {
794794
watcher.add(file);
795795
});
796796

797-
afLogger.trace('🪲🔎 Watch for:', directories.join(','));
797+
afLogger.trace(`🪲🔎 Watch for: ${directories.join(',')}`);
798798

799799
watcher.on(
800800
'change',
@@ -882,8 +882,8 @@ class CodeInjector implements ICodeInjector {
882882

883883
const allFiles = [];
884884
const sourcesHash = await this.computeSourcesHash(this.spaTmpPath(), allFiles);
885-
afLogger.trace('🪲🪲 allFiles:', JSON.stringify(
886-
allFiles.sort((a,b) => a.localeCompare(b)), null, 1))
885+
afLogger.trace(`🪲🪲 allFiles:, ${JSON.stringify(
886+
allFiles.sort((a,b) => a.localeCompare(b)), null, 1)}`);
887887

888888
const buildHash = await this.tryReadFile(path.join(serveDir, '.adminforth_build_hash'));
889889
const messagesHash = await this.tryReadFile(path.join(serveDir, '.adminforth_messages_hash'));
@@ -963,7 +963,7 @@ class CodeInjector implements ICodeInjector {
963963
// parse port from message " ➜ Local: http://localhost:xyz/"
964964
const s = stripAnsiCodes(data.toString());
965965

966-
afLogger.trace('🪲 devServer stdout ➜ (port detect):', s);
966+
afLogger.trace(`🪲 devServer stdout ➜ (port detect): ${s}`);
967967
const portMatch = s.match(/.+?http:\/\/.+?:(\d+).+?/m);
968968
if (portMatch) {
969969
this.devServerPort = parseInt(portMatch[1]);

adminforth/modules/socketBroker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,17 @@ export default class SocketBroker implements IWebSocketBroker {
126126

127127
async publish(topic: string, data: any, filterUsers?: (adminUser: AdminUser) => Promise<boolean>): Promise<void> {
128128
if (!this.topics[topic]) {
129-
afLogger.trace('No clients subscribed to topic', topic);
129+
afLogger.trace(`No clients subscribed to topic ${topic}`);
130130
return;
131131
}
132132
for (const client of this.topics[topic]) {
133133
if (filterUsers) {
134134
if (! (await filterUsers(client.adminUser)) ) {
135-
afLogger.trace('Client not authorized to receive message', topic, client.adminUser);
135+
afLogger.trace(`Client not authorized to receive message ${topic} ${client.adminUser}`);
136136
continue;
137137
}
138138
}
139-
afLogger.trace('Sending data to socket', topic, data);
139+
afLogger.trace(`Sending data to socket ${topic} ${JSON.stringify(data)}`);
140140
client.send(JSON.stringify({ type: 'message', topic, data }));
141141
}
142142
}

0 commit comments

Comments
 (0)