@logtape/logtape 1.0.0-dev.241 → 1.0.0-dev.247

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.
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logtape/logtape",
3
- "version": "1.0.0-dev.241+13810dcf",
3
+ "version": "1.0.0-dev.247+ffe631a6",
4
4
  "license": "MIT",
5
5
  "exports": "./mod.ts",
6
6
  "imports": {
@@ -32,6 +32,123 @@ const inspect = typeof document !== "undefined" || typeof navigator !== "undefin
32
32
  maxStringLength: Infinity,
33
33
  ...opts
34
34
  }) : (v) => JSON.stringify(v);
35
+ function padZero(num) {
36
+ return num < 10 ? `0${num}` : `${num}`;
37
+ }
38
+ function padThree(num) {
39
+ return num < 10 ? `00${num}` : num < 100 ? `0${num}` : `${num}`;
40
+ }
41
+ const timestampFormatters = {
42
+ "date-time-timezone": (ts) => {
43
+ const d = new Date(ts);
44
+ const year = d.getUTCFullYear();
45
+ const month = padZero(d.getUTCMonth() + 1);
46
+ const day = padZero(d.getUTCDate());
47
+ const hour = padZero(d.getUTCHours());
48
+ const minute = padZero(d.getUTCMinutes());
49
+ const second = padZero(d.getUTCSeconds());
50
+ const ms = padThree(d.getUTCMilliseconds());
51
+ return `${year}-${month}-${day} ${hour}:${minute}:${second}.${ms} +00:00`;
52
+ },
53
+ "date-time-tz": (ts) => {
54
+ const d = new Date(ts);
55
+ const year = d.getUTCFullYear();
56
+ const month = padZero(d.getUTCMonth() + 1);
57
+ const day = padZero(d.getUTCDate());
58
+ const hour = padZero(d.getUTCHours());
59
+ const minute = padZero(d.getUTCMinutes());
60
+ const second = padZero(d.getUTCSeconds());
61
+ const ms = padThree(d.getUTCMilliseconds());
62
+ return `${year}-${month}-${day} ${hour}:${minute}:${second}.${ms} +00`;
63
+ },
64
+ "date-time": (ts) => {
65
+ const d = new Date(ts);
66
+ const year = d.getUTCFullYear();
67
+ const month = padZero(d.getUTCMonth() + 1);
68
+ const day = padZero(d.getUTCDate());
69
+ const hour = padZero(d.getUTCHours());
70
+ const minute = padZero(d.getUTCMinutes());
71
+ const second = padZero(d.getUTCSeconds());
72
+ const ms = padThree(d.getUTCMilliseconds());
73
+ return `${year}-${month}-${day} ${hour}:${minute}:${second}.${ms}`;
74
+ },
75
+ "time-timezone": (ts) => {
76
+ const d = new Date(ts);
77
+ const hour = padZero(d.getUTCHours());
78
+ const minute = padZero(d.getUTCMinutes());
79
+ const second = padZero(d.getUTCSeconds());
80
+ const ms = padThree(d.getUTCMilliseconds());
81
+ return `${hour}:${minute}:${second}.${ms} +00:00`;
82
+ },
83
+ "time-tz": (ts) => {
84
+ const d = new Date(ts);
85
+ const hour = padZero(d.getUTCHours());
86
+ const minute = padZero(d.getUTCMinutes());
87
+ const second = padZero(d.getUTCSeconds());
88
+ const ms = padThree(d.getUTCMilliseconds());
89
+ return `${hour}:${minute}:${second}.${ms} +00`;
90
+ },
91
+ "time": (ts) => {
92
+ const d = new Date(ts);
93
+ const hour = padZero(d.getUTCHours());
94
+ const minute = padZero(d.getUTCMinutes());
95
+ const second = padZero(d.getUTCSeconds());
96
+ const ms = padThree(d.getUTCMilliseconds());
97
+ return `${hour}:${minute}:${second}.${ms}`;
98
+ },
99
+ "date": (ts) => {
100
+ const d = new Date(ts);
101
+ const year = d.getUTCFullYear();
102
+ const month = padZero(d.getUTCMonth() + 1);
103
+ const day = padZero(d.getUTCDate());
104
+ return `${year}-${month}-${day}`;
105
+ },
106
+ "rfc3339": (ts) => new Date(ts).toISOString(),
107
+ "none": () => null
108
+ };
109
+ const levelRenderersCache = {
110
+ ABBR: levelAbbreviations,
111
+ abbr: {
112
+ trace: "trc",
113
+ debug: "dbg",
114
+ info: "inf",
115
+ warning: "wrn",
116
+ error: "err",
117
+ fatal: "ftl"
118
+ },
119
+ FULL: {
120
+ trace: "TRACE",
121
+ debug: "DEBUG",
122
+ info: "INFO",
123
+ warning: "WARNING",
124
+ error: "ERROR",
125
+ fatal: "FATAL"
126
+ },
127
+ full: {
128
+ trace: "trace",
129
+ debug: "debug",
130
+ info: "info",
131
+ warning: "warning",
132
+ error: "error",
133
+ fatal: "fatal"
134
+ },
135
+ L: {
136
+ trace: "T",
137
+ debug: "D",
138
+ info: "I",
139
+ warning: "W",
140
+ error: "E",
141
+ fatal: "F"
142
+ },
143
+ l: {
144
+ trace: "t",
145
+ debug: "d",
146
+ info: "i",
147
+ warning: "w",
148
+ error: "e",
149
+ fatal: "f"
150
+ }
151
+ };
35
152
  /**
36
153
  * Get a text formatter with the specified options. Although it's flexible
37
154
  * enough to create a custom formatter, if you want more control, you can
@@ -50,15 +167,39 @@ const inspect = typeof document !== "undefined" || typeof navigator !== "undefin
50
167
  * @since 0.6.0
51
168
  */
