Skip to content

Commit c3ae78b

Browse files
committed
chore: use logger instead of console.log
1 parent 7b1718b commit c3ae78b

File tree

18 files changed

+43
-51
lines changed

18 files changed

+43
-51
lines changed

adminforth/commands/createApp/templates/adminuser.ts.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import AdminForth, { AdminForthDataTypes } from 'adminforth';
2-
import type { AdminForthResourceInput, AdminForthResource, AdminUser } from 'adminforth';
2+
import type { AdminForthResourceInput, AdminForthResource, AdminUser, logger } from 'adminforth';
33
import { randomUUID } from 'crypto';
44

55
async function allowedForSuperAdmin({ adminUser }: { adminUser: AdminUser }): Promise<boolean> {
@@ -94,7 +94,7 @@ export default {
9494
},
9595
edit: {
9696
beforeSave: async ({ oldRecord, updates, adminUser, resource }: { oldRecord: any, updates: any, adminUser: AdminUser, resource: AdminForthResource }) => {
97-
console.log('Updating user', updates);
97+
logger.info('Updating user', updates);
9898
if (oldRecord.id === adminUser.dbUser.id && updates.role) {
9999
return { ok: false, error: 'You cannot change your own role' };
100100
}

adminforth/commands/createApp/templates/index.ts.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import AdminForth from 'adminforth';
33
import usersResource from "./resources/adminuser.js";
44
import { fileURLToPath } from 'url';
55
import path from 'path';
6-
import { Filters } from 'adminforth';
6+
import { Filters, logger } from 'adminforth';
77
import { initApi } from './api.js';
88

99
const ADMIN_BASE_URL = '';
@@ -75,7 +75,7 @@ if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
7575
const port = 3500;
7676

7777
admin.bundleNow({ hotReload: process.env.NODE_ENV === 'development' }).then(() => {
78-
console.log('Bundling AdminForth SPA done.');
78+
logger.info('Bundling AdminForth SPA done.');
7979
});
8080

8181
admin.express.serve(app);
@@ -91,6 +91,6 @@ if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
9191
});
9292

9393
admin.express.listen(port, () => {
94-
console.log(`\n⚡ AdminForth is available at http://localhost:${port}${ADMIN_BASE_URL}\n`);
94+
logger.info(`\n⚡ AdminForth is available at http://localhost:${port}${ADMIN_BASE_URL}\n`);
9595
});
9696
}

adminforth/documentation/blog/2024-10-01-ai-blog/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Open `index.ts` file in root directory and update it with the following content:
212212

213213
```ts title="./index.ts"
214214
import express from 'express';
215-
import AdminForth, { Filters, Sorts } from 'adminforth';
215+
import AdminForth, { Filters, Sorts, logger } from 'adminforth';
216216
import userResource from './resources/adminuser.js';
217217
import postResource from './resources/posts.js';
218218
import contentImageResource from './resources/content-image.js';
@@ -287,7 +287,7 @@ if (import.meta.url === `file://${process.argv[1]}`) {
287287
const port = 3500;
288288

289289
admin.bundleNow({ hotReload: process.env.NODE_ENV === 'development' }).then(() => {
290-
console.log('Bundling AdminForth SPA done.');
290+
logger.info('Bundling AdminForth SPA done.');
291291
});
292292

293293
// api to server recent posts
@@ -343,7 +343,7 @@ if (import.meta.url === `file://${process.argv[1]}`) {
343343
});
344344

345345
admin.express.listen(port, () => {
346-
console.log(`\n⚡ AdminForth is available at http://localhost:${port}/admin\n`)
346+
logger.info(`\n⚡ AdminForth is available at http://localhost:${port}/admin\n`)
347347
});
348348
}
349349
```

adminforth/documentation/docs/tutorial/01-helloWorld.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Create `index.ts` file in root directory with following content:
131131

132132
```ts title="./index.ts"
133133
import express from 'express';
134-
import AdminForth, { AdminForthDataTypes, Filters } from 'adminforth';
134+
import AdminForth, { AdminForthDataTypes, Filters, logger } from 'adminforth';
135135
import type { AdminForthResourceInput, AdminForthResource, AdminUser } from 'adminforth';
136136

