Skip to content

Conversation

@yaroslav8765
Copy link
Contributor

No description provided.

Copy link
Contributor

Copilot AI left a 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.error and process.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.

Copy link
Contributor

Copilot AI left a 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.

Copy link
Contributor

Copilot AI left a 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.

Copy link
Contributor

Copilot AI left a 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' ) }
Copy link

Copilot AI Jan 12, 2026

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.

Suggested change
{ level: process.env.HEAVY_DEBUG ? 'trace' : ( process.env.AF_DEBUG_LEVEL || 'info' ) }
{ level: process.env.HEAVY_DEBUG ? 'trace' : ( process.env.AF_DEBUG_LEVEL || 'info' ) }

Copilot uses AI. Check for mistakes.
if (process.env.HEAVY_DEBUG) {
console.log('🪲Interpreting resource', resource.resourceId, source, 'adminUser', adminUser);
}
afLogger.trace(`🪲Interpreting resource, ${resource.resourceId}, ${source}, 'adminUser', ${adminUser}`);
Copy link

Copilot AI Jan 12, 2026

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.

Suggested change
afLogger.trace(`🪲Interpreting resource, ${resource.resourceId}, ${source}, 'adminUser', ${adminUser}`);
afLogger.trace(`🪲Interpreting resource, ${resource.resourceId}, ${source}, 'adminUser', ${JSON.stringify(adminUser)}`);

Copilot uses AI. Check for mistakes.
type: AdminForthDataTypes.STRING,
});
console.log('Adding passwordHashField to userResource', userResource)
afLogger.info(`Adding passwordHashField to userResource, ${userResource}`);
Copy link

Copilot AI Jan 12, 2026

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.

Suggested change
afLogger.info(`Adding passwordHashField to userResource, ${userResource}`);
afLogger.info(`Adding passwordHashField to userResource, resourceId=${userResource.resourceId}`);

Copilot uses AI. Check for mistakes.
// execute hook if needed
for (const hook of listify(resource.hooks?.create?.beforeSave)) {
console.log('🪲 Hook beforeSave', hook);
afLogger.debug(`🪲 Hook beforeSave ${hook}`);
Copy link

Copilot AI Jan 12, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +28
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
Copy link

Copilot AI Jan 12, 2026

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.

Suggested change
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'),
});

Copilot uses AI. Check for mistakes.
}
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/*`);
Copy link

Copilot AI Jan 12, 2026

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').

Suggested change
afLogger.trace(`®️ Registering SPA serve handler', ${slashedPrefix}assets/*`);
afLogger.trace(`®️ Registering SPA serve handler, ${slashedPrefix}assets/*`);

Copilot uses AI. Check for mistakes.
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}`);
Copy link

Copilot AI Jan 12, 2026

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.

Suggested change
afLogger.trace(`Client not authorized to receive message ${topic} ${client.adminUser}`);
afLogger.trace(`Client not authorized to receive message ${topic} ${JSON.stringify(client.adminUser)}`);

Copilot uses AI. Check for mistakes.
Comment on lines 8 to +14
```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);
Copy link

Copilot AI Jan 12, 2026

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.

Copilot uses AI. Check for mistakes.
// 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}`);
Copy link

Copilot AI Jan 12, 2026

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.

Suggested change
afLogger.trace(`🪲 Hook afterSave ${hook}`);
afLogger.trace(`🪲 Hook afterSave ${hook.name || 'anonymous'}`);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants