-
Notifications
You must be signed in to change notification settings - Fork 21
Feature/admin forth/1137/lets remove heavy debug and in #445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Feature/admin forth/1137/lets remove heavy debug and in #445
Conversation
…ector, and socketBroker modules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR modernizes the logging infrastructure by replacing scattered console.log, console.error, and environment-based debug statements with a structured logging system using pino and pino-pretty. The implementation introduces three logger instances (logger, afLogger, dbLogger) for different logging contexts, each configurable via environment variables.
Changes:
- Introduced centralized logging module using pino with three distinct loggers for user logs, AdminForth internal logs, and database query logs
- Replaced
console.log/console.errorandprocess.env.HEAVY_DEBUG && console.log()patterns with appropriate logger calls throughout the codebase - Added pino and pino-pretty dependencies to package.json
- Updated documentation and templates to use the new logger
Reviewed changes
Copilot reviewed 37 out of 38 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| adminforth/modules/logger.ts | New centralized logging module with three logger instances |
| adminforth/package.json | Added pino and pino-pretty dependencies |
| adminforth/servers/express.ts | Replaced console.log with afLogger calls |
| adminforth/modules/socketBroker.ts | Converted debug logs to afLogger.trace |
| adminforth/modules/restApi.ts | Replaced console.log with afLogger calls |
| adminforth/modules/codeInjector.ts | Converted debug and info logs to afLogger |
| adminforth/index.ts | Exported logger and replaced console.log with afLogger |
| adminforth/dataConnectors/*.ts | Replaced database debug logs with dbLogger |
| dev-demo/resources/*.ts | Updated to use logger from adminforth |
| dev-demo/index.ts | Replaced console.log with logger calls |
| adminforth/spa/src/components/*.vue | Removed commented-out console.log statements |
| adminforth/documentation/**/*.md | Updated examples to use logger |
| adminforth/commands/**/*.js | Replaced console.log with afLogger calls |
Files not reviewed (1)
- adminforth/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 40 out of 41 changed files in this pull request and generated 9 comments.
Files not reviewed (1)
- adminforth/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 40 out of 41 changed files in this pull request and generated 2 comments.
Files not reviewed (1)
- adminforth/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 32 out of 33 changed files in this pull request and generated 10 comments.
Files not reviewed (1)
- adminforth/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| export const afLogger = baseLogger.child( | ||
| { layer: 'af' }, | ||
| { level: process.env.HEAVY_DEBUG ? 'trace' : ( process.env.AF_DEBUG_LEVEL || 'info' ) } |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra space before the opening parenthesis in line 22. This is inconsistent with lines 17 and 27. Consider removing the extra space for consistency.
| { level: process.env.HEAVY_DEBUG ? 'trace' : ( process.env.AF_DEBUG_LEVEL || 'info' ) } | |
| { level: process.env.HEAVY_DEBUG ? 'trace' : ( process.env.AF_DEBUG_LEVEL || 'info' ) } |
| if (process.env.HEAVY_DEBUG) { | ||
| console.log('🪲Interpreting resource', resource.resourceId, source, 'adminUser', adminUser); | ||
| } | ||
| afLogger.trace(`🪲Interpreting resource, ${resource.resourceId}, ${source}, 'adminUser', ${adminUser}`); |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The adminUser object is being directly interpolated into the log message without JSON.stringify. This will result in [object Object] being logged. Consider using ${JSON.stringify(adminUser)} or logging specific properties like ${adminUser.username} for better log readability.
| afLogger.trace(`🪲Interpreting resource, ${resource.resourceId}, ${source}, 'adminUser', ${adminUser}`); | |
| afLogger.trace(`🪲Interpreting resource, ${resource.resourceId}, ${source}, 'adminUser', ${JSON.stringify(adminUser)}`); |
| type: AdminForthDataTypes.STRING, | ||
| }); | ||
| console.log('Adding passwordHashField to userResource', userResource) | ||
| afLogger.info(`Adding passwordHashField to userResource, ${userResource}`); |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The userResource object is being directly interpolated into the log message without JSON.stringify. This will result in [object Object] being logged. Consider using ${JSON.stringify(userResource)} or logging specific properties like ${userResource.resourceId} for better log readability.
| afLogger.info(`Adding passwordHashField to userResource, ${userResource}`); | |
| afLogger.info(`Adding passwordHashField to userResource, resourceId=${userResource.resourceId}`); |
| // execute hook if needed | ||
| for (const hook of listify(resource.hooks?.create?.beforeSave)) { | ||
| console.log('🪲 Hook beforeSave', hook); | ||
| afLogger.debug(`🪲 Hook beforeSave ${hook}`); |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hook function object is being directly interpolated into the log message without proper conversion. This will result in [Function: functionName] or similar being logged. Consider logging ${hook.name} if you want the function name, or removing it if the message is sufficient without it.
| export const logger = baseLogger.child( | ||
| { layer: 'user_logs' }, | ||
| { level: process.env.HEAVY_DEBUG ? 'trace' : ( process.env.DEBUG_LEVEL || 'info' ) } | ||
| ); | ||
|
|
||
| export const afLogger = baseLogger.child( | ||
| { layer: 'af' }, | ||
| { level: process.env.HEAVY_DEBUG ? 'trace' : ( process.env.AF_DEBUG_LEVEL || 'info' ) } | ||
| ); | ||
|
|
||
| export const dbLogger = baseLogger.child( | ||
| { layer: 'db' }, | ||
| { level: process.env.HEAVY_DEBUG_QUERY ? 'trace' : (process.env.DB_DEBUG_LEVEL|| 'info') } | ||
| ); No newline at end of file |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logger children are configured with a level option in the second parameter, but pino's child method expects the level to be part of the first parameter (the bindings object). The current configuration will not set the log level correctly. The level should be moved to the first parameter or set separately using a different approach.
| export const logger = baseLogger.child( | |
| { layer: 'user_logs' }, | |
| { level: process.env.HEAVY_DEBUG ? 'trace' : ( process.env.DEBUG_LEVEL || 'info' ) } | |
| ); | |
| export const afLogger = baseLogger.child( | |
| { layer: 'af' }, | |
| { level: process.env.HEAVY_DEBUG ? 'trace' : ( process.env.AF_DEBUG_LEVEL || 'info' ) } | |
| ); | |
| export const dbLogger = baseLogger.child( | |
| { layer: 'db' }, | |
| { level: process.env.HEAVY_DEBUG_QUERY ? 'trace' : (process.env.DB_DEBUG_LEVEL|| 'info') } | |
| ); | |
| export const logger = baseLogger.child({ | |
| layer: 'user_logs', | |
| level: process.env.HEAVY_DEBUG ? 'trace' : ( process.env.DEBUG_LEVEL || 'info' ), | |
| }); | |
| export const afLogger = baseLogger.child({ | |
| layer: 'af', | |
| level: process.env.HEAVY_DEBUG ? 'trace' : ( process.env.AF_DEBUG_LEVEL || 'info' ), | |
| }); | |
| export const dbLogger = baseLogger.child({ | |
| layer: 'db', | |
| level: process.env.HEAVY_DEBUG_QUERY ? 'trace' : (process.env.DB_DEBUG_LEVEL|| 'info'), | |
| }); |
| } | ||
| this.expressApp.get(`${slashedPrefix}assets/*`, handler); | ||
| process.env.HEAVY_DEBUG && console.log('®️ Registering SPA serve handler', `${slashedPrefix}assets/*`); | ||
| afLogger.trace(`®️ Registering SPA serve handler', ${slashedPrefix}assets/*`); |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a mismatched quote in the template literal. The string starts with a backtick and contains a single quote that should be removed or the template literal should be properly closed. The correct format should be: ®️ Registering SPA serve handler, ${slashedPrefix}assets/* (removing the single quote after 'handler').
| afLogger.trace(`®️ Registering SPA serve handler', ${slashedPrefix}assets/*`); | |
| afLogger.trace(`®️ Registering SPA serve handler, ${slashedPrefix}assets/*`); |
| if (filterUsers) { | ||
| if (! (await filterUsers(client.adminUser)) ) { | ||
| process.env.HEAVY_DEBUG && console.log('Client not authorized to receive message', topic, client.adminUser); | ||
| afLogger.trace(`Client not authorized to receive message ${topic} ${client.adminUser}`); |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The client.adminUser object is being directly interpolated into the log message without JSON.stringify. This will result in [object Object] being logged. Consider using ${JSON.stringify(client.adminUser)} or logging specific properties like ${client.adminUser.username} for better log readability.
| afLogger.trace(`Client not authorized to receive message ${topic} ${client.adminUser}`); | |
| afLogger.trace(`Client not authorized to receive message ${topic} ${JSON.stringify(client.adminUser)}`); |
| ```javascript | ||
| import websocket from '@/websocket'; | ||
| import { logger } from 'adminforth' | ||
|
|
||
| websocket.subscribe('/topic-name', (data) => { | ||
| // this callback called when we receive publish in topic from the websocket | ||
| console.log(data); | ||
| logger.info(data); |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logger import import { logger } from 'adminforth' is shown in a frontend JavaScript context (subscribing to websocket in a Vue component). However, the logger is a backend-only module using pino, which won't work in the browser. If logging is needed in frontend code, consider using console.log or a browser-compatible logging solution. Remove this import from the frontend example.
| // execute hook if needed | ||
| for (const hook of listify(resource.hooks?.create?.afterSave)) { | ||
| process.env.HEAVY_DEBUG && console.log('🪲 Hook afterSave', hook); | ||
| afLogger.trace(`🪲 Hook afterSave ${hook}`); |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hook function object is being directly interpolated into the log message without proper conversion. This will result in [Function: functionName] or similar being logged. Consider logging ${hook.name} if you want the function name, or removing it if the message is sufficient without it.
| afLogger.trace(`🪲 Hook afterSave ${hook}`); | |
| afLogger.trace(`🪲 Hook afterSave ${hook.name || 'anonymous'}`); |
No description provided.