@jungjaehoon/mama-core 1.0.1

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,86 @@
1
+ /**
2
+ * DebugLogger - Centralized logging for MAMA hooks
3
+ *
4
+ * CLAUDE.md Compliant:
5
+ * - NO console.log (use DebugLogger.info instead)
6
+ * - console.error/warn allowed but wrapped for consistency
7
+ *
8
+ * Features:
9
+ * - Log levels (DEBUG, INFO, WARN, ERROR)
10
+ * - Timestamp formatting
11
+ * - Environment-based filtering
12
+ * - Module/context tagging
13
+ */
14
+
15
+ const LOG_LEVELS = {
16
+ DEBUG: 0,
17
+ INFO: 1,
18
+ WARN: 2,
19
+ ERROR: 3,
20
+ NONE: 4,
21
+ };
22
+
23
+ class DebugLogger {
24
+ constructor(context = 'MAMA') {
25
+ this.context = context;
26
+ this.level = this._getLogLevel();
27
+ }
28
+
29
+ _getLogLevel() {
30
+ // Changed default from 'INFO' to 'ERROR' for cleaner output
31
+ // Users can override with MAMA_LOG_LEVEL env var
32
+ const env = process.env.MAMA_LOG_LEVEL || 'ERROR';
33
+ return LOG_LEVELS[env.toUpperCase()] ?? LOG_LEVELS.ERROR;
34
+ }
35
+
36
+ _shouldLog(level) {
37
+ return LOG_LEVELS[level] >= this.level;
38
+ }
39
+
40
+ _formatMessage(level, ...args) {
41
+ const timestamp = new Date().toISOString();
42
+ const prefix = `[${timestamp}] [${this.context}] [${level}]`;
43
+ return [prefix, ...args];
44
+ }
45
+
46
+ debug(...args) {
47
+ if (!this._shouldLog('DEBUG')) {
48
+ return;
49
+ }
50
+ console.error(...this._formatMessage('DEBUG', ...args));
51
+ }
52
+
53
+ info(...args) {
54
+ if (!this._shouldLog('INFO')) {
55
+ return;
56
+ }
57
+ console.error(...this._formatMessage('INFO', ...args));
58
+ }
59
+
60
+ warn(...args) {
61
+ if (!this._shouldLog('WARN')) {
62
+ return;
63
+ }
64
+ console.warn(...this._formatMessage('WARN', ...args));
65
+ }
66
+
67
+ error(...args) {
68
+ if (!this._shouldLog('ERROR')) {
69
+ return;
70
+ }
71
+ console.error(...this._formatMessage('ERROR', ...args));
72
+ }
73
+ }
74
+
75
+ // Export singleton with default context
76
+ const logger = new DebugLogger('MAMA');
77
+
78
+ // Export class for custom contexts
79
+ module.exports = {
80
+ DebugLogger,
81
+ default: logger,
82
+ debug: (...args) => logger.debug(...args),
83
+ info: (...args) => logger.info(...args),
84
+ warn: (...args) => logger.warn(...args),
85
+ error: (...args) => logger.error(...args),
86
+ };