Skip to content

Commit 3bc45ba

Browse files
committed
fix: add debug mode for plugin logging
- Add logger utility with debug config support - All logs (info, debug, warn, error) now respect debug: true/false in plugin config - Default debug: false keeps console clean - Set debug: true in plugin config to see all logs
1 parent 56b0670 commit 3bc45ba

7 files changed

Lines changed: 180 additions & 309 deletions

File tree

RELEASE_CHECKLIST.md

Lines changed: 0 additions & 236 deletions
This file was deleted.

server/src/bootstrap.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import type { Core } from '@strapi/strapi';
2+
import { createLogger } from './utils/logger';
23

34
export default ({ strapi }: { strapi: Core.Strapi }) => {
4-
strapi.log.info('[Magic-Mark] Plugin bootstrapping...');
5+
const log = createLogger(strapi);
6+
7+
log.info('Plugin bootstrapping...');
58

69
// Initialize License Guard
710
try {
@@ -12,16 +15,16 @@ export default ({ strapi }: { strapi: Core.Strapi }) => {
1215
const licenseStatus = await licenseGuardService.initialize();
1316

1417
if (!licenseStatus.valid) {
15-
strapi.log.error('╔════════════════════════════════════════════════════════════════╗');
16-
strapi.log.error('║ [ERROR] MAGICMARK PLUGIN - NO VALID LICENSE ║');
17-
strapi.log.error('║ ║');
18-
strapi.log.error('║ This plugin requires a valid license to operate. ║');
19-
strapi.log.error('║ Please activate your license via Admin UI: ║');
20-
strapi.log.error('║ Go to Settings → MagicMark → License ║');
21-
strapi.log.error('║ ║');
22-
strapi.log.error('║ The plugin will run with limited functionality until ║');
23-
strapi.log.error('║ a valid license is activated. ║');
24-
strapi.log.error('╚════════════════════════════════════════════════════════════════╝');
18+
log.error('╔════════════════════════════════════════════════════════════════╗');
19+
log.error('║ [ERROR] MAGICMARK PLUGIN - NO VALID LICENSE ║');
20+
log.error('║ ║');
21+
log.error('║ This plugin requires a valid license to operate. ║');
22+
log.error('║ Please activate your license via Admin UI: ║');
23+
log.error('║ Go to Settings → MagicMark → License ║');
24+
log.error('║ ║');
25+
log.error('║ The plugin will run with limited functionality until ║');
26+
log.error('║ a valid license is activated. ║');
27+
log.error('╚════════════════════════════════════════════════════════════════╝');
2528
} else if (licenseStatus.valid) {
2629
// Get license key from store if data is not available (grace period)
2730
const pluginStore = strapi.store({
@@ -30,27 +33,27 @@ export default ({ strapi }: { strapi: Core.Strapi }) => {
3033
});
3134
const storedKey = await pluginStore.get({ key: 'licenseKey' }) as string | undefined;
3235

33-
strapi.log.info('╔════════════════════════════════════════════════════════════════╗');
34-
strapi.log.info('║ [SUCCESS] MAGICMARK PLUGIN LICENSE ACTIVE ║');
35-
strapi.log.info('║ ║');
36+
log.info('╔════════════════════════════════════════════════════════════════╗');
37+
log.info('║ [SUCCESS] MAGICMARK PLUGIN LICENSE ACTIVE ║');
38+
log.info('║ ║');
3639

3740
if (licenseStatus.data) {
38-
strapi.log.info(`║ License: ${licenseStatus.data.licenseKey} ║`);
39-
strapi.log.info(`║ User: ${licenseStatus.data.firstName} ${licenseStatus.data.lastName}`.padEnd(66) + '║');
40-
strapi.log.info(`║ Email: ${licenseStatus.data.email}`.padEnd(66) + '║');
41+
log.info(`║ License: ${licenseStatus.data.licenseKey} ║`);
42+
log.info(`║ User: ${licenseStatus.data.firstName} ${licenseStatus.data.lastName}`.padEnd(66) + '║');
43+
log.info(`║ Email: ${licenseStatus.data.email}`.padEnd(66) + '║');
4144
} else if (storedKey) {
42-
strapi.log.info(`║ License: ${storedKey} (Offline Mode) ║`);
43-
strapi.log.info(`║ Status: Grace Period Active ║`);
45+
log.info(`║ License: ${storedKey} (Offline Mode) ║`);
46+
log.info(`║ Status: Grace Period Active ║`);
4447
}
4548

46-
strapi.log.info('║ ║');
47-
strapi.log.info('║ [PING] Auto-pinging every 15 minutes ║');
48-
strapi.log.info('╚════════════════════════════════════════════════════════════════╝');
49+
log.info('║ ║');
50+
log.info('║ [PING] Auto-pinging every 15 minutes ║');
51+
log.info('╚════════════════════════════════════════════════════════════════╝');
4952
}
5053
}, 3000); // Wait 3 seconds for API to be ready
5154
} catch (error) {
52-
strapi.log.error('[ERROR] Error initializing License Guard:', error);
55+
log.error('[ERROR] Error initializing License Guard:', error);
5356
}
5457

55-
strapi.log.info('[Magic-Mark] Plugin bootstrapped successfully');
58+
log.info('Plugin bootstrapped successfully');
5659
};

server/src/config/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
export default {
2-
default: {},
2+
default: {
3+
// Enable debug logging (set to true to see all plugin logs)
4+
debug: false,
5+
},
36
validator: () => {},
47
};

server/src/destroy.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import type { Core } from '@strapi/strapi';
2+
import { createLogger } from './utils/logger';
23

34
export default ({ strapi }: { strapi: Core.Strapi }) => {
5+
const log = createLogger(strapi);
6+
47
// Cleanup License Guard ping interval
58
try {
69
const licenseGuardService = strapi.plugin('magic-mark')?.service('license-guard');
710
if (licenseGuardService) {
811
licenseGuardService.cleanup();
9-
strapi.log.info('[SUCCESS] License Guard cleanup completed');
12+
log.info('[SUCCESS] License Guard cleanup completed');
1013
}
1114
} catch (error) {
12-
strapi.log.error('[ERROR] Error during License Guard cleanup:', error);
15+
log.error('[ERROR] Error during License Guard cleanup:', error);
1316
}
1417
};

server/src/register.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Core } from '@strapi/strapi';
2+
import { createLogger } from './utils/logger';
23

34
const magicMarkActions = {
45
actions: [
@@ -20,10 +21,12 @@ const magicMarkActions = {
2021
};
2122

2223
export default async ({ strapi }: { strapi: Core.Strapi }) => {
24+
const log = createLogger(strapi);
25+
2326
// Register permissions
2427
await strapi.admin.services.permission.actionProvider.registerMany(
2528
magicMarkActions.actions
2629
);
2730

28-
strapi.log.info('[Magic-Mark] Plugin registered successfully');
31+
log.info('Plugin registered successfully');
2932
};

0 commit comments

Comments
 (0)