137137
export const admin = new AdminForth({
@@ -218,7 +218,7 @@ export const admin = new AdminForth({
218218
},
219219
edit: {
220220
beforeSave: async ({ oldRecord, updates, adminUser, resource }: { oldRecord: any, updates: any, adminUser: AdminUser, resource: AdminForthResource }) => {
221-
console.log('Updating user', updates);
221+
logger.info('Updating user', updates);
222222
if (oldRecord.id === adminUser.dbUser.id && updates.role) {
223223
return { ok: false, error: 'You cannot change your own role' };
224224
}
@@ -321,7 +321,7 @@ if (import.meta.url === `file://${process.argv[1]}`) {
321321

322322
// needed to compile SPA. Call it here or from a build script e.g. in Docker build time to reduce downtime
323323
admin.bundleNow({ hotReload: process.env.NODE_ENV === 'development' }).then(() => {
324-
console.log('Bundling AdminForth SPA done.');
324+
logger.info('Bundling AdminForth SPA done.');
325325
});
326326

327327
// serve after you added all api
@@ -338,7 +338,7 @@ if (import.meta.url === `file://${process.argv[1]}`) {
338338
});
339339

340340
admin.express.listen(port, () => {
341-
console.log(`\n⚡ AdminForth is available at http://localhost:${port}\n`)
341+
logger.info(`\n⚡ AdminForth is available at http://localhost:${port}\n`)
342342
});
343343
}
344344
```

adminforth/documentation/docs/tutorial/03-Customization/09-Actions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Here's how to add a custom action:
2222

2323
// Handler function when action is triggered
2424
action: async ({ recordId, adminUser }) => {
25-
console.log("auto submit", recordId, adminUser);
25+
logger.info("auto submit", recordId, adminUser);
2626
return {
2727
ok: true,
2828
successMessage: "Auto submitted"

adminforth/documentation/docs/tutorial/03-Customization/16-websocket.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ In two words, to subscribe to a topic from any frontend component you need to do
77

88
```javascript
99
import websocket from '@/websocket';
10+
import { logger } from 'adminforth'
1011

1112
websocket.subscribe('/topic-name', (data) => {
1213
// this callback called when we receive publish in topic from the websocket
13-
console.log(data);
14+
logger.info(data);
1415
});
1516
```
1617

@@ -192,7 +193,7 @@ const admin = new AdminForth({
192193
//diff-add
193194
const [subject, param] = /^\/(.+?)\/(.+)/.exec(topic)!.slice(1);
194195
//diff-add
195-
console.log(`Websocket user ${adminUser.username} tries to subscribe to topic ${subject} with param ${param}`);
196+
logger.info(`Websocket user ${adminUser.username} tries to subscribe to topic ${subject} with param ${param}`);
196197
//diff-add
197198
if (subject === 'property-cost') {
198199
//diff-add

adminforth/documentation/docs/tutorial/05-Plugins/15-email-invite.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ To Setup SES, you need to have an AWS account and SES service enabled. You can f
3131
```typescript title="./resources/adminuser.ts"
3232
import EmailInvitePlugin from '@adminforth/email-invite';
3333
import EmailAdapterAwsSes from '@adminforth/email-adapter-aws-ses';
34+
import { logger } from 'adminforth'
3435

3536
export default {
3637
dataSource: 'maindb',
@@ -77,7 +78,7 @@ export default {
7778
},
7879
edit: {
7980
beforeSave: async ({ oldRecord, updates, adminUser, resource }: { oldRecord: any, updates: any, adminUser: AdminUser, resource: AdminForthResource }) => {
80-
console.log('Updating user', updates);
81+
logger.info('Updating user', updates);
8182
if (oldRecord.id === adminUser.dbUser.id && updates.role) {
8283
return { ok: false, error: 'You cannot change your own role' };
8384
}

adminforth/documentation/docs/tutorial/07-Plugins/16-email-invite.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ To Setup SES, you need to have an AWS account and SES service enabled. You can f
3131
```typescript title="./resources/adminuser.ts"
3232
import EmailInvitePlugin from '@adminforth/email-invite';
3333
import EmailAdapterAwsSes from '@adminforth/email-adapter-aws-ses';
34+
import { logger } from 'adminforth'
3435

3536
export default {
3637
dataSource: 'maindb',
@@ -77,7 +78,7 @@ export default {
7778
},
7879
edit: {
7980
beforeSave: async ({ oldRecord, updates, adminUser, resource }: { oldRecord: any, updates: any, adminUser: AdminUser, resource: AdminForthResource }) => {
80-
console.log('Updating user', updates);
81+
logger.info('Updating user', updates);
8182
if (oldRecord.id === adminUser.dbUser.id && updates.role) {
8283
return { ok: false, error: 'You cannot change your own role' };
8384
}

adminforth/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import ClickhouseConnector from './dataConnectors/clickhouse.js';
3535
import OperationalResource from './modules/operationalResource.js';
3636
import SocketBroker from './modules/socketBroker.js';
3737
import { afLogger } from './modules/logger.js';
38+
export { logger } from './modules/logger.js';
3839

3940
// exports
4041
export * from './types/Back.js';
@@ -176,7 +177,7 @@ class AdminForth implements IAdminForth {
176177
dbDiscover: 'running',
177178
};
178179

179-
console.info(`${this.formatAdminForth()} v${ADMINFORTH_VERSION} initializing...`);
180+
afLogger.info(`${this.formatAdminForth()} v${ADMINFORTH_VERSION} initializing...`);
180181
afLogger.trace('🔧 About to set global.adminforth...');
181182
global.adminforth = this;
182183
afLogger.trace('🔧 global.adminforth set successfully');

adminforth/modules/codeInjector.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ function hashify(obj) {
6565
}
6666

6767
function notifyWatcherIssue(limit) {
68-
console.log('Ran out of file handles after watching %s files.', limit);
69-
console.log('Falling back to polling which uses more CPU.');
70-
console.log('Run ulimit -n 10000 to increase the limit for open files.');
68+
afLogger.info('Ran out of file handles after watching %s files.', limit);
69+
afLogger.info('Falling back to polling which uses more CPU.');
70+
afLogger.info('Run ulimit -n 10000 to increase the limit for open files.');
7171
}
7272

7373
class CodeInjector implements ICodeInjector {
@@ -92,7 +92,7 @@ class CodeInjector implements ICodeInjector {
9292
}
9393

9494
cleanup() {
95-
console.log('Cleaning up...');
95+
afLogger.info('Cleaning up...');
9696
this.allWatchers.forEach((watcher) => {
9797
watcher.removeAll();
9898
});
@@ -108,14 +108,6 @@ class CodeInjector implements ICodeInjector {
108108

109109
}
110110

111-
// async runShell({ command }) {
112-
// console.log(`⚙️ Running shell ${command}...`);
113-
// console.time(`${command} done in`);
114-
// const { stdout: out, stderr: err } = await execAsync(command);
115-
// console.timeEnd(`${command} done in`);
116-
// console.log(`Command ${command} output:`, out, err);
117-
// }
118-
119111
async runNpmShell({command, cwd, envOverrides = {}}: {
120112
command: string,
121113
cwd: string,
@@ -511,7 +503,6 @@ class CodeInjector implements ICodeInjector {
511503
this.allComponentNames[filePath] = componentName;
512504
});
513505

514-
// console.log('🔧 Injecting code into Vue sources...', this.allComponentNames);
515506

516507
let customComponentsImports = '';
517508
for (const [targetPath, component] of Object.entries(this.allComponentNames)) {
@@ -859,7 +850,7 @@ class CodeInjector implements ICodeInjector {
859850
}
860851

861852
async bundleNow({ hotReload = false }: { hotReload: boolean }) {
862-
console.log(`${this.adminforth.formatAdminForth()} Bundling ${hotReload ? 'and listening for changes (🔥 Hotreload)' : ' (no hot reload)'}`);
853+
afLogger.info(`${this.adminforth.formatAdminForth()} Bundling ${hotReload ? 'and listening for changes (🔥 Hotreload)' : ' (no hot reload)'}`);
863854
this.adminforth.runningHotReload = hotReload;
864855

865856
await this.prepareSources();
@@ -917,7 +908,7 @@ class CodeInjector implements ICodeInjector {
917908
// save hash
918909
await fs.promises.writeFile(path.join(serveDir, '.adminforth_messages_hash'), sourcesHash);
919910
} else {
920-
console.log(`AdminForth i18n message extraction skipped — build already performed for the current sources.`);
911+
afLogger.info(`AdminForth i18n message extraction skipped — build already performed for the current sources.`);
921912
}
922913

923914
if (!hotReload) {
@@ -932,14 +923,14 @@ class CodeInjector implements ICodeInjector {
932923
// save hash
933924
await fs.promises.writeFile(path.join(serveDir, '.adminforth_build_hash'), sourcesHash);
934925
} else {
935-
console.log(`Skipping AdminForth SPA bundling - already completed for the current sources.`);
926+
afLogger.info(`Skipping AdminForth SPA bundling - already completed for the current sources.`);
936927
}
937928
} else {
938929

939930
const command = 'run dev';
940-
console.log(`⚙️ spawn: npm ${command}...`);
931+
afLogger.info(`⚙️ spawn: npm ${command}...`);
941932
if (process.env.VITE_ADMINFORTH_PUBLIC_PATH) {
942-
console.log('⚠️ Your VITE_ADMINFORTH_PUBLIC_PATH:', process.env.VITE_ADMINFORTH_PUBLIC_PATH, 'has no effect');
933+
afLogger.info('⚠️ Your VITE_ADMINFORTH_PUBLIC_PATH:', process.env.VITE_ADMINFORTH_PUBLIC_PATH, 'has no effect');
943934
}
944935
const env = {
945936
VITE_ADMINFORTH_PUBLIC_PATH: this.adminforth.config.baseUrl,

0 commit comments

Comments
 (0)