strapi-plugin-magic-sessionmanager 4.2.0 → 4.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,84 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Debug Logger Utility for magic-sessionmanager
5
+ * Only logs messages when debug: true in plugin config
6
+ * ALL logs (including errors/warnings) are hidden unless debug mode is enabled
7
+ */
8
+
9
+ const PLUGIN_NAME = 'magic-sessionmanager';
10
+ const PREFIX = '[magic-sessionmanager]';
11
+
12
+ /**
13
+ * Format message with prefix - returns a formatted string
14
+ */
15
+ function formatMessage(prefix, args) {
16
+ if (args.length === 0) return prefix;
17
+ const parts = args.map(arg =>
18
+ typeof arg === 'string' ? arg : JSON.stringify(arg)
19
+ );
20
+ return `${prefix} ${parts.join(' ')}`;
21
+ }
22
+
23
+ /**
24
+ * Creates a logger instance that respects debug config
25
+ * @param {object} strapi - Strapi instance
26
+ * @returns {object} Logger with info, debug, warn, error methods
27
+ */
28
+ function createLogger(strapi) {
29
+ const getDebugMode = () => {
30
+ try {
31
+ const config = strapi.config.get(`plugin::${PLUGIN_NAME}`) || {};
32
+ return config.debug === true;
33
+ } catch {
34
+ return false;
35
+ }
36
+ };
37
+
38
+ return {
39
+ /**
40
+ * Log info - only when debug: true
41
+ */
42
+ info: (...args) => {
43
+ if (getDebugMode()) {
44
+ strapi.log.info(formatMessage(PREFIX, args));
45
+ }
46
+ },
47
+
48
+ /**
49
+ * Log debug - only when debug: true
50
+ */
51
+ debug: (...args) => {
52
+ if (getDebugMode()) {
53
+ strapi.log.debug(formatMessage(PREFIX, args));
54
+ }
55
+ },
56
+
57
+ /**
58
+ * Log warning - only when debug: true
59
+ */
60
+ warn: (...args) => {
61
+ if (getDebugMode()) {
62
+ strapi.log.warn(formatMessage(PREFIX, args));
63
+ }
64
+ },
65
+
66
+ /**
67
+ * Log error - only when debug: true
68
+ */
69
+ error: (...args) => {
70
+ if (getDebugMode()) {
71
+ strapi.log.error(formatMessage(PREFIX, args));
72
+ }
73
+ },
74
+
75
+ /**
76
+ * Force log - always logged (for critical errors only)
77
+ */
78
+ forceError: (...args) => {
79
+ strapi.log.error(formatMessage(PREFIX, args));
80
+ },
81
+ };
82
+ }
83
+
84
+ module.exports = { createLogger };