@momentumcms/logger 0.0.1 → 0.1.2

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/index.js +249 -0
  3. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 0.1.2 (2026-02-16)
2
+
3
+ ### 🩹 Fixes
4
+
5
+ - **release:** centralize manifestRootsToUpdate to update both source and dist ([2b8f832](https://github.com/DonaldMurillo/momentum-cms/commit/2b8f832))
6
+ - **create-app:** fix Angular SSR, Analog builds, and CJS/ESM compatibility ([28d4d0a](https://github.com/DonaldMurillo/momentum-cms/commit/28d4d0a))
7
+
8
+ ### ❤️ Thank You
9
+
10
+ - Claude Opus 4.6
11
+ - Donald Murillo @DonaldMurillo
12
+
1
13
  ## 0.1.1 (2026-02-16)
2
14
 
3
15
  This was a version bump only for logger to align it with other projects, there were no code changes.
package/index.js ADDED
@@ -0,0 +1,249 @@
1
+ // libs/logger/src/lib/log-level.ts
2
+ var LOG_LEVEL_VALUES = {
3
+ debug: 0,
4
+ info: 1,
5
+ warn: 2,
6
+ error: 3,
7
+ fatal: 4,
8
+ silent: 5
9
+ };
10
+ function shouldLog(messageLevel, configuredLevel) {
11
+ return LOG_LEVEL_VALUES[messageLevel] >= LOG_LEVEL_VALUES[configuredLevel];
12
+ }
13
+
14
+ // libs/logger/src/lib/ansi-colors.ts
15
+ var ANSI = {
16
+ reset: "\x1B[0m",
17
+ bold: "\x1B[1m",
18
+ dim: "\x1B[2m",
19
+ // Foreground colors
20
+ red: "\x1B[31m",
21
+ green: "\x1B[32m",
22
+ yellow: "\x1B[33m",
23
+ blue: "\x1B[34m",
24
+ magenta: "\x1B[35m",
25
+ cyan: "\x1B[36m",
26
+ white: "\x1B[37m",
27
+ gray: "\x1B[90m",
28
+ // Background colors
29
+ bgRed: "\x1B[41m",
30
+ bgYellow: "\x1B[43m"
31
+ };
32
+ function colorize(text, ...codes) {
33
+ if (codes.length === 0)
34
+ return text;
35
+ return `${codes.join("")}${text}${ANSI.reset}`;
36
+ }
37
+ function supportsColor() {
38
+ if (process.env["FORCE_COLOR"] === "1")
39
+ return true;
40
+ if (process.env["NO_COLOR"] !== void 0)
41
+ return false;
42
+ if (process.env["TERM"] === "dumb")
43
+ return false;
44
+ return process.stdout.isTTY === true;
45
+ }
46
+
47
+ // libs/logger/src/lib/formatters.ts
48
+ var LEVEL_COLORS = {
49
+ debug: [ANSI.dim, ANSI.gray],
50
+ info: [ANSI.cyan],
51
+ warn: [ANSI.yellow],
52
+ error: [ANSI.red],
53
+ fatal: [ANSI.bold, ANSI.white, ANSI.bgRed]
54
+ };
55
+ function padLevel(level) {
56
+ return level.toUpperCase().padEnd(5);
57
+ }
58
+ function formatTimestamp(date) {
59
+ const y = date.getFullYear();
60
+ const mo = String(date.getMonth() + 1).padStart(2, "0");
61
+ const d = String(date.getDate()).padStart(2, "0");
62
+ const h = String(date.getHours()).padStart(2, "0");
63
+ const mi = String(date.getMinutes()).padStart(2, "0");
64
+ const s = String(date.getSeconds()).padStart(2, "0");
65
+ const ms = String(date.getMilliseconds()).padStart(3, "0");
66
+ return `${y}-${mo}-${d} ${h}:${mi}:${s}.${ms}`;
67
+ }
68
+ function formatData(data) {
69
+ const entries = Object.entries(data);
70
+ if (entries.length === 0)
71
+ return "";
72
+ return " " + entries.map(([k, v]) => `${k}=${typeof v === "string" ? v : JSON.stringify(v)}`).join(" ");
73
+ }
74
+ function prettyFormatter(entry) {
75
+ const useColor = supportsColor();
76
+ const level = entry.level;
77
+ const ts = formatTimestamp(entry.timestamp);
78
+ const levelStr = padLevel(entry.level);
79
+ const ctx = `[${entry.context}]`;
80
+ const msg = entry.message;
81
+ const enrichmentStr = entry.enrichments ? formatData(entry.enrichments) : "";
82
+ const dataStr = entry.data ? formatData(entry.data) : "";
83
+ const extra = `${enrichmentStr}${dataStr}`;
84
+ if (useColor) {
85
+ const colors = LEVEL_COLORS[level];
86
+ const coloredLevel = colorize(levelStr, ...colors);
87
+ const coloredCtx = colorize(ctx, ANSI.magenta);
88
+ const coloredTs = colorize(ts, ANSI.gray);
89
+ return `${coloredTs} ${coloredLevel} ${coloredCtx} ${msg}${extra}
90
+ `;
91
+ }
92
+ return `${ts} ${levelStr} ${ctx} ${msg}${extra}
93
+ `;
94
+ }
95
+ function jsonFormatter(entry) {
96
+ const output = {
97
+ timestamp: entry.timestamp.toISOString(),
98
+ level: entry.level,
99
+ context: entry.context,
100
+ message: entry.message
101
+ };
102
+ if (entry.enrichments && Object.keys(entry.enrichments).length > 0) {
103
+ Object.assign(output, entry.enrichments);
104
+ }
105
+ if (entry.data && Object.keys(entry.data).length > 0) {
106
+ output["data"] = entry.data;
107
+ }
108
+ return JSON.stringify(output) + "\n";
109
+ }
110
+
111
+ // libs/logger/src/lib/logger-config.types.ts
112
+ function resolveLoggingConfig(config) {
113
+ return {
114
+ level: config?.level ?? "info",
115
+ format: config?.format ?? "pretty",
116
+ timestamps: config?.timestamps ?? true,
117
+ output: config?.output ?? ((msg) => {
118
+ process.stdout.write(msg);
119
+ }),
120
+ errorOutput: config?.errorOutput ?? ((msg) => {
121
+ process.stderr.write(msg);
122
+ })
123
+ };
124
+ }
125
+
126
+ // libs/logger/src/lib/logger.ts
127
+ var ERROR_LEVELS = /* @__PURE__ */ new Set(["warn", "error", "fatal"]);
128
+ var MomentumLogger = class _MomentumLogger {
129
+ static {
130
+ this.enrichers = [];
131
+ }
132
+ constructor(context, config) {
133
+ this.context = context;
134
+ this.config = isResolvedConfig(config) ? config : resolveLoggingConfig(config);
135
+ this.formatter = this.config.format === "json" ? jsonFormatter : prettyFormatter;
136
+ }
137
+ debug(message, data) {
138
+ this.log("debug", message, data);
139
+ }
140
+ info(message, data) {
141
+ this.log("info", message, data);
142
+ }
143
+ warn(message, data) {
144
+ this.log("warn", message, data);
145
+ }
146
+ error(message, data) {
147
+ this.log("error", message, data);
148
+ }
149
+ fatal(message, data) {
150
+ this.log("fatal", message, data);
151
+ }
152
+ /**
153
+ * Creates a child logger with a sub-context.
154
+ * e.g., `Momentum:DB` → `Momentum:DB:Migrate`
155
+ */
156
+ child(subContext) {
157
+ return new _MomentumLogger(`${this.context}:${subContext}`, this.config);
158
+ }
159
+ /**
160
+ * Registers a global enricher that adds extra fields to all log entries.
161
+ */
162
+ static registerEnricher(enricher) {
163
+ _MomentumLogger.enrichers.push(enricher);
164
+ }
165
+ /**
166
+ * Removes a previously registered enricher.
167
+ */
168
+ static removeEnricher(enricher) {
169
+ const index = _MomentumLogger.enrichers.indexOf(enricher);
170
+ if (index >= 0) {
171
+ _MomentumLogger.enrichers.splice(index, 1);
172
+ }
173
+ }
174
+ /**
175
+ * Clears all registered enrichers. Primarily for testing.
176
+ */
177
+ static clearEnrichers() {
178
+ _MomentumLogger.enrichers.length = 0;
179
+ }
180
+ log(level, message, data) {
181
+ if (!shouldLog(level, this.config.level))
182
+ return;
183
+ const enrichments = this.collectEnrichments();
184
+ const entry = {
185
+ timestamp: /* @__PURE__ */ new Date(),
186
+ level,
187
+ context: this.context,
188
+ message,
189
+ data,
190
+ enrichments: Object.keys(enrichments).length > 0 ? enrichments : void 0
191
+ };
192
+ const formatted = this.formatter(entry);
193
+ if (ERROR_LEVELS.has(level)) {
194
+ this.config.errorOutput(formatted);
195
+ } else {
196
+ this.config.output(formatted);
197
+ }
198
+ }
199
+ collectEnrichments() {
200
+ const result = {};
201
+ for (const enricher of _MomentumLogger.enrichers) {
202
+ Object.assign(result, enricher.enrich());
203
+ }
204
+ return result;
205
+ }
206
+ };
207
+ function isResolvedConfig(config) {
208
+ if (!config)
209
+ return false;
210
+ return typeof config.level === "string" && typeof config.format === "string" && typeof config.timestamps === "boolean" && // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- type guard narrows union
211
+ typeof config.output === "function" && // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- type guard narrows union
212
+ typeof config.errorOutput === "function";
213
+ }
214
+
215
+ // libs/logger/src/lib/logger-singleton.ts
216
+ var loggerInstance = null;
217
+ var ROOT_CONTEXT = "Momentum";
218
+ function initializeMomentumLogger(config) {
219
+ loggerInstance = new MomentumLogger(ROOT_CONTEXT, config);
220
+ return loggerInstance;
221
+ }
222
+ function getMomentumLogger() {
223
+ if (!loggerInstance) {
224
+ loggerInstance = new MomentumLogger(ROOT_CONTEXT);
225
+ }
226
+ return loggerInstance;
227
+ }
228
+ function createLogger(context) {
229
+ return getMomentumLogger().child(context);
230
+ }
231
+ function resetMomentumLogger() {
232
+ loggerInstance = null;
233
+ MomentumLogger.clearEnrichers();
234
+ }
235
+ export {
236
+ ANSI,
237
+ LOG_LEVEL_VALUES,
238
+ MomentumLogger,
239
+ colorize,
240
+ createLogger,
241
+ getMomentumLogger,
242
+ initializeMomentumLogger,
243
+ jsonFormatter,
244
+ prettyFormatter,
245
+ resetMomentumLogger,
246
+ resolveLoggingConfig,
247
+ shouldLog,
248
+ supportsColor
249
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momentumcms/logger",
3
- "version": "0.0.1",
3
+ "version": "0.1.2",
4
4
  "description": "Structured logging for Momentum CMS",
5
5
  "license": "MIT",
6
6
  "author": "Momentum CMS Contributors",
@@ -22,8 +22,8 @@
22
22
  "engines": {
23
23
  "node": ">=18"
24
24
  },
25
- "type": "commonjs",
26
25
  "main": "./index.cjs",
27
26
  "types": "./src/index.d.ts",
28
- "dependencies": {}
27
+ "dependencies": {},
28
+ "module": "./index.js"
29
29
  }