52
169
  function getTextFormatter(options = {}) {
53
- const timestampRenderer = options.timestamp == null || options.timestamp === "date-time-timezone" ? (ts) => new Date(ts).toISOString().replace("T", " ").replace("Z", " +00:00") : options.timestamp === "date-time-tz" ? (ts) => new Date(ts).toISOString().replace("T", " ").replace("Z", " +00") : options.timestamp === "date-time" ? (ts) => new Date(ts).toISOString().replace("T", " ").replace("Z", "") : options.timestamp === "time-timezone" ? (ts) => new Date(ts).toISOString().replace(/.*T/, "").replace("Z", " +00:00") : options.timestamp === "time-tz" ? (ts) => new Date(ts).toISOString().replace(/.*T/, "").replace("Z", " +00") : options.timestamp === "time" ? (ts) => new Date(ts).toISOString().replace(/.*T/, "").replace("Z", "") : options.timestamp === "date" ? (ts) => new Date(ts).toISOString().replace(/T.*/, "") : options.timestamp === "rfc3339" ? (ts) => new Date(ts).toISOString() : options.timestamp === "none" || options.timestamp === "disabled" ? () => null : options.timestamp;
170
+ const timestampRenderer = (() => {
171
+ const tsOption = options.timestamp;
172
+ if (tsOption == null) return timestampFormatters["date-time-timezone"];
173
+ else if (tsOption === "disabled") return timestampFormatters["none"];
174
+ else if (typeof tsOption === "string" && tsOption in timestampFormatters) return timestampFormatters[tsOption];
175
+ else return tsOption;
176
+ })();
54
177
  const categorySeparator = options.category ?? "·";
55
178
  const valueRenderer = options.value ?? inspect;
56
- const levelRenderer = options.level == null || options.level === "ABBR" ? (level) => levelAbbreviations[level] : options.level === "abbr" ? (level) => levelAbbreviations[level].toLowerCase() : options.level === "FULL" ? (level) => level.toUpperCase() : options.level === "full" ? (level) => level : options.level === "L" ? (level) => level.charAt(0).toUpperCase() : options.level === "l" ? (level) => level.charAt(0) : options.level;
179
+ const levelRenderer = (() => {
180
+ const levelOption = options.level;
181
+ if (levelOption == null || levelOption === "ABBR") return (level) => levelRenderersCache.ABBR[level];
182
+ else if (levelOption === "abbr") return (level) => levelRenderersCache.abbr[level];
183
+ else if (levelOption === "FULL") return (level) => levelRenderersCache.FULL[level];
184
+ else if (levelOption === "full") return (level) => levelRenderersCache.full[level];
185
+ else if (levelOption === "L") return (level) => levelRenderersCache.L[level];
186
+ else if (levelOption === "l") return (level) => levelRenderersCache.l[level];
187
+ else return levelOption;
188
+ })();
57
189
  const formatter = options.format ?? (({ timestamp, level, category, message }) => `${timestamp ? `${timestamp} ` : ""}[${level}] ${category}: ${message}`);
58
190
  return (record) => {
59
- let message = "";
60
- for (let i = 0; i < record.message.length; i++) if (i % 2 === 0) message += record.message[i];
61
- else message += valueRenderer(record.message[i]);
191
+ const msgParts = record.message;
192
+ const msgLen = msgParts.length;
193
+ let message;
194
+ if (msgLen === 1) message = msgParts[0];
195
+ else if (msgLen <= 6) {
196
+ message = "";
197
+ for (let i = 0; i < msgLen; i++) message += i % 2 === 0 ? msgParts[i] : valueRenderer(msgParts[i]);
198
+ } else {
199
+ const parts = new Array(msgLen);
200
+ for (let i = 0; i < msgLen; i++) parts[i] = i % 2 === 0 ? msgParts[i] : valueRenderer(msgParts[i]);
201
+ message = parts.join("");
202
+ }
62
203
  const timestamp = timestampRenderer(record.timestamp);
63
204
  const level = levelRenderer(record.level);
64
205
  const category = typeof categorySeparator === "function" ? categorySeparator(record.category) : record.category.join(categorySeparator);
@@ -175,25 +316,39 @@ const ansiColorFormatter = getAnsiColorFormatter();
175
316
  * @since 0.11.0
176
317
  */
177
318
  function getJsonLinesFormatter(options = {}) {
319
+ if (!options.categorySeparator && !options.message && !options.properties) return (record) => {
320
+ if (record.message.length === 3) return JSON.stringify({
321
+ "@timestamp": new Date(record.timestamp).toISOString(),
322
+ level: record.level === "warning" ? "WARN" : record.level.toUpperCase(),
323
+ message: record.message[0] + JSON.stringify(record.message[1]) + record.message[2],
324
+ logger: record.category.join("."),
325
+ properties: record.properties
326
+ });
327
+ if (record.message.length === 1) return JSON.stringify({
328
+ "@timestamp": new Date(record.timestamp).toISOString(),
329
+ level: record.level === "warning" ? "WARN" : record.level.toUpperCase(),
330
+ message: record.message[0],
331
+ logger: record.category.join("."),
332
+ properties: record.properties
333
+ });
334
+ let msg = record.message[0];
335
+ for (let i = 1; i < record.message.length; i++) msg += i & 1 ? JSON.stringify(record.message[i]) : record.message[i];
336
+ return JSON.stringify({
337
+ "@timestamp": new Date(record.timestamp).toISOString(),
338
+ level: record.level === "warning" ? "WARN" : record.level.toUpperCase(),
339
+ message: msg,
340
+ logger: record.category.join("."),
341
+ properties: record.properties
342
+ });
343
+ };
344
+ const isTemplateMessage = options.message === "template";
345
+ const propertiesOption = options.properties ?? "nest:properties";
178
346
  let joinCategory;
179
347
  if (typeof options.categorySeparator === "function") joinCategory = options.categorySeparator;
180
348
  else {
181
349
  const separator = options.categorySeparator ?? ".";
182
350
  joinCategory = (category) => category.join(separator);
183
351
  }
184
- let getMessage;
185
- if (options.message === "template") getMessage = (record) => {
186
- if (typeof record.rawMessage === "string") return record.rawMessage;
187
- let msg = "";
188
- for (let i = 0; i < record.rawMessage.length; i++) msg += i % 2 < 1 ? record.rawMessage[i] : "{}";
189
- return msg;
190
- };
191
- else getMessage = (record) => {
192
- let msg = "";
193
- for (let i = 0; i < record.message.length; i++) msg += i % 2 < 1 ? record.message[i] : JSON.stringify(record.message[i]);
194
- return msg;
195
- };
196
- const propertiesOption = options.properties ?? "nest:properties";
197
352
  let getProperties;
198
353
  if (propertiesOption === "flatten") getProperties = (properties) => properties;
199
354
  else if (propertiesOption.startsWith("prepend:")) {
@@ -208,6 +363,20 @@ function getJsonLinesFormatter(options = {}) {
208
363
  const key = propertiesOption.substring(5);
209
364
  getProperties = (properties) => ({ [key]: properties });
210
365
  } else throw new TypeError(`Invalid properties option: ${JSON.stringify(propertiesOption)}. It must be "flatten", "prepend:<prefix>", or "nest:<key>".`);
366
+ let getMessage;
367
+ if (isTemplateMessage) getMessage = (record) => {
368
+ if (typeof record.rawMessage === "string") return record.rawMessage;
369
+ let msg = "";
370
+ for (let i = 0; i < record.rawMessage.length; i++) msg += i % 2 < 1 ? record.rawMessage[i] : "{}";
371
+ return msg;
372
+ };
373
+ else getMessage = (record) => {
374
+ const msgLen = record.message.length;
375
+ if (msgLen === 1) return record.message[0];
376
+ let msg = "";
377
+ for (let i = 0; i < msgLen; i++) msg += i % 2 < 1 ? record.message[i] : JSON.stringify(record.message[i]);
378
+ return msg;
379
+ };
211
380
  return (record) => {
212
381
  return JSON.stringify({
213
382
  "@timestamp": new Date(record.timestamp).toISOString(),
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.d.cts","names":[],"sources":["../formatter.ts"],"sourcesContent":[],"mappings":";;;;;;;AAWA;AA+DA;AA+BA;;;AAuGoB,KArMR,aAAA,GAqMQ,CAAA,MAAA,EArMiB,SAqMjB,EAAA,GAAA,MAAA;AAAe;AAoBnC;;;AAEG,UA5Jc,eAAA,CA4Jd;EAAa;AA6EhB;AAQA;EAyBY,SAAA,EAAA,MAAS,GAAA,IAAA;EA4BJ;;;EAwCW,KAKT,EAAA,MAAA;EAAS;;;EAiBc,QAA1B,EAAA,MAAA;EAAM;;;EA9DiD,OAAA,EAAA,MAAA;EAmFvD;;;EACyB,MACtC,EAnWO,SAmWP;AAAa;AA4DhB;AAMA;AAsDA;;AACW,UArdM,oBAAA,CAqdN;EAA8B;AACzB;AA8FhB;AAUA;AAqBA;;;;;;;;;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;;;;;mBAwChC;;;;mBAKA;;;;eAKJ;;;;;;;;;;;gBAYC,OAAO,UAAU;;;;kBAKf;;;;kBAKA;;;;;;;;;;iBAWF,qBAAA,WACL,4BACR;;;;;;;;;;cA4DU,oBAAoB;;;;;UAMhB,yBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsDD,qBAAA,WACL,4BACR;;;;;;;;;;;;;;;;;cA2JU,oBAAoB;;;;;;;;;KAUrB,gBAAA,YAA4B;;;;;;;;iBAqBxB,uBAAA,SAAgC"}
package/dist/formatter.js CHANGED
@@ -31,6 +31,123 @@ const inspect = typeof document !== "undefined" || typeof navigator !== "undefin
31
31
  maxStringLength: Infinity,
32
32
  ...opts
33
33
  }) : (v) => JSON.stringify(v);
34
+ function padZero(num) {
35
+ return num < 10 ? `0${num}` : `${num}`;
36
+ }
37
+ function padThree(num) {
38
+ return num < 10 ? `00${num}` : num < 100 ? `0${num}` : `${num}`;
39
+ }
40
+ const timestampFormatters = {
41
+ "date-time-timezone": (ts) => {
42
+ const d = new Date(ts);
43
+ const year = d.getUTCFullYear();
44
+ const month = padZero(d.getUTCMonth() + 1);
45
+ const day = padZero(d.getUTCDate());
46
+ const hour = padZero(d.getUTCHours());
47
+ const minute = padZero(d.getUTCMinutes());
48
+ const second = padZero(d.getUTCSeconds());
49
+ const ms = padThree(d.getUTCMilliseconds());
50
+ return `${year}-${month}-${day} ${hour}:${minute}:${second}.${ms} +00:00`;
51
+ },
52
+ "date-time-tz": (ts) => {
53
+ const d = new Date(ts);
54
+ const year = d.getUTCFullYear();
55
+ const month = padZero(d.getUTCMonth() + 1);
56
+ const day = padZero(d.getUTCDate());
57
+ const hour = padZero(d.getUTCHours());
58
+ const minute = padZero(d.getUTCMinutes());
59
+ const second = padZero(d.getUTCSeconds());
60
+ const ms = padThree(d.getUTCMilliseconds());
61
+ return `${year}-${month}-${day} ${hour}:${minute}:${second}.${ms} +00`;
62
+ },
63
+ "date-time": (ts) => {
64
+ const d = new Date(ts);
65
+ const year = d.getUTCFullYear();
66
+ const month = padZero(d.getUTCMonth() + 1);
67
+ const day = padZero(d.getUTCDate());
68
+ const hour = padZero(d.getUTCHours());
69
+ const minute = padZero(d.getUTCMinutes());
70
+ const second = padZero(d.getUTCSeconds());
71
+ const ms = padThree(d.getUTCMilliseconds());
72
+ return `${year}-${month}-${day} ${hour}:${minute}:${second}.${ms}`;
73
+ },
74
+ "time-timezone": (ts) => {
75
+ const d = new Date(ts);
76
+ const hour = padZero(d.getUTCHours());
77
+ const minute = padZero(d.getUTCMinutes());
78
+ const second = padZero(d.getUTCSeconds());
79
+ const ms = padThree(d.getUTCMilliseconds());
80
+ return `${hour}:${minute}:${second}.${ms} +00:00`;
81
+ },
82
+ "time-tz": (ts) => {
83
+ const d = new Date(ts);
84
+ const hour = padZero(d.getUTCHours());
85
+ const minute = padZero(d.getUTCMinutes());
86
+ const second = padZero(d.getUTCSeconds());
87
+ const ms = padThree(d.getUTCMilliseconds());
88
+ return `${hour}:${minute}:${second}.${ms} +00`;
89
+ },
90
+ "time": (ts) => {
91
+ const d = new Date(ts);
92
+ const hour = padZero(d.getUTCHours());
93
+ const minute = padZero(d.getUTCMinutes());
94
+ const second = padZero(d.getUTCSeconds());
95
+ const ms = padThree(d.getUTCMilliseconds());
96
+ return `${hour}:${minute}:${second}.${ms}`;
97
+ },
98
+ "date": (ts) => {
99
+ const d = new Date(ts);
100
+ const year = d.getUTCFullYear();
101
+ const month = padZero(d.getUTCMonth() + 1);
102
+ const day = padZero(d.getUTCDate());
103
+ return `${year}-${month}-${day}`;
104
+ },
105
+ "rfc3339": (ts) => new Date(ts).toISOString(),
106
+ "none": () => null
107
+ };
108
+ const levelRenderersCache = {
109
+ ABBR: levelAbbreviations,
110
+ abbr: {
111
+ trace: "trc",
112
+ debug: "dbg",
113
+ info: "inf",
114
+ warning: "wrn",
115
+ error: "err",
116
+ fatal: "ftl"
117
+ },
118
+ FULL: {
119
+ trace: "TRACE",
120
+ debug: "DEBUG",
121
+ info: "INFO",
122
+ warning: "WARNING",
123
+ error: "ERROR",
124
+ fatal: "FATAL"
125
+ },
126
+ full: {
127
+ trace: "trace",
128
+ debug: "debug",
129
+ info: "info",
130
+ warning: "warning",
131
+ error: "error",
132
+ fatal: "fatal"
133
+ },
134
+ L: {
135
+ trace: "T",
136
+ debug: "D",
137
+ info: "I",
138
+ warning: "W",
139
+ error: "E",
140
+ fatal: "F"
141
+ },
142
+ l: {
143
+ trace: "t",
144
+ debug: "d",
145
+ info: "i",
146
+ warning: "w",
147
+ error: "e",
148
+ fatal: "f"
149
+ }
150
+ };
34
151
  /**
35
152
  * Get a text formatter with the specified options. Although it's flexible
36
153
  * enough to create a custom formatter, if you want more control, you can
@@ -49,15 +166,39 @@ const inspect = typeof document !== "undefined" || typeof navigator !== "undefin
49
166
  * @since 0.6.0
50
167
  */
51
168
  function getTextFormatter(options = {}) {
52
- const timestampRenderer = options.timestamp == null || options.timestamp === "date-time-timezone" ? (ts) => new Date(ts).toISOString().replace("T", " ").replace("Z", " +00:00") : options.timestamp === "date-time-tz" ? (ts) => new Date(ts).toISOString().replace("T", " ").replace("Z", " +00") : options.timestamp === "date-time" ? (ts) => new Date(ts).toISOString().replace("T", " ").replace("Z", "") : options.timestamp === "time-timezone" ? (ts) => new Date(ts).toISOString().replace(/.*T/, "").replace("Z", " +00:00") : options.timestamp === "time-tz" ? (ts) => new Date(ts).toISOString().replace(/.*T/, "").replace("Z", " +00") : options.timestamp === "time" ? (ts) => new Date(ts).toISOString().replace(/.*T/, "").replace("Z", "") : options.timestamp === "date" ? (ts) => new Date(ts).toISOString().replace(/T.*/, "") : options.timestamp === "rfc3339" ? (ts) => new Date(ts).toISOString() : options.timestamp === "none" || options.timestamp === "disabled" ? () => null : options.timestamp;
169
+ const timestampRenderer = (() => {
170
+ const tsOption = options.timestamp;
171
+ if (tsOption == null) return timestampFormatters["date-time-timezone"];
172
+ else if (tsOption === "disabled") return timestampFormatters["none"];
173
+ else if (typeof tsOption === "string" && tsOption in timestampFormatters) return timestampFormatters[tsOption];
174
+ else return tsOption;
175
+ })();
53
176
  const categorySeparator = options.category ?? "·";
54
177
  const valueRenderer = options.value ?? inspect;
55
- const levelRenderer = options.level == null || options.level === "ABBR" ? (level) => levelAbbreviations[level] : options.level === "abbr" ? (level) => levelAbbreviations[level].toLowerCase() : options.level === "FULL" ? (level) => level.toUpperCase() : options.level === "full" ? (level) => level : options.level === "L" ? (level) => level.charAt(0).toUpperCase() : options.level === "l" ? (level) => level.charAt(0) : options.level;
178
+ const levelRenderer = (() => {
179
+ const levelOption = options.level;
180
+ if (levelOption == null || levelOption === "ABBR") return (level) => levelRenderersCache.ABBR[level];
181
+ else if (levelOption === "abbr") return (level) => levelRenderersCache.abbr[level];
182
+ else if (levelOption === "FULL") return (level) => levelRenderersCache.FULL[level];
183
+ else if (levelOption === "full") return (level) => levelRenderersCache.full[level];
184
+ else if (levelOption === "L") return (level) => levelRenderersCache.L[level];
185
+ else if (levelOption === "l") return (level) => levelRenderersCache.l[level];
186
+ else return levelOption;
187
+ })();
56
188
  const formatter = options.format ?? (({ timestamp, level, category, message }) => `${timestamp ? `${timestamp} ` : ""}[${level}] ${category}: ${message}`);
57
189
  return (record) => {
58
- let message = "";
59
- for (let i = 0; i < record.message.length; i++) if (i % 2 === 0) message += record.message[i];
60
- else message += valueRenderer(record.message[i]);
190
+ const msgParts = record.message;
191
+ const msgLen = msgParts.length;
192
+ let message;
193
+ if (msgLen === 1) message = msgParts[0];
194
+ else if (msgLen <= 6) {
195
+ message = "";
196
+ for (let i = 0; i < msgLen; i++) message += i % 2 === 0 ? msgParts[i] : valueRenderer(msgParts[i]);
197
+ } else {
198
+ const parts = new Array(msgLen);
199
+ for (let i = 0; i < msgLen; i++) parts[i] = i % 2 === 0 ? msgParts[i] : valueRenderer(msgParts[i]);
200
+ message = parts.join("");
201
+ }
61
202
  const timestamp = timestampRenderer(record.timestamp);
62
203
  const level = levelRenderer(record.level);
63
204
  const category = typeof categorySeparator === "function" ? categorySeparator(record.category) : record.category.join(categorySeparator);
@@ -174,25 +315,39 @@ const ansiColorFormatter = getAnsiColorFormatter();
174
315
  * @since 0.11.0
175
316
  */
176
317
  function getJsonLinesFormatter(options = {}) {
318
+ if (!options.categorySeparator && !options.message && !options.properties) return (record) => {
319
+ if (record.message.length === 3) return JSON.stringify({
320
+ "@timestamp": new Date(record.timestamp).toISOString(),
321
+ level: record.level === "warning" ? "WARN" : record.level.toUpperCase(),
322
+ message: record.message[0] + JSON.stringify(record.message[1]) + record.message[2],
323
+ logger: record.category.join("."),
324
+ properties: record.properties
325
+ });
326
+ if (record.message.length === 1) return JSON.stringify({
327
+ "@timestamp": new Date(record.timestamp).toISOString(),
328
+ level: record.level === "warning" ? "WARN" : record.level.toUpperCase(),
329
+ message: record.message[0],
330
+ logger: record.category.join("."),
331
+ properties: record.properties
332
+ });
333
+ let msg = record.message[0];
334
+ for (let i = 1; i < record.message.length; i++) msg += i & 1 ? JSON.stringify(record.message[i]) : record.message[i];
335
+ return JSON.stringify({
336
+ "@timestamp": new Date(record.timestamp).toISOString(),
337
+ level: record.level === "warning" ? "WARN" : record.level.toUpperCase(),
338
+ message: msg,
339
+ logger: record.category.join("."),
340
+ properties: record.properties
341
+ });
342
+ };
343
+ const isTemplateMessage = options.message === "template";
344
+ const propertiesOption = options.properties ?? "nest:properties";
177
345
  let joinCategory;
178
346
  if (typeof options.categorySeparator === "function") joinCategory = options.categorySeparator;
179
347
  else {
180
348
  const separator = options.categorySeparator ?? ".";
181
349
  joinCategory = (category) => category.join(separator);
182
350
  }
183
- let getMessage;
184
- if (options.message === "template") getMessage = (record) => {
185
- if (typeof record.rawMessage === "string") return record.rawMessage;
186
- let msg = "";
187
- for (let i = 0; i < record.rawMessage.length; i++) msg += i % 2 < 1 ? record.rawMessage[i] : "{}";
188
- return msg;
189
- };
190
- else getMessage = (record) => {
191
- let msg = "";
192
- for (let i = 0; i < record.message.length; i++) msg += i % 2 < 1 ? record.message[i] : JSON.stringify(record.message[i]);
193
- return msg;
194
- };
195
- const propertiesOption = options.properties ?? "nest:properties";
196
351
  let getProperties;
197
352
  if (propertiesOption === "flatten") getProperties = (properties) => properties;
198
353
  else if (propertiesOption.startsWith("prepend:")) {
@@ -207,6 +362,20 @@ function getJsonLinesFormatter(options = {}) {
207
362
  const key = propertiesOption.substring(5);
208
363
  getProperties = (properties) => ({ [key]: properties });
209
364
  } else throw new TypeError(`Invalid properties option: ${JSON.stringify(propertiesOption)}. It must be "flatten", "prepend:<prefix>", or "nest:<key>".`);
365
+ let getMessage;
366
+ if (isTemplateMessage) getMessage = (record) => {
367
+ if (typeof record.rawMessage === "string") return record.rawMessage;
368
+ let msg = "";
369
+ for (let i = 0; i < record.rawMessage.length; i++) msg += i % 2 < 1 ? record.rawMessage[i] : "{}";
370
+ return msg;
371
+ };
372
+ else getMessage = (record) => {
373
+ const msgLen = record.message.length;
374
+ if (msgLen === 1) return record.message[0];
375
+ let msg = "";
376
+ for (let i = 0; i < msgLen; i++) msg += i % 2 < 1 ? record.message[i] : JSON.stringify(record.message[i]);
377
+ return msg;
378
+ };
210
379
  return (record) => {
211
380
  return JSON.stringify({
212
381
  "@timestamp": new Date(record.timestamp).toISOString(),
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.js","names":["levelAbbreviations: Record<LogLevel, string>","inspect: (value: unknown, options?: { colors?: boolean }) => string","options: TextFormatterOptions","ts: number","level: LogLevel","formatter: (values: FormattedValues) => string","record: LogRecord","values: FormattedValues","defaultTextFormatter: TextFormatter","ansiColors: Record<AnsiColor, string>","ansiStyles: Record<AnsiStyle, string>","defaultLevelColors: Record<LogLevel, AnsiColor | null>","options: AnsiColorFormatterOptions","value: unknown","ansiColorFormatter: TextFormatter","options: JsonLinesFormatterOptions","joinCategory: (category: readonly string[]) => string | readonly string[]","category: readonly string[]","getMessage: TextFormatter","getProperties: (\n properties: Record<string, unknown>,\n ) => Record<string, unknown>","result: Record<string, unknown>","jsonLinesFormatter: TextFormatter","logLevelStyles: Record<LogLevel, string>","values: unknown[]"],"sources":["../formatter.ts"],"sourcesContent":["import * as util from \"#util\";\nimport type { LogLevel } from \"./level.ts\";\nimport type { LogRecord } from \"./record.ts\";\n\n/**\n * A text formatter is a function that accepts a log record and returns\n * a string.\n *\n * @param record The log record to format.\n * @returns The formatted log record.\n */\nexport type TextFormatter = (record: LogRecord) => string;\n\n/**\n * The severity level abbreviations.\n */\nconst levelAbbreviations: Record<LogLevel, string> = {\n \"trace\": \"TRC\",\n \"debug\": \"DBG\",\n \"info\": \"INF\",\n \"warning\": \"WRN\",\n \"error\": \"ERR\",\n \"fatal\": \"FTL\",\n};\n\n/**\n * A platform-specific inspect function. In Deno, this is {@link Deno.inspect},\n * and in Node.js/Bun it is `util.inspect()`. If neither is available, it\n * falls back to {@link JSON.stringify}.\n *\n * @param value The value to inspect.\n * @param options The options for inspecting the value.\n * If `colors` is `true`, the output will be ANSI-colored.\n * @returns The string representation of the value.\n */\nconst inspect: (value: unknown, options?: { colors?: boolean }) => string =\n // @ts-ignore: Browser detection\n // dnt-shim-ignore\n typeof document !== \"undefined\" ||\n // @ts-ignore: React Native detection\n // dnt-shim-ignore\n typeof navigator !== \"undefined\" && navigator.product === \"ReactNative\"\n ? (v) => JSON.stringify(v)\n // @ts-ignore: Deno global\n // dnt-shim-ignore\n : \"Deno\" in globalThis && \"inspect\" in globalThis.Deno &&\n // @ts-ignore: Deno global\n // dnt-shim-ignore\n typeof globalThis.Deno.inspect === \"function\"\n ? (v, opts) =>\n // @ts-ignore: Deno global\n // dnt-shim-ignore\n globalThis.Deno.inspect(v, {\n strAbbreviateSize: Infinity,\n iterableLimit: Infinity,\n ...opts,\n })\n // @ts-ignore: Node.js global\n // dnt-shim-ignore\n : util != null && \"inspect\" in util && typeof util.inspect === \"function\"\n ? (v, opts) =>\n // @ts-ignore: Node.js global\n // dnt-shim-ignore\n util.inspect(v, {\n maxArrayLength: Infinity,\n maxStringLength: Infinity,\n ...opts,\n })\n : (v) => JSON.stringify(v);\n\n/**\n * The formatted values for a log record.\n * @since 0.6.0\n */\nexport interface FormattedValues {\n /**\n * The formatted timestamp.\n */\n timestamp: string | null;\n\n /**\n * The formatted log level.\n */\n level: string;\n\n /**\n * The formatted category.\n */\n category: string;\n\n /**\n * The formatted message.\n */\n message: string;\n\n /**\n * The unformatted log record.\n */\n record: LogRecord;\n}\n\n/**\n * The various options for the built-in text formatters.\n * @since 0.6.0\n */\nexport interface TextFormatterOptions {\n /**\n * The timestamp format. This can be one of the following:\n *\n * - `\"date-time-timezone\"`: The date and time with the full timezone offset\n * (e.g., `\"2023-11-14 22:13:20.000 +00:00\"`).\n * - `\"date-time-tz\"`: The date and time with the short timezone offset\n * (e.g., `\"2023-11-14 22:13:20.000 +00\"`).\n * - `\"date-time\"`: The date and time without the timezone offset\n * (e.g., `\"2023-11-14 22:13:20.000\"`).\n * - `\"time-timezone\"`: The time with the full timezone offset but without\n * the date (e.g., `\"22:13:20.000 +00:00\"`).\n * - `\"time-tz\"`: The time with the short timezone offset but without the date\n * (e.g., `\"22:13:20.000 +00\"`).\n * - `\"time\"`: The time without the date or timezone offset\n * (e.g., `\"22:13:20.000\"`).\n * - `\"date\"`: The date without the time or timezone offset\n * (e.g., `\"2023-11-14\"`).\n * - `\"rfc3339\"`: The date and time in RFC 3339 format\n * (e.g., `\"2023-11-14T22:13:20.000Z\"`).\n * - `\"none\"` or `\"disabled\"`: No display\n *\n * Alternatively, this can be a function that accepts a timestamp and returns\n * a string.\n *\n * The default is `\"date-time-timezone\"`.\n */\n timestamp?:\n | \"date-time-timezone\"\n | \"date-time-tz\"\n | \"date-time\"\n | \"time-timezone\"\n | \"time-tz\"\n | \"time\"\n | \"date\"\n | \"rfc3339\"\n | \"none\"\n | \"disabled\"\n | ((ts: number) => string | null);\n\n /**\n * The log level format. This can be one of the following:\n *\n * - `\"ABBR\"`: The log level abbreviation in uppercase (e.g., `\"INF\"`).\n * - `\"FULL\"`: The full log level name in uppercase (e.g., `\"INFO\"`).\n * - `\"L\"`: The first letter of the log level in uppercase (e.g., `\"I\"`).\n * - `\"abbr\"`: The log level abbreviation in lowercase (e.g., `\"inf\"`).\n * - `\"full\"`: The full log level name in lowercase (e.g., `\"info\"`).\n * - `\"l\"`: The first letter of the log level in lowercase (e.g., `\"i\"`).\n *\n * Alternatively, this can be a function that accepts a log level and returns\n * a string.\n *\n * The default is `\"ABBR\"`.\n */\n level?:\n | \"ABBR\"\n | \"FULL\"\n | \"L\"\n | \"abbr\"\n | \"full\"\n | \"l\"\n | ((level: LogLevel) => string);\n\n /**\n * The separator between category names. For example, if the separator is\n * `\"·\"`, the category `[\"a\", \"b\", \"c\"]` will be formatted as `\"a·b·c\"`.\n * The default separator is `\"·\"`.\n *\n * If this is a function, it will be called with the category array and\n * should return a string, which will be used for rendering the category.\n */\n category?: string | ((category: readonly string[]) => string);\n\n /**\n * The format of the embedded values.\n *\n * A function that renders a value to a string. This function is used to\n * render the values in the log record. The default is [`util.inspect()`] in\n * Node.js/Bun and [`Deno.inspect()`] in Deno.\n *\n * [`util.inspect()`]: https://nodejs.org/api/util.html#utilinspectobject-options\n * [`Deno.inspect()`]: https://docs.deno.com/api/deno/~/Deno.inspect\n * @param value The value to render.\n * @returns The string representation of the value.\n */\n value?: (value: unknown) => string;\n\n /**\n * How those formatted parts are concatenated.\n *\n * A function that formats the log record. This function is called with the\n * formatted values and should return a string. Note that the formatted\n * *should not* include a newline character at the end.\n *\n * By default, this is a function that formats the log record as follows:\n *\n * ```\n * 2023-11-14 22:13:20.000 +00:00 [INF] category·subcategory: Hello, world!\n * ```\n * @param values The formatted values.\n * @returns The formatted log record.\n */\n format?: (values: FormattedValues) => string;\n}\n\n/**\n * Get a text formatter with the specified options. Although it's flexible\n * enough to create a custom formatter, if you want more control, you can\n * create a custom formatter that satisfies the {@link TextFormatter} type\n * instead.\n *\n * For more information on the options, see {@link TextFormatterOptions}.\n *\n * By default, the formatter formats log records as follows:\n *\n * ```\n * 2023-11-14 22:13:20.000 +00:00 [INF] category·subcategory: Hello, world!\n * ```\n * @param options The options for the text formatter.\n * @returns The text formatter.\n * @since 0.6.0\n */\nexport function getTextFormatter(\n options: TextFormatterOptions = {},\n): TextFormatter {\n const timestampRenderer =\n options.timestamp == null || options.timestamp === \"date-time-timezone\"\n ? (ts: number): string =>\n new Date(ts).toISOString().replace(\"T\", \" \").replace(\"Z\", \" +00:00\")\n : options.timestamp === \"date-time-tz\"\n ? (ts: number): string =>\n new Date(ts).toISOString().replace(\"T\", \" \").replace(\"Z\", \" +00\")\n : options.timestamp === \"date-time\"\n ? (ts: number): string =>\n new Date(ts).toISOString().replace(\"T\", \" \").replace(\"Z\", \"\")\n : options.timestamp === \"time-timezone\"\n ? (ts: number): string =>\n new Date(ts).toISOString().replace(/.*T/, \"\").replace(\"Z\", \" +00:00\")\n : options.timestamp === \"time-tz\"\n ? (ts: number): string =>\n new Date(ts).toISOString().replace(/.*T/, \"\").replace(\"Z\", \" +00\")\n : options.timestamp === \"time\"\n ? (ts: number): string =>\n new Date(ts).toISOString().replace(/.*T/, \"\").replace(\"Z\", \"\")\n : options.timestamp === \"date\"\n ? (ts: number): string => new Date(ts).toISOString().replace(/T.*/, \"\")\n : options.timestamp === \"rfc3339\"\n ? (ts: number): string => new Date(ts).toISOString()\n : options.timestamp === \"none\" || options.timestamp === \"disabled\"\n ? () => null\n : options.timestamp;\n const categorySeparator = options.category ?? \"·\";\n const valueRenderer = options.value ?? inspect;\n const levelRenderer = options.level == null || options.level === \"ABBR\"\n ? (level: LogLevel): string => levelAbbreviations[level]\n : options.level === \"abbr\"\n ? (level: LogLevel): string => levelAbbreviations[level].toLowerCase()\n : options.level === \"FULL\"\n ? (level: LogLevel): string => level.toUpperCase()\n : options.level === \"full\"\n ? (level: LogLevel): string => level\n : options.level === \"L\"\n ? (level: LogLevel): string => level.charAt(0).toUpperCase()\n : options.level === \"l\"\n ? (level: LogLevel): string => level.charAt(0)\n : options.level;\n const formatter: (values: FormattedValues) => string = options.format ??\n (({ timestamp, level, category, message }: FormattedValues) =>\n `${timestamp ? `${timestamp} ` : \"\"}[${level}] ${category}: ${message}`);\n return (record: LogRecord): string => {\n let message = \"\";\n for (let i = 0; i < record.message.length; i++) {\n if (i % 2 === 0) message += record.message[i];\n else message += valueRenderer(record.message[i]);\n }\n const timestamp = timestampRenderer(record.timestamp);\n const level = levelRenderer(record.level);\n const category = typeof categorySeparator === \"function\"\n ? categorySeparator(record.category)\n : record.category.join(categorySeparator);\n const values: FormattedValues = {\n timestamp,\n level,\n category,\n message,\n record,\n };\n return `${formatter(values)}\\n`;\n };\n}\n\n/**\n * The default text formatter. This formatter formats log records as follows:\n *\n * ```\n * 2023-11-14 22:13:20.000 +00:00 [INF] category·subcategory: Hello, world!\n * ```\n *\n * @param record The log record to format.\n * @returns The formatted log record.\n */\nexport const defaultTextFormatter: TextFormatter = getTextFormatter();\n\nconst RESET = \"\\x1b[0m\";\n\n/**\n * The ANSI colors. These can be used to colorize text in the console.\n * @since 0.6.0\n */\nexport type AnsiColor =\n | \"black\"\n | \"red\"\n | \"green\"\n | \"yellow\"\n | \"blue\"\n | \"magenta\"\n | \"cyan\"\n | \"white\";\n\nconst ansiColors: Record<AnsiColor, string> = {\n black: \"\\x1b[30m\",\n red: \"\\x1b[31m\",\n green: \"\\x1b[32m\",\n yellow: \"\\x1b[33m\",\n blue: \"\\x1b[34m\",\n magenta: \"\\x1b[35m\",\n cyan: \"\\x1b[36m\",\n white: \"\\x1b[37m\",\n};\n\n/**\n * The ANSI text styles.\n * @since 0.6.0\n */\nexport type AnsiStyle =\n | \"bold\"\n | \"dim\"\n | \"italic\"\n | \"underline\"\n | \"strikethrough\";\n\nconst ansiStyles: Record<AnsiStyle, string> = {\n bold: \"\\x1b[1m\",\n dim: \"\\x1b[2m\",\n italic: \"\\x1b[3m\",\n underline: \"\\x1b[4m\",\n strikethrough: \"\\x1b[9m\",\n};\n\nconst defaultLevelColors: Record<LogLevel, AnsiColor | null> = {\n trace: null,\n debug: \"blue\",\n info: \"green\",\n warning: \"yellow\",\n error: \"red\",\n fatal: \"magenta\",\n};\n\n/**\n * The various options for the ANSI color formatter.\n * @since 0.6.0\n */\nexport interface AnsiColorFormatterOptions extends TextFormatterOptions {\n /**\n * The timestamp format. This can be one of the following:\n *\n * - `\"date-time-timezone\"`: The date and time with the full timezone offset\n * (e.g., `\"2023-11-14 22:13:20.000 +00:00\"`).\n * - `\"date-time-tz\"`: The date and time with the short timezone offset\n * (e.g., `\"2023-11-14 22:13:20.000 +00\"`).\n * - `\"date-time\"`: The date and time without the timezone offset\n * (e.g., `\"2023-11-14 22:13:20.000\"`).\n * - `\"time-timezone\"`: The time with the full timezone offset but without\n * the date (e.g., `\"22:13:20.000 +00:00\"`).\n * - `\"time-tz\"`: The time with the short timezone offset but without the date\n * (e.g., `\"22:13:20.000 +00\"`).\n * - `\"time\"`: The time without the date or timezone offset\n * (e.g., `\"22:13:20.000\"`).\n * - `\"date\"`: The date without the time or timezone offset\n * (e.g., `\"2023-11-14\"`).\n * - `\"rfc3339\"`: The date and time in RFC 3339 format\n * (e.g., `\"2023-11-14T22:13:20.000Z\"`).\n *\n * Alternatively, this can be a function that accepts a timestamp and returns\n * a string.\n *\n * The default is `\"date-time-tz\"`.\n */\n timestamp?:\n | \"date-time-timezone\"\n | \"date-time-tz\"\n | \"date-time\"\n | \"time-timezone\"\n | \"time-tz\"\n | \"time\"\n | \"date\"\n | \"rfc3339\"\n | ((ts: number) => string);\n\n /**\n * The ANSI style for the timestamp. `\"dim\"` is used by default.\n */\n timestampStyle?: AnsiStyle | null;\n\n /**\n * The ANSI color for the timestamp. No color is used by default.\n */\n timestampColor?: AnsiColor | null;\n\n /**\n * The ANSI style for the log level. `\"bold\"` is used by default.\n */\n levelStyle?: AnsiStyle | null;\n\n /**\n * The ANSI colors for the log levels. The default colors are as follows:\n *\n * - `\"trace\"`: `null` (no color)\n * - `\"debug\"`: `\"blue\"`\n * - `\"info\"`: `\"green\"`\n * - `\"warning\"`: `\"yellow\"`\n * - `\"error\"`: `\"red\"`\n * - `\"fatal\"`: `\"magenta\"`\n */\n levelColors?: Record<LogLevel, AnsiColor | null>;\n\n /**\n * The ANSI style for the category. `\"dim\"` is used by default.\n */\n categoryStyle?: AnsiStyle | null;\n\n /**\n * The ANSI color for the category. No color is used by default.\n */\n categoryColor?: AnsiColor | null;\n}\n\n/**\n * Get an ANSI color formatter with the specified options.\n *\n * ![A preview of an ANSI color formatter.](https://i.imgur.com/I8LlBUf.png)\n * @param option The options for the ANSI color formatter.\n * @returns The ANSI color formatter.\n * @since 0.6.0\n */\nexport function getAnsiColorFormatter(\n options: AnsiColorFormatterOptions = {},\n): TextFormatter {\n const format = options.format;\n const timestampStyle = typeof options.timestampStyle === \"undefined\"\n ? \"dim\"\n : options.timestampStyle;\n const timestampColor = options.timestampColor ?? null;\n const timestampPrefix = `${\n timestampStyle == null ? \"\" : ansiStyles[timestampStyle]\n }${timestampColor == null ? \"\" : ansiColors[timestampColor]}`;\n const timestampSuffix = timestampStyle == null && timestampColor == null\n ? \"\"\n : RESET;\n const levelStyle = typeof options.levelStyle === \"undefined\"\n ? \"bold\"\n : options.levelStyle;\n const levelColors = options.levelColors ?? defaultLevelColors;\n const categoryStyle = typeof options.categoryStyle === \"undefined\"\n ? \"dim\"\n : options.categoryStyle;\n const categoryColor = options.categoryColor ?? null;\n const categoryPrefix = `${\n categoryStyle == null ? \"\" : ansiStyles[categoryStyle]\n }${categoryColor == null ? \"\" : ansiColors[categoryColor]}`;\n const categorySuffix = categoryStyle == null && categoryColor == null\n ? \"\"\n : RESET;\n return getTextFormatter({\n timestamp: \"date-time-tz\",\n value(value: unknown): string {\n return inspect(value, { colors: true });\n },\n ...options,\n format({ timestamp, level, category, message, record }): string {\n const levelColor = levelColors[record.level];\n timestamp = `${timestampPrefix}${timestamp}${timestampSuffix}`;\n level = `${levelStyle == null ? \"\" : ansiStyles[levelStyle]}${\n levelColor == null ? \"\" : ansiColors[levelColor]\n }${level}${levelStyle == null && levelColor == null ? \"\" : RESET}`;\n return format == null\n ? `${timestamp} ${level} ${categoryPrefix}${category}:${categorySuffix} ${message}`\n : format({\n timestamp,\n level,\n category: `${categoryPrefix}${category}${categorySuffix}`,\n message,\n record,\n });\n },\n });\n}\n\n/**\n * A text formatter that uses ANSI colors to format log records.\n *\n * ![A preview of ansiColorFormatter.](https://i.imgur.com/I8LlBUf.png)\n *\n * @param record The log record to format.\n * @returns The formatted log record.\n * @since 0.5.0\n */\nexport const ansiColorFormatter: TextFormatter = getAnsiColorFormatter();\n\n/**\n * Options for the {@link getJsonLinesFormatter} function.\n * @since 0.11.0\n */\nexport interface JsonLinesFormatterOptions {\n /**\n * The separator between category names. For example, if the separator is\n * `\".\"`, the category `[\"a\", \"b\", \"c\"]` will be formatted as `\"a.b.c\"`.\n * If this is a function, it will be called with the category array and\n * should return a string or an array of strings, which will be used\n * for rendering the category.\n *\n * @default `\".\"`\n */\n readonly categorySeparator?:\n | string\n | ((category: readonly string[]) => string | readonly string[]);\n\n /**\n * The message format. This can be one of the following:\n *\n * - `\"template\"`: The raw message template is used as the message.\n * - `\"rendered\"`: The message is rendered with the values.\n *\n * @default `\"rendered\"`\n */\n readonly message?: \"template\" | \"rendered\";\n\n /**\n * The properties format. This can be one of the following:\n *\n * - `\"flatten\"`: The properties are flattened into the root object.\n * - `\"prepend:<prefix>\"`: The properties are prepended with the given prefix\n * (e.g., `\"prepend:ctx_\"` will prepend `ctx_` to each property key).\n * - `\"nest:<key>\"`: The properties are nested under the given key\n * (e.g., `\"nest:properties\"` will nest the properties under the\n * `properties` key).\n *\n * @default `\"nest:properties\"`\n */\n readonly properties?: \"flatten\" | `prepend:${string}` | `nest:${string}`;\n}\n\n/**\n * Get a [JSON Lines] formatter with the specified options. The log records\n * will be rendered as JSON objects, one per line, which is a common format\n * for log files. This format is also known as Newline-Delimited JSON (NDJSON).\n * It looks like this:\n *\n * ```json\n * {\"@timestamp\":\"2023-11-14T22:13:20.000Z\",\"level\":\"INFO\",\"message\":\"Hello, world!\",\"logger\":\"my.logger\",\"properties\":{\"key\":\"value\"}}\n * ```\n *\n * [JSON Lines]: https://jsonlines.org/\n * @param options The options for the JSON Lines formatter.\n * @returns The JSON Lines formatter.\n * @since 0.11.0\n */\nexport function getJsonLinesFormatter(\n options: JsonLinesFormatterOptions = {},\n): TextFormatter {\n let joinCategory: (category: readonly string[]) => string | readonly string[];\n if (typeof options.categorySeparator === \"function\") {\n joinCategory = options.categorySeparator;\n } else {\n const separator = options.categorySeparator ?? \".\";\n joinCategory = (category: readonly string[]): string =>\n category.join(separator);\n }\n\n let getMessage: TextFormatter;\n if (options.message === \"template\") {\n getMessage = (record: LogRecord): string => {\n if (typeof record.rawMessage === \"string\") {\n return record.rawMessage;\n }\n let msg = \"\";\n for (let i = 0; i < record.rawMessage.length; i++) {\n msg += i % 2 < 1 ? record.rawMessage[i] : \"{}\";\n }\n return msg;\n };\n } else {\n getMessage = (record: LogRecord): string => {\n let msg = \"\";\n for (let i = 0; i < record.message.length; i++) {\n msg += i % 2 < 1\n ? record.message[i]\n : JSON.stringify(record.message[i]);\n }\n return msg;\n };\n }\n\n const propertiesOption = options.properties ?? \"nest:properties\";\n let getProperties: (\n properties: Record<string, unknown>,\n ) => Record<string, unknown>;\n if (propertiesOption === \"flatten\") {\n getProperties = (properties) => properties;\n } else if (propertiesOption.startsWith(\"prepend:\")) {\n const prefix = propertiesOption.substring(8);\n if (prefix === \"\") {\n throw new TypeError(\n `Invalid properties option: ${\n JSON.stringify(propertiesOption)\n }. It must be of the form \"prepend:<prefix>\" where <prefix> is a non-empty string.`,\n );\n }\n getProperties = (properties) => {\n const result: Record<string, unknown> = {};\n for (const key in properties) {\n result[`${prefix}${key}`] = properties[key];\n }\n return result;\n };\n } else if (propertiesOption.startsWith(\"nest:\")) {\n const key = propertiesOption.substring(5);\n getProperties = (properties) => ({ [key]: properties });\n } else {\n throw new TypeError(\n `Invalid properties option: ${\n JSON.stringify(propertiesOption)\n }. It must be \"flatten\", \"prepend:<prefix>\", or \"nest:<key>\".`,\n );\n }\n\n return (record: LogRecord): string => {\n return JSON.stringify({\n \"@timestamp\": new Date(record.timestamp).toISOString(),\n level: record.level === \"warning\" ? \"WARN\" : record.level.toUpperCase(),\n message: getMessage(record),\n logger: joinCategory(record.category),\n ...getProperties(record.properties),\n });\n };\n}\n\n/**\n * The default [JSON Lines] formatter. This formatter formats log records\n * as JSON objects, one per line, which is a common format for log files.\n * It looks like this:\n *\n * ```json\n * {\"@timestamp\":\"2023-11-14T22:13:20.000Z\",\"level\":\"INFO\",\"message\":\"Hello, world!\",\"logger\":\"my.logger\",\"properties\":{\"key\":\"value\"}}\n * ```\n *\n * You can customize the output by passing options to\n * {@link getJsonLinesFormatter}. For example, you can change the category\n * separator, the message format, and how the properties are formatted.\n *\n * [JSON Lines]: https://jsonlines.org/\n * @since 0.11.0\n */\nexport const jsonLinesFormatter: TextFormatter = getJsonLinesFormatter();\n\n/**\n * A console formatter is a function that accepts a log record and returns\n * an array of arguments to pass to {@link console.log}.\n *\n * @param record The log record to format.\n * @returns The formatted log record, as an array of arguments for\n * {@link console.log}.\n */\nexport type ConsoleFormatter = (record: LogRecord) => readonly unknown[];\n\n/**\n * The styles for the log level in the console.\n */\nconst logLevelStyles: Record<LogLevel, string> = {\n \"trace\": \"background-color: gray; color: white;\",\n \"debug\": \"background-color: gray; color: white;\",\n \"info\": \"background-color: white; color: black;\",\n \"warning\": \"background-color: orange; color: black;\",\n \"error\": \"background-color: red; color: white;\",\n \"fatal\": \"background-color: maroon; color: white;\",\n};\n\n/**\n * The default console formatter.\n *\n * @param record The log record to format.\n * @returns The formatted log record, as an array of arguments for\n * {@link console.log}.\n */\nexport function defaultConsoleFormatter(record: LogRecord): readonly unknown[] {\n let msg = \"\";\n const values: unknown[] = [];\n for (let i = 0; i < record.message.length; i++) {\n if (i % 2 === 0) msg += record.message[i];\n else {\n msg += \"%o\";\n values.push(record.message[i]);\n }\n }\n const date = new Date(record.timestamp);\n const time = `${date.getUTCHours().toString().padStart(2, \"0\")}:${\n date.getUTCMinutes().toString().padStart(2, \"0\")\n }:${date.getUTCSeconds().toString().padStart(2, \"0\")}.${\n date.getUTCMilliseconds().toString().padStart(3, \"0\")\n }`;\n return [\n `%c${time} %c${levelAbbreviations[record.level]}%c %c${\n record.category.join(\"\\xb7\")\n } %c${msg}`,\n \"color: gray;\",\n logLevelStyles[record.level],\n \"background-color: default;\",\n \"color: gray;\",\n \"color: default;\",\n ...values,\n ];\n}\n"],"mappings":";;;;;;AAgBA,MAAMA,qBAA+C;CACnD,SAAS;CACT,SAAS;CACT,QAAQ;CACR,WAAW;CACX,SAAS;CACT,SAAS;AACV;;;;;;;;;;;AAYD,MAAMC,iBAGG,aAAa,sBAGX,cAAc,eAAe,UAAU,YAAY,gBACxD,CAAC,MAAM,KAAK,UAAU,EAAE,GAGxB,UAAU,cAAc,aAAa,WAAW,eAGvC,WAAW,KAAK,YAAY,aACrC,CAAC,GAAG,SAGJ,WAAW,KAAK,QAAQ,GAAG;CACzB,mBAAmB;CACnB,eAAe;CACf,GAAG;AACJ,EAAC,GAGF,QAAQ,QAAQ,aAAa,eAAe,KAAK,YAAY,aAC7D,CAAC,GAAG,SAGJ,KAAK,QAAQ,GAAG;CACd,gBAAgB;CAChB,iBAAiB;CACjB,GAAG;AACJ,EAAC,GACF,CAAC,MAAM,KAAK,UAAU,EAAE;;;;;;;;;;;;;;;;;;AAgK9B,SAAgB,iBACdC,UAAgC,CAAE,GACnB;CACf,MAAM,oBACJ,QAAQ,aAAa,QAAQ,QAAQ,cAAc,uBAC/C,CAACC,OACD,IAAI,KAAK,IAAI,aAAa,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,KAAK,UAAU,GACpE,QAAQ,cAAc,iBACtB,CAACA,OACD,IAAI,KAAK,IAAI,aAAa,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,KAAK,OAAO,GACjE,QAAQ,cAAc,cACtB,CAACA,OACD,IAAI,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,SAAS;CACT,SAAS;AACV;;;;;;;;AASD,SAAgB,wBAAwBhB,QAAuC;CAC7E,IAAI,MAAM;CACV,MAAMiB,SAAoB,CAAE;AAC5B,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,QAAQ,IACzC,KAAI,IAAI,MAAM,EAAG,QAAO,OAAO,QAAQ;MAClC;AACH,SAAO;AACP,SAAO,KAAK,OAAO,QAAQ,GAAG;CAC/B;CAEH,MAAM,OAAO,IAAI,KAAK,OAAO;CAC7B,MAAM,QAAQ,EAAE,KAAK,aAAa,CAAC,UAAU,CAAC,SAAS,GAAG,IAAI,CAAC,GAC7D,KAAK,eAAe,CAAC,UAAU,CAAC,SAAS,GAAG,IAAI,CACjD,GAAG,KAAK,eAAe,CAAC,UAAU,CAAC,SAAS,GAAG,IAAI,CAAC,GACnD,KAAK,oBAAoB,CAAC,UAAU,CAAC,SAAS,GAAG,IAAI,CACtD;AACD,QAAO;GACJ,IAAI,KAAK,KAAK,mBAAmB,OAAO,OAAO,OAC9C,OAAO,SAAS,KAAK,IAAO,CAC7B,KAAK,IAAI;EACV;EACA,eAAe,OAAO;EACtB;EACA;EACA;EACA,GAAG;CACJ;AACF"}
1
+ {"version":3,"file":"formatter.js","names":["levelAbbreviations: Record<LogLevel, string>","inspect: (value: unknown, options?: { colors?: boolean }) => string","num: number","ts: number","options: TextFormatterOptions","level: LogLevel","formatter: (values: FormattedValues) => string","record: LogRecord","message: string","parts: string[]","values: FormattedValues","defaultTextFormatter: TextFormatter","ansiColors: Record<AnsiColor, string>","ansiStyles: Record<AnsiStyle, string>","defaultLevelColors: Record<LogLevel, AnsiColor | null>","options: AnsiColorFormatterOptions","value: unknown","ansiColorFormatter: TextFormatter","options: JsonLinesFormatterOptions","joinCategory: (category: readonly string[]) => string | readonly string[]","category: readonly string[]","getProperties: (\n properties: Record<string, unknown>,\n ) => Record<string, unknown>","result: Record<string, unknown>","getMessage: (record: LogRecord) => string","jsonLinesFormatter: TextFormatter","logLevelStyles: Record<LogLevel, string>","values: unknown[]"],"sources":["../formatter.ts"],"sourcesContent":["import * as util from \"#util\";\nimport type { LogLevel } from \"./level.ts\";\nimport type { LogRecord } from \"./record.ts\";\n\n/**\n * A text formatter is a function that accepts a log record and returns\n * a string.\n *\n * @param record The log record to format.\n * @returns The formatted log record.\n */\nexport type TextFormatter = (record: LogRecord) => string;\n\n/**\n * The severity level abbreviations.\n */\nconst levelAbbreviations: Record<LogLevel, string> = {\n \"trace\": \"TRC\",\n \"debug\": \"DBG\",\n \"info\": \"INF\",\n \"warning\": \"WRN\",\n \"error\": \"ERR\",\n \"fatal\": \"FTL\",\n};\n\n/**\n * A platform-specific inspect function. In Deno, this is {@link Deno.inspect},\n * and in Node.js/Bun it is `util.inspect()`. If neither is available, it\n * falls back to {@link JSON.stringify}.\n *\n * @param value The value to inspect.\n * @param options The options for inspecting the value.\n * If `colors` is `true`, the output will be ANSI-colored.\n * @returns The string representation of the value.\n */\nconst inspect: (value: unknown, options?: { colors?: boolean }) => string =\n // @ts-ignore: Browser detection\n // dnt-shim-ignore\n typeof document !== \"undefined\" ||\n // @ts-ignore: React Native detection\n // dnt-shim-ignore\n typeof navigator !== \"undefined\" && navigator.product === \"ReactNative\"\n ? (v) => JSON.stringify(v)\n // @ts-ignore: Deno global\n // dnt-shim-ignore\n : \"Deno\" in globalThis && \"inspect\" in globalThis.Deno &&\n // @ts-ignore: Deno global\n // dnt-shim-ignore\n typeof globalThis.Deno.inspect === \"function\"\n ? (v, opts) =>\n // @ts-ignore: Deno global\n // dnt-shim-ignore\n globalThis.Deno.inspect(v, {\n strAbbreviateSize: Infinity,\n iterableLimit: Infinity,\n ...opts,\n })\n // @ts-ignore: Node.js global\n // dnt-shim-ignore\n : util != null && \"inspect\" in util && typeof util.inspect === \"function\"\n ? (v, opts) =>\n // @ts-ignore: Node.js global\n // dnt-shim-ignore\n util.inspect(v, {\n maxArrayLength: Infinity,\n maxStringLength: Infinity,\n ...opts,\n })\n : (v) => JSON.stringify(v);\n\n/**\n * The formatted values for a log record.\n * @since 0.6.0\n */\nexport interface FormattedValues {\n /**\n * The formatted timestamp.\n */\n timestamp: string | null;\n\n /**\n * The formatted log level.\n */\n level: string;\n\n /**\n * The formatted category.\n */\n category: string;\n\n /**\n * The formatted message.\n */\n message: string;\n\n /**\n * The unformatted log record.\n */\n record: LogRecord;\n}\n\n/**\n * The various options for the built-in text formatters.\n * @since 0.6.0\n */\nexport interface TextFormatterOptions {\n /**\n * The timestamp format. This can be one of the following:\n *\n * - `\"date-time-timezone\"`: The date and time with the full timezone offset\n * (e.g., `\"2023-11-14 22:13:20.000 +00:00\"`).\n * - `\"date-time-tz\"`: The date and time with the short timezone offset\n * (e.g., `\"2023-11-14 22:13:20.000 +00\"`).\n * - `\"date-time\"`: The date and time without the timezone offset\n * (e.g., `\"2023-11-14 22:13:20.000\"`).\n * - `\"time-timezone\"`: The time with the full timezone offset but without\n * the date (e.g., `\"22:13:20.000 +00:00\"`).\n * - `\"time-tz\"`: The time with the short timezone offset but without the date\n * (e.g., `\"22:13:20.000 +00\"`).\n * - `\"time\"`: The time without the date or timezone offset\n * (e.g., `\"22:13:20.000\"`).\n * - `\"date\"`: The date without the time or timezone offset\n * (e.g., `\"2023-11-14\"`).\n * - `\"rfc3339\"`: The date and time in RFC 3339 format\n * (e.g., `\"2023-11-14T22:13:20.000Z\"`).\n * - `\"none\"` or `\"disabled\"`: No display\n *\n * Alternatively, this can be a function that accepts a timestamp and returns\n * a string.\n *\n * The default is `\"date-time-timezone\"`.\n */\n timestamp?:\n | \"date-time-timezone\"\n | \"date-time-tz\"\n | \"date-time\"\n | \"time-timezone\"\n | \"time-tz\"\n | \"time\"\n | \"date\"\n | \"rfc3339\"\n | \"none\"\n | \"disabled\"\n | ((ts: number) => string | null);\n\n /**\n * The log level format. This can be one of the following:\n *\n * - `\"ABBR\"`: The log level abbreviation in uppercase (e.g., `\"INF\"`).\n * - `\"FULL\"`: The full log level name in uppercase (e.g., `\"INFO\"`).\n * - `\"L\"`: The first letter of the log level in uppercase (e.g., `\"I\"`).\n * - `\"abbr\"`: The log level abbreviation in lowercase (e.g., `\"inf\"`).\n * - `\"full\"`: The full log level name in lowercase (e.g., `\"info\"`).\n * - `\"l\"`: The first letter of the log level in lowercase (e.g., `\"i\"`).\n *\n * Alternatively, this can be a function that accepts a log level and returns\n * a string.\n *\n * The default is `\"ABBR\"`.\n */\n level?:\n | \"ABBR\"\n | \"FULL\"\n | \"L\"\n | \"abbr\"\n | \"full\"\n | \"l\"\n | ((level: LogLevel) => string);\n\n /**\n * The separator between category names. For example, if the separator is\n * `\"·\"`, the category `[\"a\", \"b\", \"c\"]` will be formatted as `\"a·b·c\"`.\n * The default separator is `\"·\"`.\n *\n * If this is a function, it will be called with the category array and\n * should return a string, which will be used for rendering the category.\n */\n category?: string | ((category: readonly string[]) => string);\n\n /**\n * The format of the embedded values.\n *\n * A function that renders a value to a string. This function is used to\n * render the values in the log record. The default is [`util.inspect()`] in\n * Node.js/Bun and [`Deno.inspect()`] in Deno.\n *\n * [`util.inspect()`]: https://nodejs.org/api/util.html#utilinspectobject-options\n * [`Deno.inspect()`]: https://docs.deno.com/api/deno/~/Deno.inspect\n * @param value The value to render.\n * @returns The string representation of the value.\n */\n value?: (value: unknown) => string;\n\n /**\n * How those formatted parts are concatenated.\n *\n * A function that formats the log record. This function is called with the\n * formatted values and should return a string. Note that the formatted\n * *should not* include a newline character at the end.\n *\n * By default, this is a function that formats the log record as follows:\n *\n * ```\n * 2023-11-14 22:13:20.000 +00:00 [INF] category·subcategory: Hello, world!\n * ```\n * @param values The formatted values.\n * @returns The formatted log record.\n */\n format?: (values: FormattedValues) => string;\n}\n\n// Optimized helper functions for timestamp formatting\nfunction padZero(num: number): string {\n return num < 10 ? `0${num}` : `${num}`;\n}\n\nfunction padThree(num: number): string {\n return num < 10 ? `00${num}` : num < 100 ? `0${num}` : `${num}`;\n}\n\n// Pre-optimized timestamp formatter functions\nconst timestampFormatters = {\n \"date-time-timezone\": (ts: number): string => {\n const d = new Date(ts);\n const year = d.getUTCFullYear();\n const month = padZero(d.getUTCMonth() + 1);\n const day = padZero(d.getUTCDate());\n const hour = padZero(d.getUTCHours());\n const minute = padZero(d.getUTCMinutes());\n const second = padZero(d.getUTCSeconds());\n const ms = padThree(d.getUTCMilliseconds());\n return `${year}-${month}-${day} ${hour}:${minute}:${second}.${ms} +00:00`;\n },\n \"date-time-tz\": (ts: number): string => {\n const d = new Date(ts);\n const year = d.getUTCFullYear();\n const month = padZero(d.getUTCMonth() + 1);\n const day = padZero(d.getUTCDate());\n const hour = padZero(d.getUTCHours());\n const minute = padZero(d.getUTCMinutes());\n const second = padZero(d.getUTCSeconds());\n const ms = padThree(d.getUTCMilliseconds());\n return `${year}-${month}-${day} ${hour}:${minute}:${second}.${ms} +00`;\n },\n \"date-time\": (ts: number): string => {\n const d = new Date(ts);\n const year = d.getUTCFullYear();\n const month = padZero(d.getUTCMonth() + 1);\n const day = padZero(d.getUTCDate());\n const hour = padZero(d.getUTCHours());\n const minute = padZero(d.getUTCMinutes());\n const second = padZero(d.getUTCSeconds());\n const ms = padThree(d.getUTCMilliseconds());\n return `${year}-${month}-${day} ${hour}:${minute}:${second}.${ms}`;\n },\n \"time-timezone\": (ts: number): string => {\n const d = new Date(ts);\n const hour = padZero(d.getUTCHours());\n const minute = padZero(d.getUTCMinutes());\n const second = padZero(d.getUTCSeconds());\n const ms = padThree(d.getUTCMilliseconds());\n return `${hour}:${minute}:${second}.${ms} +00:00`;\n },\n \"time-tz\": (ts: number): string => {\n const d = new Date(ts);\n const hour = padZero(d.getUTCHours());\n const minute = padZero(d.getUTCMinutes());\n const second = padZero(d.getUTCSeconds());\n const ms = padThree(d.getUTCMilliseconds());\n return `${hour}:${minute}:${second}.${ms} +00`;\n },\n \"time\": (ts: number): string => {\n const d = new Date(ts);\n const hour = padZero(d.getUTCHours());\n const minute = padZero(d.getUTCMinutes());\n const second = padZero(d.getUTCSeconds());\n const ms = padThree(d.getUTCMilliseconds());\n return `${hour}:${minute}:${second}.${ms}`;\n },\n \"date\": (ts: number): string => {\n const d = new Date(ts);\n const year = d.getUTCFullYear();\n const month = padZero(d.getUTCMonth() + 1);\n const day = padZero(d.getUTCDate());\n return `${year}-${month}-${day}`;\n },\n \"rfc3339\": (ts: number): string => new Date(ts).toISOString(),\n \"none\": (): null => null,\n} as const;\n\n// Pre-computed level renderers for common cases\nconst levelRenderersCache = {\n ABBR: levelAbbreviations,\n abbr: {\n trace: \"trc\",\n debug: \"dbg\",\n info: \"inf\",\n warning: \"wrn\",\n error: \"err\",\n fatal: \"ftl\",\n } as const,\n FULL: {\n trace: \"TRACE\",\n debug: \"DEBUG\",\n info: \"INFO\",\n warning: \"WARNING\",\n error: \"ERROR\",\n fatal: \"FATAL\",\n } as const,\n full: {\n trace: \"trace\",\n debug: \"debug\",\n info: \"info\",\n warning: \"warning\",\n error: \"error\",\n fatal: \"fatal\",\n } as const,\n L: {\n trace: \"T\",\n debug: \"D\",\n info: \"I\",\n warning: \"W\",\n error: \"E\",\n fatal: \"F\",\n } as const,\n l: {\n trace: \"t\",\n debug: \"d\",\n info: \"i\",\n warning: \"w\",\n error: \"e\",\n fatal: \"f\",\n } as const,\n} as const;\n\n/**\n * Get a text formatter with the specified options. Although it's flexible\n * enough to create a custom formatter, if you want more control, you can\n * create a custom formatter that satisfies the {@link TextFormatter} type\n * instead.\n *\n * For more information on the options, see {@link TextFormatterOptions}.\n *\n * By default, the formatter formats log records as follows:\n *\n * ```\n * 2023-11-14 22:13:20.000 +00:00 [INF] category·subcategory: Hello, world!\n * ```\n * @param options The options for the text formatter.\n * @returns The text formatter.\n * @since 0.6.0\n */\nexport function getTextFormatter(\n options: TextFormatterOptions = {},\n): TextFormatter {\n // Pre-compute timestamp formatter with optimized lookup\n const timestampRenderer = (() => {\n const tsOption = options.timestamp;\n if (tsOption == null) {\n return timestampFormatters[\"date-time-timezone\"];\n } else if (tsOption === \"disabled\") {\n return timestampFormatters[\"none\"];\n } else if (\n typeof tsOption === \"string\" && tsOption in timestampFormatters\n ) {\n return timestampFormatters[tsOption as keyof typeof timestampFormatters];\n } else {\n return tsOption as (ts: number) => string | null;\n }\n })();\n\n const categorySeparator = options.category ?? \"·\";\n const valueRenderer = options.value ?? inspect;\n\n // Pre-compute level renderer for better performance\n const levelRenderer = (() => {\n const levelOption = options.level;\n if (levelOption == null || levelOption === \"ABBR\") {\n return (level: LogLevel): string => levelRenderersCache.ABBR[level];\n } else if (levelOption === \"abbr\") {\n return (level: LogLevel): string => levelRenderersCache.abbr[level];\n } else if (levelOption === \"FULL\") {\n return (level: LogLevel): string => levelRenderersCache.FULL[level];\n } else if (levelOption === \"full\") {\n return (level: LogLevel): string => levelRenderersCache.full[level];\n } else if (levelOption === \"L\") {\n return (level: LogLevel): string => levelRenderersCache.L[level];\n } else if (levelOption === \"l\") {\n return (level: LogLevel): string => levelRenderersCache.l[level];\n } else {\n return levelOption;\n }\n })();\n\n const formatter: (values: FormattedValues) => string = options.format ??\n (({ timestamp, level, category, message }: FormattedValues) =>\n `${timestamp ? `${timestamp} ` : \"\"}[${level}] ${category}: ${message}`);\n\n return (record: LogRecord): string => {\n // Optimized message building\n const msgParts = record.message;\n const msgLen = msgParts.length;\n\n let message: string;\n if (msgLen === 1) {\n // Fast path for simple messages with no interpolation\n message = msgParts[0] as string;\n } else if (msgLen <= 6) {\n // Fast path for small messages - direct concatenation\n message = \"\";\n for (let i = 0; i < msgLen; i++) {\n message += (i % 2 === 0) ? msgParts[i] : valueRenderer(msgParts[i]);\n }\n } else {\n // Optimized path for larger messages - array join\n const parts: string[] = new Array(msgLen);\n for (let i = 0; i < msgLen; i++) {\n parts[i] = (i % 2 === 0)\n ? msgParts[i] as string\n : valueRenderer(msgParts[i]);\n }\n message = parts.join(\"\");\n }\n\n const timestamp = timestampRenderer(record.timestamp);\n const level = levelRenderer(record.level);\n const category = typeof categorySeparator === \"function\"\n ? categorySeparator(record.category)\n : record.category.join(categorySeparator);\n\n const values: FormattedValues = {\n timestamp,\n level,\n category,\n message,\n record,\n };\n return `${formatter(values)}\\n`;\n };\n}\n\n/**\n * The default text formatter. This formatter formats log records as follows:\n *\n * ```\n * 2023-11-14 22:13:20.000 +00:00 [INF] category·subcategory: Hello, world!\n * ```\n *\n * @param record The log record to format.\n * @returns The formatted log record.\n */\nexport const defaultTextFormatter: TextFormatter = getTextFormatter();\n\nconst RESET = \"\\x1b[0m\";\n\n/**\n * The ANSI colors. These can be used to colorize text in the console.\n * @since 0.6.0\n */\nexport type AnsiColor =\n | \"black\"\n | \"red\"\n | \"green\"\n | \"yellow\"\n | \"blue\"\n | \"magenta\"\n | \"cyan\"\n | \"white\";\n\nconst ansiColors: Record<AnsiColor, string> = {\n black: \"\\x1b[30m\",\n red: \"\\x1b[31m\",\n green: \"\\x1b[32m\",\n yellow: \"\\x1b[33m\",\n blue: \"\\x1b[34m\",\n magenta: \"\\x1b[35m\",\n cyan: \"\\x1b[36m\",\n white: \"\\x1b[37m\",\n};\n\n/**\n * The ANSI text styles.\n * @since 0.6.0\n */\nexport type AnsiStyle =\n | \"bold\"\n | \"dim\"\n | \"italic\"\n | \"underline\"\n | \"strikethrough\";\n\nconst ansiStyles: Record<AnsiStyle, string> = {\n bold: \"\\x1b[1m\",\n dim: \"\\x1b[2m\",\n italic: \"\\x1b[3m\",\n underline: \"\\x1b[4m\",\n strikethrough: \"\\x1b[9m\",\n};\n\nconst defaultLevelColors: Record<LogLevel, AnsiColor | null> = {\n trace: null,\n debug: \"blue\",\n info: \"green\",\n warning: \"yellow\",\n error: \"red\",\n fatal: \"magenta\",\n};\n\n/**\n * The various options for the ANSI color formatter.\n * @since 0.6.0\n */\nexport interface AnsiColorFormatterOptions extends TextFormatterOptions {\n /**\n * The timestamp format. This can be one of the following:\n *\n * - `\"date-time-timezone\"`: The date and time with the full timezone offset\n * (e.g., `\"2023-11-14 22:13:20.000 +00:00\"`).\n * - `\"date-time-tz\"`: The date and time with the short timezone offset\n * (e.g., `\"2023-11-14 22:13:20.000 +00\"`).\n * - `\"date-time\"`: The date and time without the timezone offset\n * (e.g., `\"2023-11-14 22:13:20.000\"`).\n * - `\"time-timezone\"`: The time with the full timezone offset but without\n * the date (e.g., `\"22:13:20.000 +00:00\"`).\n * - `\"time-tz\"`: The time with the short timezone offset but without the date\n * (e.g., `\"22:13:20.000 +00\"`).\n * - `\"time\"`: The time without the date or timezone offset\n * (e.g., `\"22:13:20.000\"`).\n * - `\"date\"`: The date without the time or timezone offset\n * (e.g., `\"2023-11-14\"`).\n * - `\"rfc3339\"`: The date and time in RFC 3339 format\n * (e.g., `\"2023-11-14T22:13:20.000Z\"`).\n *\n * Alternatively, this can be a function that accepts a timestamp and returns\n * a string.\n *\n * The default is `\"date-time-tz\"`.\n */\n timestamp?:\n | \"date-time-timezone\"\n | \"date-time-tz\"\n | \"date-time\"\n | \"time-timezone\"\n | \"time-tz\"\n | \"time\"\n | \"date\"\n | \"rfc3339\"\n | ((ts: number) => string);\n\n /**\n * The ANSI style for the timestamp. `\"dim\"` is used by default.\n */\n timestampStyle?: AnsiStyle | null;\n\n /**\n * The ANSI color for the timestamp. No color is used by default.\n */\n timestampColor?: AnsiColor | null;\n\n /**\n * The ANSI style for the log level. `\"bold\"` is used by default.\n */\n levelStyle?: AnsiStyle | null;\n\n /**\n * The ANSI colors for the log levels. The default colors are as follows:\n *\n * - `\"trace\"`: `null` (no color)\n * - `\"debug\"`: `\"blue\"`\n * - `\"info\"`: `\"green\"`\n * - `\"warning\"`: `\"yellow\"`\n * - `\"error\"`: `\"red\"`\n * - `\"fatal\"`: `\"magenta\"`\n */\n levelColors?: Record<LogLevel, AnsiColor | null>;\n\n /**\n * The ANSI style for the category. `\"dim\"` is used by default.\n */\n categoryStyle?: AnsiStyle | null;\n\n /**\n * The ANSI color for the category. No color is used by default.\n */\n categoryColor?: AnsiColor | null;\n}\n\n/**\n * Get an ANSI color formatter with the specified options.\n *\n * ![A preview of an ANSI color formatter.](https://i.imgur.com/I8LlBUf.png)\n * @param option The options for the ANSI color formatter.\n * @returns The ANSI color formatter.\n * @since 0.6.0\n */\nexport function getAnsiColorFormatter(\n options: AnsiColorFormatterOptions = {},\n): TextFormatter {\n const format = options.format;\n const timestampStyle = typeof options.timestampStyle === \"undefined\"\n ? \"dim\"\n : options.timestampStyle;\n const timestampColor = options.timestampColor ?? null;\n const timestampPrefix = `${\n timestampStyle == null ? \"\" : ansiStyles[timestampStyle]\n }${timestampColor == null ? \"\" : ansiColors[timestampColor]}`;\n const timestampSuffix = timestampStyle == null && timestampColor == null\n ? \"\"\n : RESET;\n const levelStyle = typeof options.levelStyle === \"undefined\"\n ? \"bold\"\n : options.levelStyle;\n const levelColors = options.levelColors ?? defaultLevelColors;\n const categoryStyle = typeof options.categoryStyle === \"undefined\"\n ? \"dim\"\n : options.categoryStyle;\n const categoryColor = options.categoryColor ?? null;\n const categoryPrefix = `${\n categoryStyle == null ? \"\" : ansiStyles[categoryStyle]\n }${categoryColor == null ? \"\" : ansiColors[categoryColor]}`;\n const categorySuffix = categoryStyle == null && categoryColor == null\n ? \"\"\n : RESET;\n return getTextFormatter({\n timestamp: \"date-time-tz\",\n value(value: unknown): string {\n return inspect(value, { colors: true });\n },\n ...options,\n format({ timestamp, level, category, message, record }): string {\n const levelColor = levelColors[record.level];\n timestamp = `${timestampPrefix}${timestamp}${timestampSuffix}`;\n level = `${levelStyle == null ? \"\" : ansiStyles[levelStyle]}${\n levelColor == null ? \"\" : ansiColors[levelColor]\n }${level}${levelStyle == null && levelColor == null ? \"\" : RESET}`;\n return format == null\n ? `${timestamp} ${level} ${categoryPrefix}${category}:${categorySuffix} ${message}`\n : format({\n timestamp,\n level,\n category: `${categoryPrefix}${category}${categorySuffix}`,\n message,\n record,\n });\n },\n });\n}\n\n/**\n * A text formatter that uses ANSI colors to format log records.\n *\n * ![A preview of ansiColorFormatter.](https://i.imgur.com/I8LlBUf.png)\n *\n * @param record The log record to format.\n * @returns The formatted log record.\n * @since 0.5.0\n */\nexport const ansiColorFormatter: TextFormatter = getAnsiColorFormatter();\n\n/**\n * Options for the {@link getJsonLinesFormatter} function.\n * @since 0.11.0\n */\nexport interface JsonLinesFormatterOptions {\n /**\n * The separator between category names. For example, if the separator is\n * `\".\"`, the category `[\"a\", \"b\", \"c\"]` will be formatted as `\"a.b.c\"`.\n * If this is a function, it will be called with the category array and\n * should return a string or an array of strings, which will be used\n * for rendering the category.\n *\n * @default `\".\"`\n */\n readonly categorySeparator?:\n | string\n | ((category: readonly string[]) => string | readonly string[]);\n\n /**\n * The message format. This can be one of the following:\n *\n * - `\"template\"`: The raw message template is used as the message.\n * - `\"rendered\"`: The message is rendered with the values.\n *\n * @default `\"rendered\"`\n */\n readonly message?: \"template\" | \"rendered\";\n\n /**\n * The properties format. This can be one of the following:\n *\n * - `\"flatten\"`: The properties are flattened into the root object.\n * - `\"prepend:<prefix>\"`: The properties are prepended with the given prefix\n * (e.g., `\"prepend:ctx_\"` will prepend `ctx_` to each property key).\n * - `\"nest:<key>\"`: The properties are nested under the given key\n * (e.g., `\"nest:properties\"` will nest the properties under the\n * `properties` key).\n *\n * @default `\"nest:properties\"`\n */\n readonly properties?: \"flatten\" | `prepend:${string}` | `nest:${string}`;\n}\n\n/**\n * Get a [JSON Lines] formatter with the specified options. The log records\n * will be rendered as JSON objects, one per line, which is a common format\n * for log files. This format is also known as Newline-Delimited JSON (NDJSON).\n * It looks like this:\n *\n * ```json\n * {\"@timestamp\":\"2023-11-14T22:13:20.000Z\",\"level\":\"INFO\",\"message\":\"Hello, world!\",\"logger\":\"my.logger\",\"properties\":{\"key\":\"value\"}}\n * ```\n *\n * [JSON Lines]: https://jsonlines.org/\n * @param options The options for the JSON Lines formatter.\n * @returns The JSON Lines formatter.\n * @since 0.11.0\n */\nexport function getJsonLinesFormatter(\n options: JsonLinesFormatterOptions = {},\n): TextFormatter {\n // Most common configuration - optimize for the default case\n if (!options.categorySeparator && !options.message && !options.properties) {\n // Ultra-minimalist path - eliminate all possible overhead\n return (record: LogRecord): string => {\n // Direct benchmark pattern match (most common case first)\n if (record.message.length === 3) {\n return JSON.stringify({\n \"@timestamp\": new Date(record.timestamp).toISOString(),\n level: record.level === \"warning\"\n ? \"WARN\"\n : record.level.toUpperCase(),\n message: record.message[0] + JSON.stringify(record.message[1]) +\n record.message[2],\n logger: record.category.join(\".\"),\n properties: record.properties,\n });\n }\n\n // Single message (second most common)\n if (record.message.length === 1) {\n return JSON.stringify({\n \"@timestamp\": new Date(record.timestamp).toISOString(),\n level: record.level === \"warning\"\n ? \"WARN\"\n : record.level.toUpperCase(),\n message: record.message[0],\n logger: record.category.join(\".\"),\n properties: record.properties,\n });\n }\n\n // Complex messages (fallback)\n let msg = record.message[0] as string;\n for (let i = 1; i < record.message.length; i++) {\n msg += (i & 1) ? JSON.stringify(record.message[i]) : record.message[i];\n }\n\n return JSON.stringify({\n \"@timestamp\": new Date(record.timestamp).toISOString(),\n level: record.level === \"warning\" ? \"WARN\" : record.level.toUpperCase(),\n message: msg,\n logger: record.category.join(\".\"),\n properties: record.properties,\n });\n };\n }\n\n // Pre-compile configuration for non-default cases\n const isTemplateMessage = options.message === \"template\";\n const propertiesOption = options.properties ?? \"nest:properties\";\n\n // Pre-compile category joining strategy\n let joinCategory: (category: readonly string[]) => string | readonly string[];\n if (typeof options.categorySeparator === \"function\") {\n joinCategory = options.categorySeparator;\n } else {\n const separator = options.categorySeparator ?? \".\";\n joinCategory = (category: readonly string[]): string =>\n category.join(separator);\n }\n\n // Pre-compile properties handling strategy\n let getProperties: (\n properties: Record<string, unknown>,\n ) => Record<string, unknown>;\n\n if (propertiesOption === \"flatten\") {\n getProperties = (properties) => properties;\n } else if (propertiesOption.startsWith(\"prepend:\")) {\n const prefix = propertiesOption.substring(8);\n if (prefix === \"\") {\n throw new TypeError(\n `Invalid properties option: ${\n JSON.stringify(propertiesOption)\n }. It must be of the form \"prepend:<prefix>\" where <prefix> is a non-empty string.`,\n );\n }\n getProperties = (properties) => {\n const result: Record<string, unknown> = {};\n for (const key in properties) {\n result[`${prefix}${key}`] = properties[key];\n }\n return result;\n };\n } else if (propertiesOption.startsWith(\"nest:\")) {\n const key = propertiesOption.substring(5);\n getProperties = (properties) => ({ [key]: properties });\n } else {\n throw new TypeError(\n `Invalid properties option: ${\n JSON.stringify(propertiesOption)\n }. It must be \"flatten\", \"prepend:<prefix>\", or \"nest:<key>\".`,\n );\n }\n\n // Pre-compile message rendering function\n let getMessage: (record: LogRecord) => string;\n\n if (isTemplateMessage) {\n getMessage = (record: LogRecord): string => {\n if (typeof record.rawMessage === \"string\") {\n return record.rawMessage;\n }\n let msg = \"\";\n for (let i = 0; i < record.rawMessage.length; i++) {\n msg += i % 2 < 1 ? record.rawMessage[i] : \"{}\";\n }\n return msg;\n };\n } else {\n getMessage = (record: LogRecord): string => {\n const msgLen = record.message.length;\n\n if (msgLen === 1) {\n return record.message[0] as string;\n }\n\n let msg = \"\";\n for (let i = 0; i < msgLen; i++) {\n msg += (i % 2 < 1)\n ? record.message[i]\n : JSON.stringify(record.message[i]);\n }\n return msg;\n };\n }\n\n return (record: LogRecord): string => {\n return JSON.stringify({\n \"@timestamp\": new Date(record.timestamp).toISOString(),\n level: record.level === \"warning\" ? \"WARN\" : record.level.toUpperCase(),\n message: getMessage(record),\n logger: joinCategory(record.category),\n ...getProperties(record.properties),\n });\n };\n}\n\n/**\n * The default [JSON Lines] formatter. This formatter formats log records\n * as JSON objects, one per line, which is a common format for log files.\n * It looks like this:\n *\n * ```json\n * {\"@timestamp\":\"2023-11-14T22:13:20.000Z\",\"level\":\"INFO\",\"message\":\"Hello, world!\",\"logger\":\"my.logger\",\"properties\":{\"key\":\"value\"}}\n * ```\n *\n * You can customize the output by passing options to\n * {@link getJsonLinesFormatter}. For example, you can change the category\n * separator, the message format, and how the properties are formatted.\n *\n * [JSON Lines]: https://jsonlines.org/\n * @since 0.11.0\n */\nexport const jsonLinesFormatter: TextFormatter = getJsonLinesFormatter();\n\n/**\n * A console formatter is a function that accepts a log record and returns\n * an array of arguments to pass to {@link console.log}.\n *\n * @param record The log record to format.\n * @returns The formatted log record, as an array of arguments for\n * {@link console.log}.\n */\nexport type ConsoleFormatter = (record: LogRecord) => readonly unknown[];\n\n/**\n * The styles for the log level in the console.\n */\nconst logLevelStyles: Record<LogLevel, string> = {\n \"trace\": \"background-color: gray; color: white;\",\n \"debug\": \"background-color: gray; color: white;\",\n \"info\": \"background-color: white; color: black;\",\n \"warning\": \"background-color: orange; color: black;\",\n \"error\": \"background-color: red; color: white;\",\n \"fatal\": \"background-color: maroon; color: white;\",\n};\n\n/**\n * The default console formatter.\n *\n * @param record The log record to format.\n * @returns The formatted log record, as an array of arguments for\n * {@link console.log}.\n */\nexport function defaultConsoleFormatter(record: LogRecord): readonly unknown[] {\n let msg = \"\";\n const values: unknown[] = [];\n for (let i = 0; i < record.message.length; i++) {\n if (i % 2 === 0) msg += record.message[i];\n else {\n msg += \"%o\";\n values.push(record.message[i]);\n }\n }\n const date = new Date(record.timestamp);\n const time = `${date.getUTCHours().toString().padStart(2, \"0\")}:${\n date.getUTCMinutes().toString().padStart(2, \"0\")\n }:${date.getUTCSeconds().toString().padStart(2, \"0\")}.${\n date.getUTCMilliseconds().toString().padStart(3, \"0\")\n }`;\n return [\n `%c${time} %c${levelAbbreviations[record.level]}%c %c${\n record.category.join(\"\\xb7\")\n } %c${msg}`,\n \"color: gray;\",\n logLevelStyles[record.level],\n \"background-color: default;\",\n \"color: gray;\",\n \"color: default;\",\n ...values,\n ];\n}\n"],"mappings":";;;;;;AAgBA,MAAMA,qBAA+C;CACnD,SAAS;CACT,SAAS;CACT,QAAQ;CACR,WAAW;CACX,SAAS;CACT,SAAS;AACV;;;;;;;;;;;AAYD,MAAMC,iBAGG,aAAa,sBAGX,cAAc,eAAe,UAAU,YAAY,gBACxD,CAAC,MAAM,KAAK,UAAU,EAAE,GAGxB,UAAU,cAAc,aAAa,WAAW,eAGvC,WAAW,KAAK,YAAY,aACrC,CAAC,GAAG,SAGJ,WAAW,KAAK,QAA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AAC,UAAU,CAAC,SAAS,GAAG,IAAI,CAAC,GAC7D,KAAK,eAAe,CAAC,UAAU,CAAC,SAAS,GAAG,IAAI,CACjD,GAAG,KAAK,eAAe,CAAC,UAAU,CAAC,SAAS,GAAG,IAAI,CAAC,GACnD,KAAK,oBAAoB,CAAC,UAAU,CAAC,SAAS,GAAG,IAAI,CACtD;AACD,QAAO;GACJ,IAAI,KAAK,KAAK,mBAAmB,OAAO,OAAO,OAC9C,OAAO,SAAS,KAAK,IAAO,CAC7B,KAAK,IAAI;EACV;EACA,eAAe,OAAO;EACtB;EACA;EACA;EACA,GAAG;CACJ;AACF"}
package/formatter.ts CHANGED
@@ -209,6 +209,130 @@ export interface TextFormatterOptions {
209
209
  format?: (values: FormattedValues) => string;
210
210
  }
211
211
 
212
+ // Optimized helper functions for timestamp formatting
213
+ function padZero(num: number): string {
214
+ return num < 10 ? `0${num}` : `${num}`;
215
+ }
216
+
217
+ function padThree(num: number): string {
218
+ return num < 10 ? `00${num}` : num < 100 ? `0${num}` : `${num}`;
219
+ }
220
+
221
+ // Pre-optimized timestamp formatter functions
222
+ const timestampFormatters = {
223
+ "date-time-timezone": (ts: number): string => {
224
+ const d = new Date(ts);
225
+ const year = d.getUTCFullYear();
226
+ const month = padZero(d.getUTCMonth() + 1);
227
+ const day = padZero(d.getUTCDate());
228
+ const hour = padZero(d.getUTCHours());
229
+ const minute = padZero(d.getUTCMinutes());
230
+ const second = padZero(d.getUTCSeconds());
231
+ const ms = padThree(d.getUTCMilliseconds());
232
+ return `${year}-${month}-${day} ${hour}:${minute}:${second}.${ms} +00:00`;
233
+ },
234
+ "date-time-tz": (ts: number): string => {
235
+ const d = new Date(ts);
236
+ const year = d.getUTCFullYear();
237
+ const month = padZero(d.getUTCMonth() + 1);
238
+ const day = padZero(d.getUTCDate());
239
+ const hour = padZero(d.getUTCHours());
240
+ const minute = padZero(d.getUTCMinutes());
241
+ const second = padZero(d.getUTCSeconds());
242
+ const ms = padThree(d.getUTCMilliseconds());
243
+ return `${year}-${month}-${day} ${hour}:${minute}:${second}.${ms} +00`;
244
+ },
245
+ "date-time": (ts: number): string => {
246
+ const d = new Date(ts);
247
+ const year = d.getUTCFullYear();
248
+ const month = padZero(d.getUTCMonth() + 1);
249
+ const day = padZero(d.getUTCDate());
250
+ const hour = padZero(d.getUTCHours());
251
+ const minute = padZero(d.getUTCMinutes());
252
+ const second = padZero(d.getUTCSeconds());
253
+ const ms = padThree(d.getUTCMilliseconds());
254
+ return `${year}-${month}-${day} ${hour}:${minute}:${second}.${ms}`;
255
+ },
256
+ "time-timezone": (ts: number): string => {
257
+ const d = new Date(ts);
258
+ const hour = padZero(d.getUTCHours());
259
+ const minute = padZero(d.getUTCMinutes());
260
+ const second = padZero(d.getUTCSeconds());
261
+ const ms = padThree(d.getUTCMilliseconds());
262
+ return `${hour}:${minute}:${second}.${ms} +00:00`;
263
+ },
264
+ "time-tz": (ts: number): string => {
265
+ const d = new Date(ts);
266
+ const hour = padZero(d.getUTCHours());
267
+ const minute = padZero(d.getUTCMinutes());
268
+ const second = padZero(d.getUTCSeconds());
269
+ const ms = padThree(d.getUTCMilliseconds());
270
+ return `${hour}:${minute}:${second}.${ms} +00`;
271
+ },
272
+ "time": (ts: number): string => {
273
+ const d = new Date(ts);
274
+ const hour = padZero(d.getUTCHours());
275
+ const minute = padZero(d.getUTCMinutes());
276
+ const second = padZero(d.getUTCSeconds());
277
+ const ms = padThree(d.getUTCMilliseconds());
278
+ return `${hour}:${minute}:${second}.${ms}`;
279
+ },
280
+ "date": (ts: number): string => {
281
+ const d = new Date(ts);
282
+ const year = d.getUTCFullYear();
283
+ const month = padZero(d.getUTCMonth() + 1);
284
+ const day = padZero(d.getUTCDate());
285
+ return `${year}-${month}-${day}`;
286
+ },
287
+ "rfc3339": (ts: number): string => new Date(ts).toISOString(),
288
+ "none": (): null => null,
289
+ } as const;
290
+
291
+ // Pre-computed level renderers for common cases
292
+ const levelRenderersCache = {
293
+ ABBR: levelAbbreviations,
294
+ abbr: {
295
+ trace: "trc",
296
+ debug: "dbg",
297
+ info: "inf",
298
+ warning: "wrn",
299
+ error: "err",
300
+ fatal: "ftl",
301
+ } as const,
302
+ FULL: {
303
+ trace: "TRACE",
304
+ debug: "DEBUG",
305
+ info: "INFO",
306
+ warning: "WARNING",
307
+ error: "ERROR",
308
+ fatal: "FATAL",
309
+ } as const,
310
+ full: {
311
+ trace: "trace",
312
+ debug: "debug",
313
+ info: "info",
314
+ warning: "warning",
315
+ error: "error",
316
+ fatal: "fatal",
317
+ } as const,
318
+ L: {
319
+ trace: "T",
320
+ debug: "D",
321
+ info: "I",
322
+ warning: "W",
323
+ error: "E",
324
+ fatal: "F",
325
+ } as const,
326
+ l: {
327
+ trace: "t",
328
+ debug: "d",
329
+ info: "i",
330
+ warning: "w",
331
+ error: "e",
332
+ fatal: "f",
333
+ } as const,
334
+ } as const;
335
+
212
336
  /**
213
337
  * Get a text formatter with the specified options. Although it's flexible
214
338
  * enough to create a custom formatter, if you want more control, you can
@@ -229,61 +353,81 @@ export interface TextFormatterOptions {
229
353
  export function getTextFormatter(
230
354
  options: TextFormatterOptions = {},
231
355
  ): TextFormatter {
232
- const timestampRenderer =
233
- options.timestamp == null || options.timestamp === "date-time-timezone"
234
- ? (ts: number): string =>
235
- new Date(ts).toISOString().replace("T", " ").replace("Z", " +00:00")
236
- : options.timestamp === "date-time-tz"
237
- ? (ts: number): string =>
238
- new Date(ts).toISOString().replace("T", " ").replace("Z", " +00")
239
- : options.timestamp === "date-time"
240
- ? (ts: number): string =>
241
- new Date(ts).toISOString().replace("T", " ").replace("Z", "")
242
- : options.timestamp === "time-timezone"
243
- ? (ts: number): string =>
244
- new Date(ts).toISOString().replace(/.*T/, "").replace("Z", " +00:00")
245
- : options.timestamp === "time-tz"
246
- ? (ts: number): string =>
247
- new Date(ts).toISOString().replace(/.*T/, "").replace("Z", " +00")
248
- : options.timestamp === "time"
249
- ? (ts: number): string =>
250
- new Date(ts).toISOString().replace(/.*T/, "").replace("Z", "")
251
- : options.timestamp === "date"
252
- ? (ts: number): string => new Date(ts).toISOString().replace(/T.*/, "")
253
- : options.timestamp === "rfc3339"
254
- ? (ts: number): string => new Date(ts).toISOString()
255
- : options.timestamp === "none" || options.timestamp === "disabled"
256
- ? () => null
257
- : options.timestamp;
356
+ // Pre-compute timestamp formatter with optimized lookup
357
+ const timestampRenderer = (() => {
358
+ const tsOption = options.timestamp;
359
+ if (tsOption == null) {
360
+ return timestampFormatters["date-time-timezone"];
361
+ } else if (tsOption === "disabled") {
362
+ return timestampFormatters["none"];
363
+ } else if (
364
+ typeof tsOption === "string" && tsOption in timestampFormatters
365
+ ) {
366
+ return timestampFormatters[tsOption as keyof typeof timestampFormatters];
367
+ } else {
368
+ return tsOption as (ts: number) => string | null;
369
+ }
370
+ })();
371
+
258
372
  const categorySeparator = options.category ?? "·";
259
373
  const valueRenderer = options.value ?? inspect;
260
- const levelRenderer = options.level == null || options.level === "ABBR"
261
- ? (level: LogLevel): string => levelAbbreviations[level]
262
- : options.level === "abbr"
263
- ? (level: LogLevel): string => levelAbbreviations[level].toLowerCase()
264
- : options.level === "FULL"
265
- ? (level: LogLevel): string => level.toUpperCase()
266
- : options.level === "full"
267
- ? (level: LogLevel): string => level
268
- : options.level === "L"
269
- ? (level: LogLevel): string => level.charAt(0).toUpperCase()
270
- : options.level === "l"
271
- ? (level: LogLevel): string => level.charAt(0)
272
- : options.level;
374
+
375
+ // Pre-compute level renderer for better performance
376
+ const levelRenderer = (() => {
377
+ const levelOption = options.level;
378
+ if (levelOption == null || levelOption === "ABBR") {
379
+ return (level: LogLevel): string => levelRenderersCache.ABBR[level];
380
+ } else if (levelOption === "abbr") {
381
+ return (level: LogLevel): string => levelRenderersCache.abbr[level];
382
+ } else if (levelOption === "FULL") {
383
+ return (level: LogLevel): string => levelRenderersCache.FULL[level];
384
+ } else if (levelOption === "full") {
385
+ return (level: LogLevel): string => levelRenderersCache.full[level];
386
+ } else if (levelOption === "L") {
387
+ return (level: LogLevel): string => levelRenderersCache.L[level];
388
+ } else if (levelOption === "l") {
389
+ return (level: LogLevel): string => levelRenderersCache.l[level];
390
+ } else {
391
+ return levelOption;
392
+ }
393
+ })();
394
+
273
395
  const formatter: (values: FormattedValues) => string = options.format ??
274
396
  (({ timestamp, level, category, message }: FormattedValues) =>
275
397
  `${timestamp ? `${timestamp} ` : ""}[${level}] ${category}: ${message}`);
398
+
276
399
  return (record: LogRecord): string => {
277
- let message = "";
278
- for (let i = 0; i < record.message.length; i++) {
279
- if (i % 2 === 0) message += record.message[i];
280
- else message += valueRenderer(record.message[i]);
400
+ // Optimized message building
401
+ const msgParts = record.message;
402
+ const msgLen = msgParts.length;
403
+
404
+ let message: string;
405
+ if (msgLen === 1) {
406
+ // Fast path for simple messages with no interpolation
407
+ message = msgParts[0] as string;
408
+ } else if (msgLen <= 6) {
409
+ // Fast path for small messages - direct concatenation
410
+ message = "";
411
+ for (let i = 0; i < msgLen; i++) {
412
+ message += (i % 2 === 0) ? msgParts[i] : valueRenderer(msgParts[i]);
413
+ }
414
+ } else {
415
+ // Optimized path for larger messages - array join
416
+ const parts: string[] = new Array(msgLen);
417
+ for (let i = 0; i < msgLen; i++) {
418
+ parts[i] = (i % 2 === 0)
419
+ ? msgParts[i] as string
420
+ : valueRenderer(msgParts[i]);
421
+ }
422
+ message = parts.join("");
281
423
  }
424
+
282
425
  const timestamp = timestampRenderer(record.timestamp);
283
426
  const level = levelRenderer(record.level);
284
427
  const category = typeof categorySeparator === "function"
285
428
  ? categorySeparator(record.category)
286
429
  : record.category.join(categorySeparator);
430
+
287
431
  const values: FormattedValues = {
288
432
  timestamp,
289
433
  level,
@@ -574,6 +718,58 @@ export interface JsonLinesFormatterOptions {
574
718
  export function getJsonLinesFormatter(
575
719
  options: JsonLinesFormatterOptions = {},
576
720
  ): TextFormatter {
721
+ // Most common configuration - optimize for the default case
722
+ if (!options.categorySeparator && !options.message && !options.properties) {
723
+ // Ultra-minimalist path - eliminate all possible overhead
724
+ return (record: LogRecord): string => {
725
+ // Direct benchmark pattern match (most common case first)
726
+ if (record.message.length === 3) {
727
+ return JSON.stringify({
728
+ "@timestamp": new Date(record.timestamp).toISOString(),
729
+ level: record.level === "warning"
730
+ ? "WARN"
731
+ : record.level.toUpperCase(),
732
+ message: record.message[0] + JSON.stringify(record.message[1]) +
733
+ record.message[2],
734
+ logger: record.category.join("."),
735
+ properties: record.properties,
736
+ });
737
+ }
738
+
739
+ // Single message (second most common)
740
+ if (record.message.length === 1) {
741
+ return JSON.stringify({
742
+ "@timestamp": new Date(record.timestamp).toISOString(),
743
+ level: record.level === "warning"
744
+ ? "WARN"
745
+ : record.level.toUpperCase(),
746
+ message: record.message[0],
747
+ logger: record.category.join("."),
748
+ properties: record.properties,
749
+ });
750
+ }
751
+
752
+ // Complex messages (fallback)
753
+ let msg = record.message[0] as string;
754
+ for (let i = 1; i < record.message.length; i++) {
755
+ msg += (i & 1) ? JSON.stringify(record.message[i]) : record.message[i];
756
+ }
757
+
758
+ return JSON.stringify({
759
+ "@timestamp": new Date(record.timestamp).toISOString(),
760
+ level: record.level === "warning" ? "WARN" : record.level.toUpperCase(),
761
+ message: msg,
762
+ logger: record.category.join("."),
763
+ properties: record.properties,
764
+ });
765
+ };
766
+ }
767
+
768
+ // Pre-compile configuration for non-default cases
769
+ const isTemplateMessage = options.message === "template";
770
+ const propertiesOption = options.properties ?? "nest:properties";
771
+
772
+ // Pre-compile category joining strategy
577
773
  let joinCategory: (category: readonly string[]) => string | readonly string[];
578
774
  if (typeof options.categorySeparator === "function") {
579
775
  joinCategory = options.categorySeparator;
@@ -583,34 +779,11 @@ export function getJsonLinesFormatter(
583
779
  category.join(separator);
584
780
  }
585
781
 
586
- let getMessage: TextFormatter;
587
- if (options.message === "template") {
588
- getMessage = (record: LogRecord): string => {
589
- if (typeof record.rawMessage === "string") {
590
- return record.rawMessage;
591
- }
592
- let msg = "";
593
- for (let i = 0; i < record.rawMessage.length; i++) {
594
- msg += i % 2 < 1 ? record.rawMessage[i] : "{}";
595
- }
596
- return msg;
597
- };
598
- } else {
599
- getMessage = (record: LogRecord): string => {
600
- let msg = "";
601
- for (let i = 0; i < record.message.length; i++) {
602
- msg += i % 2 < 1
603
- ? record.message[i]
604
- : JSON.stringify(record.message[i]);
605
- }
606
- return msg;
607
- };
608
- }
609
-
610
- const propertiesOption = options.properties ?? "nest:properties";
782
+ // Pre-compile properties handling strategy
611
783
  let getProperties: (
612
784
  properties: Record<string, unknown>,
613
785
  ) => Record<string, unknown>;
786
+
614
787
  if (propertiesOption === "flatten") {
615
788
  getProperties = (properties) => properties;
616
789
  } else if (propertiesOption.startsWith("prepend:")) {
@@ -640,6 +813,38 @@ export function getJsonLinesFormatter(
640
813
  );
641
814
  }
642
815
 
816
+ // Pre-compile message rendering function
817
+ let getMessage: (record: LogRecord) => string;
818
+
819
+ if (isTemplateMessage) {
820
+ getMessage = (record: LogRecord): string => {
821
+ if (typeof record.rawMessage === "string") {
822
+ return record.rawMessage;
823
+ }
824
+ let msg = "";
825
+ for (let i = 0; i < record.rawMessage.length; i++) {
826
+ msg += i % 2 < 1 ? record.rawMessage[i] : "{}";
827
+ }
828
+ return msg;
829
+ };
830
+ } else {
831
+ getMessage = (record: LogRecord): string => {
832
+ const msgLen = record.message.length;
833
+
834
+ if (msgLen === 1) {
835
+ return record.message[0] as string;
836
+ }
837
+
838
+ let msg = "";
839
+ for (let i = 0; i < msgLen; i++) {
840
+ msg += (i % 2 < 1)
841
+ ? record.message[i]
842
+ : JSON.stringify(record.message[i]);
843
+ }
844
+ return msg;
845
+ };
846
+ }
847
+
643
848
  return (record: LogRecord): string => {
644
849
  return JSON.stringify({
645
850
  "@timestamp": new Date(record.timestamp).toISOString(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logtape/logtape",
3
- "version": "1.0.0-dev.241+13810dcf",
3
+ "version": "1.0.0-dev.247+ffe631a6",
4
4
  "description": "Simple logging library with zero dependencies for Deno/Node.js/Bun/browsers",
5
5
  "keywords": [
6
6
  "logging",
@@ -31,21 +31,37 @@
31
31
  "types": "./dist/mod.d.ts",
32
32
  "exports": {
33
33
  ".": {
34
+ "types": {
35
+ "import": "./dist/mod.d.ts",
36
+ "require": "./dist/mod.d.cts"
37
+ },
34
38
  "import": "./dist/mod.js",
35
- "require": "./dist/mod.cjs",
36
- "types": "./dist/mod.d.ts"
39
+ "require": "./dist/mod.cjs"
37
40
  },
38
41
  "./package.json": "./package.json"
39
42
  },
40
43
  "imports": {
41
44
  "#util": {
42
- "node": "./dist/util.node.cjs",
43
- "bun": "./dist/util.node.js",
45
+ "types": {
46
+ "import": "./dist/util.d.ts",
47
+ "require": "./dist/util.d.cts"
48
+ },
49
+ "browser": {
50
+ "import": "./dist/util.js",
51
+ "require": "./dist/util.cjs"
52
+ },
53
+ "node": {
54
+ "import": "./dist/util.node.js",
55
+ "require": "./dist/util.node.cjs"
56
+ },
57
+ "bun": {
58
+ "import": "./dist/util.node.js",
59
+ "require": "./dist/util.node.cjs"
60
+ },
44
61
  "deno": "./dist/util.deno.js",
45
62
  "import": "./dist/util.js",
46
63
  "require": "./dist/util.cjs",
47
- "default": "./dist/util.js",
48
- "types": "./dist/util.d.ts"
64
+ "default": "./dist/util.js"
49
65
  }
50
66
  },
51
67
  "devDependencies": {