@contember/logger 2.2.0-alpha.2 → 2.2.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/development/index.cjs +1 -0
  2. package/dist/development/index.cjs.map +1 -1
  3. package/dist/development/index.js +2 -1
  4. package/dist/development/src/handlers/PrettyPrintLoggerHandler.cjs +25 -13
  5. package/dist/development/src/handlers/PrettyPrintLoggerHandler.cjs.map +1 -1
  6. package/dist/development/src/handlers/PrettyPrintLoggerHandler.js +26 -14
  7. package/dist/development/src/handlers/PrettyPrintLoggerHandler.js.map +1 -1
  8. package/dist/development/src/proxy.cjs +2 -0
  9. package/dist/development/src/proxy.cjs.map +1 -1
  10. package/dist/development/src/proxy.js +2 -0
  11. package/dist/development/src/proxy.js.map +1 -1
  12. package/dist/production/index.cjs +1 -0
  13. package/dist/production/index.cjs.map +1 -1
  14. package/dist/production/index.js +2 -1
  15. package/dist/production/src/handlers/PrettyPrintLoggerHandler.cjs +25 -13
  16. package/dist/production/src/handlers/PrettyPrintLoggerHandler.cjs.map +1 -1
  17. package/dist/production/src/handlers/PrettyPrintLoggerHandler.js +26 -14
  18. package/dist/production/src/handlers/PrettyPrintLoggerHandler.js.map +1 -1
  19. package/dist/production/src/proxy.cjs +2 -0
  20. package/dist/production/src/proxy.cjs.map +1 -1
  21. package/dist/production/src/proxy.js +2 -0
  22. package/dist/production/src/proxy.js.map +1 -1
  23. package/dist/types/formatting.d.ts.map +1 -1
  24. package/dist/types/handlers/FingerCrossedLoggerHandler.d.ts.map +1 -1
  25. package/dist/types/handlers/JsonStreamLoggerHandler.d.ts.map +1 -1
  26. package/dist/types/handlers/LoggerHandlerList.d.ts.map +1 -1
  27. package/dist/types/handlers/NullLoggerHandler.d.ts.map +1 -1
  28. package/dist/types/handlers/PrettyPrintLoggerHandler.d.ts +6 -2
  29. package/dist/types/handlers/PrettyPrintLoggerHandler.d.ts.map +1 -1
  30. package/dist/types/handlers/TestLoggerHandler.d.ts.map +1 -1
  31. package/dist/types/impl.d.ts.map +1 -1
  32. package/dist/types/proxy.d.ts +1 -0
  33. package/dist/types/proxy.d.ts.map +1 -1
  34. package/dist/types/tsconfig.tsbuildinfo +1 -1
  35. package/package.json +2 -4
  36. package/src/handlers/PrettyPrintLoggerHandler.ts +36 -15
  37. package/src/proxy.ts +2 -0
  38. package/tests/cases/unit/fixtures/jsonHandlerConsumer.ts +3 -0
  39. package/tests/cases/unit/fixtures/prettyPrintHandlerConsumer.ts +3 -0
  40. package/tests/cases/unit/prettyPrintHandler.test.ts +60 -0
  41. package/tests/cases/unit/treeShaking.test.ts +26 -0
  42. package/tests/tsconfig.json +10 -0
  43. package/tsconfig.json +4 -1
@@ -13,6 +13,7 @@ exports.createLogger = impl.createLogger;
13
13
  exports.LogLevels = levels.LogLevels;
14
14
  exports.getLogger = proxy.getLogger;
15
15
  exports.logger = proxy.logger;
16
+ exports.tryGetLogger = proxy.tryGetLogger;
16
17
  exports.withLogger = proxy.withLogger;
17
18
  exports.FingerCrossedLoggerHandler = FingerCrossedLoggerHandler.FingerCrossedLoggerHandler;
18
19
  exports.JsonStreamLoggerHandler = JsonStreamLoggerHandler.JsonStreamLoggerHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,6 +1,6 @@
1
1
  import { createLogger } from "./src/impl.js";
2
2
  import { LogLevels } from "./src/levels.js";
3
- import { getLogger, logger, withLogger } from "./src/proxy.js";
3
+ import { getLogger, logger, tryGetLogger, withLogger } from "./src/proxy.js";
4
4
  import { FingerCrossedLoggerHandler } from "./src/handlers/FingerCrossedLoggerHandler.js";
5
5
  import { JsonStreamLoggerHandler } from "./src/handlers/JsonStreamLoggerHandler.js";
6
6
  import { PrettyPrintLoggerHandler } from "./src/handlers/PrettyPrintLoggerHandler.js";
@@ -18,6 +18,7 @@ export {
18
18
  createLogger,
19
19
  getLogger,
20
20
  logger,
21
+ tryGetLogger,
21
22
  withLogger
22
23
  };
23
24
  //# sourceMappingURL=index.js.map
@@ -1,15 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const chalk = require("chalk");
4
3
  const node_util = require("node:util");
5
4
  const levels = require("../levels.cjs");
6
5
  var __defProp = Object.defineProperty;
7
6
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
7
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
+ const detectColorSupport = () => {
9
+ const forceColor = process.env.FORCE_COLOR;
10
+ if (forceColor !== void 0) {
11
+ return forceColor !== "0" && forceColor !== "false";
12
+ }
13
+ const stdout = process.stdout;
14
+ return stdout.isTTY === true && (typeof stdout.hasColors !== "function" || stdout.hasColors());
15
+ };
16
+ const createStyler = (colors) => (styles, text) => {
17
+ if (!colors) {
18
+ return text;
19
+ }
20
+ const list = typeof styles === "string" ? [styles] : styles;
21
+ return list.reduceRight((result, current) => node_util.styleText(current, result, { validateStream: false }), text);
22
+ };
9
23
  class PrettyPrintLoggerHandler {
10
24
  constructor(stream, options = {}) {
11
25
  this.stream = stream;
12
26
  __publicField(this, "options");
27
+ __publicField(this, "style", createStyler(detectColorSupport()));
13
28
  this.options = {
14
29
  logLevel: levels.LogLevels.debug,
15
30
  formatters: {},
@@ -37,12 +52,12 @@ class PrettyPrintLoggerHandler {
37
52
  const formattedValue = node_util.inspect(value, {
38
53
  depth: 5
39
54
  }).replaceAll(/\n/g, "\n" + indent);
40
- const formattedValue2 = this.options.formatters[key] ? this.options.formatters[key]({ value, key, formattedValue, chalk, attributes: allAttributes }) : formattedValue;
55
+ const formattedValue2 = this.options.formatters[key] ? this.options.formatters[key]({ value, key, formattedValue, style: this.style, attributes: allAttributes }) : formattedValue;
41
56
  if (formattedValue2 === void 0) {
42
57
  continue;
43
58
  }
44
59
  if (typeof formattedValue2 === "string") {
45
- this.stream.write(indent + chalk.dim(`${key}: ${formattedValue2}
60
+ this.stream.write(indent + this.style("dim", `${key}: ${formattedValue2}
46
61
  `));
47
62
  } else {
48
63
  this.stream.write(indent + formattedValue2.line + "\n");
@@ -57,20 +72,17 @@ class PrettyPrintLoggerHandler {
57
72
  if (!result) {
58
73
  return date;
59
74
  }
60
- return chalk.dim(result[1] + "T") + result[2] + chalk.dim("." + result[3] + "Z");
75
+ return this.style("dim", result[1] + "T") + result[2] + this.style("dim", "." + result[3] + "Z");
61
76
  }
62
77
  formatLevel(level) {
63
78
  const levelText = `${level.name}${" ".repeat(5 - level.name.length)}`;
64
- let color = chalk;
65
79
  if (level.value <= 10) {
66
- color = color.dim;
67
- } else if (level.value <= 20) ;
68
- else if (level.value <= 30) {
69
- color = color.yellowBright;
70
- } else {
71
- color = color.redBright;
80
+ return this.style("dim", levelText);
81
+ }
82
+ if (level.value <= 20) {
83
+ return levelText;
72
84
  }
73
- return color(levelText);
85
+ return this.style(level.value <= 30 ? "yellowBright" : "redBright", levelText);
74
86
  }
75
87
  close() {
76
88
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PrettyPrintLoggerHandler.cjs","sources":["../../../../../packages/logger/src/handlers/PrettyPrintLoggerHandler.ts"],"sourcesContent":["import chalk from 'chalk'\nimport { inspect } from 'node:util'\nimport { LogEntry, LoggerAttributes, LoggerHandler, LogLevel } from '../types.js'\nimport { LogLevels } from '../levels.js'\n\nexport interface PrettyPrintLoggerHandlerOptions {\n\tlogLevel: LogLevel\n\tformatters: {\n\t\t[key: string]: (\n\t\t\targs: { value: any; formattedValue: string; key: string; chalk: typeof chalk; attributes: LoggerAttributes },\n\t\t) => undefined | string | { line: string }\n\t}\n}\n\nexport class PrettyPrintLoggerHandler implements LoggerHandler {\n\tprivate readonly options: PrettyPrintLoggerHandlerOptions\n\n\tconstructor(\n\t\tprivate readonly stream: NodeJS.WritableStream,\n\t\toptions: Partial<PrettyPrintLoggerHandlerOptions> = {},\n\t) {\n\t\tthis.options = {\n\t\t\tlogLevel: LogLevels.debug,\n\t\t\tformatters: {},\n\t\t\t...options,\n\t\t}\n\t}\n\n\tgetMinLevel(): number {\n\t\treturn this.options.logLevel.value\n\t}\n\n\thandle(entry: LogEntry) {\n\t\tif (entry.level.value < this.options.logLevel.value) {\n\t\t\treturn\n\t\t}\n\t\tconst startLength = entry.isoTime.length + 7\n\n\t\tthis.stream.write(`${this.formatTime(entry.isoTime)} ${this.formatLevel(entry.level)} `)\n\n\t\tconst indent = ' '.repeat(startLength)\n\t\tthis.stream.write(`${entry.message.replaceAll(/\\n/g, '\\n' + indent)}\\n`)\n\t\tconst allAttributes = { ...entry.loggerAttributes, ...entry.ownAttributes }\n\t\tfor (const key in allAttributes) {\n\t\t\tconst value = allAttributes[key]\n\t\t\tif (typeof key !== 'string' || value === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst formattedValue = inspect(value, {\n\t\t\t\tdepth: 5,\n\t\t\t}).replaceAll(/\\n/g, '\\n' + indent)\n\t\t\tconst formattedValue2 = this.options.formatters[key]\n\t\t\t\t? (this.options.formatters[key]({ value, key, formattedValue, chalk, attributes: allAttributes }))\n\t\t\t\t: formattedValue\n\t\t\tif (formattedValue2 === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (typeof formattedValue2 === 'string') {\n\t\t\t\tthis.stream.write(indent + chalk.dim(`${key}: ${formattedValue2}\\n`))\n\t\t\t} else {\n\t\t\t\tthis.stream.write(indent + formattedValue2.line + '\\n')\n\t\t\t}\n\t\t}\n\t\tif (entry.error) {\n\t\t\tthis.stream.write(inspect(entry.error).replaceAll(/^/gm, indent) + '\\n')\n\t\t}\n\t}\n\n\tprivate formatTime(date: string): string {\n\t\tconst result = date.match(/^([0-9-]+)T([0-9:]+)\\.(\\d+)Z$/)\n\t\tif (!result) {\n\t\t\treturn date\n\t\t}\n\t\treturn chalk.dim(result[1] + 'T') + result[2] + chalk.dim('.' + result[3] + 'Z')\n\t}\n\n\tprivate formatLevel(level: LogLevel): string {\n\t\tconst levelText = `${level.name}${' '.repeat(5 - level.name.length)}`\n\t\tlet color = chalk\n\t\tif (level.value <= 10) {\n\t\t\tcolor = color.dim\n\t\t} else if (level.value <= 20) {\n\t\t\t// nothing\n\t\t} else if (level.value <= 30) {\n\t\t\tcolor = color.yellowBright\n\t\t} else {\n\t\t\tcolor = color.redBright\n\t\t}\n\t\treturn color(levelText)\n\t}\n\n\tclose(): void {\n\t}\n}\n"],"names":["LogLevels","inspect"],"mappings":";;;;;;;;AAcO,MAAM,yBAAkD;AAAA,EAG9D,YACkB,QACjB,UAAoD,IACnD;AAFgB,SAAA,SAAA;AAHlB,kBAAA,MAAiB,SAAA;AAMhB,SAAK,UAAU;AAAA,MACd,UAAUA,OAAAA,UAAU;AAAA,MACpB,YAAY,CAAA;AAAA,MACZ,GAAG;AAAA,IAAA;AAAA,EAEL;AAAA,EAEA,cAAsB;AACrB,WAAO,KAAK,QAAQ,SAAS;AAAA,EAC9B;AAAA,EAEA,OAAO,OAAiB;AACvB,QAAI,MAAM,MAAM,QAAQ,KAAK,QAAQ,SAAS,OAAO;AACpD;AAAA,IACD;AACA,UAAM,cAAc,MAAM,QAAQ,SAAS;AAE3C,SAAK,OAAO,MAAM,GAAG,KAAK,WAAW,MAAM,OAAO,CAAC,IAAI,KAAK,YAAY,MAAM,KAAK,CAAC,GAAG;AAEvF,UAAM,SAAS,IAAI,OAAO,WAAW;AACrC,SAAK,OAAO,MAAM,GAAG,MAAM,QAAQ,WAAW,OAAO,OAAO,MAAM,CAAC;AAAA,CAAI;AACvE,UAAM,gBAAgB,EAAE,GAAG,MAAM,kBAAkB,GAAG,MAAM,cAAA;AAC5D,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cAAQ,MAAM;AAAA,IACf,OAAO;AACN,cAAQ,MAAM;AAAA,IACf;AACA,WAAO,MAAM,SAAS;AAAA,EACvB;AAAA,EAEA,QAAc;AAAA,EACd;AACD;;"}
1
+ {"version":3,"file":"PrettyPrintLoggerHandler.cjs","sources":["../../../../../packages/logger/src/handlers/PrettyPrintLoggerHandler.ts"],"sourcesContent":["import { inspect, styleText } from 'node:util'\nimport { LogEntry, LoggerAttributes, LoggerHandler, LogLevel } from '../types.js'\nimport { LogLevels } from '../levels.js'\n\nexport type LogTextStyle = Exclude<Parameters<typeof styleText>[0], readonly unknown[]>\n\n/** Styles `text` with the given styles (outermost first); returns it unchanged when the terminal has no colors. */\nexport type LogTextStyler = (styles: LogTextStyle | readonly LogTextStyle[], text: string) => string\n\nexport interface PrettyPrintLoggerHandlerOptions {\n\tlogLevel: LogLevel\n\tformatters: {\n\t\t[key: string]: (\n\t\t\targs: { value: any; formattedValue: string; key: string; style: LogTextStyler; attributes: LoggerAttributes },\n\t\t) => undefined | string | { line: string }\n\t}\n}\n\n// Same detection as in @contember/cli-common colors.ts (logger cannot depend on it); keep them in sync.\nconst detectColorSupport = (): boolean => {\n\tconst forceColor = process.env.FORCE_COLOR\n\tif (forceColor !== undefined) {\n\t\treturn forceColor !== '0' && forceColor !== 'false'\n\t}\n\t// hasColors() honours NO_COLOR, NODE_DISABLE_COLORS and TERM=dumb; Bun's non-TTY stdout has no hasColors.\n\tconst stdout = process.stdout\n\treturn stdout.isTTY === true && (typeof stdout.hasColors !== 'function' || stdout.hasColors())\n}\n\nconst createStyler = (colors: boolean): LogTextStyler => (styles, text) => {\n\tif (!colors) {\n\t\treturn text\n\t}\n\tconst list: readonly LogTextStyle[] = typeof styles === 'string' ? [styles] : styles\n\t// validateStream is off because the decision is ours; Bun ignores the option and Node < 22.13 lacks it.\n\treturn list.reduceRight((result, current) => styleText(current, result, { validateStream: false }), text)\n}\n\nexport class PrettyPrintLoggerHandler implements LoggerHandler {\n\tprivate readonly options: PrettyPrintLoggerHandlerOptions\n\tprivate readonly style: LogTextStyler = createStyler(detectColorSupport())\n\n\tconstructor(\n\t\tprivate readonly stream: NodeJS.WritableStream,\n\t\toptions: Partial<PrettyPrintLoggerHandlerOptions> = {},\n\t) {\n\t\tthis.options = {\n\t\t\tlogLevel: LogLevels.debug,\n\t\t\tformatters: {},\n\t\t\t...options,\n\t\t}\n\t}\n\n\tgetMinLevel(): number {\n\t\treturn this.options.logLevel.value\n\t}\n\n\thandle(entry: LogEntry) {\n\t\tif (entry.level.value < this.options.logLevel.value) {\n\t\t\treturn\n\t\t}\n\t\tconst startLength = entry.isoTime.length + 7\n\n\t\tthis.stream.write(`${this.formatTime(entry.isoTime)} ${this.formatLevel(entry.level)} `)\n\n\t\tconst indent = ' '.repeat(startLength)\n\t\tthis.stream.write(`${entry.message.replaceAll(/\\n/g, '\\n' + indent)}\\n`)\n\t\tconst allAttributes = { ...entry.loggerAttributes, ...entry.ownAttributes }\n\t\tfor (const key in allAttributes) {\n\t\t\tconst value = allAttributes[key]\n\t\t\tif (typeof key !== 'string' || value === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst formattedValue = inspect(value, {\n\t\t\t\tdepth: 5,\n\t\t\t}).replaceAll(/\\n/g, '\\n' + indent)\n\t\t\tconst formattedValue2 = this.options.formatters[key]\n\t\t\t\t? (this.options.formatters[key]({ value, key, formattedValue, style: this.style, attributes: allAttributes }))\n\t\t\t\t: formattedValue\n\t\t\tif (formattedValue2 === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (typeof formattedValue2 === 'string') {\n\t\t\t\tthis.stream.write(indent + this.style('dim', `${key}: ${formattedValue2}\\n`))\n\t\t\t} else {\n\t\t\t\tthis.stream.write(indent + formattedValue2.line + '\\n')\n\t\t\t}\n\t\t}\n\t\tif (entry.error) {\n\t\t\tthis.stream.write(inspect(entry.error).replaceAll(/^/gm, indent) + '\\n')\n\t\t}\n\t}\n\n\tprivate formatTime(date: string): string {\n\t\tconst result = date.match(/^([0-9-]+)T([0-9:]+)\\.(\\d+)Z$/)\n\t\tif (!result) {\n\t\t\treturn date\n\t\t}\n\t\treturn this.style('dim', result[1] + 'T') + result[2] + this.style('dim', '.' + result[3] + 'Z')\n\t}\n\n\tprivate formatLevel(level: LogLevel): string {\n\t\tconst levelText = `${level.name}${' '.repeat(5 - level.name.length)}`\n\t\tif (level.value <= 10) {\n\t\t\treturn this.style('dim', levelText)\n\t\t}\n\t\tif (level.value <= 20) {\n\t\t\treturn levelText\n\t\t}\n\t\treturn this.style(level.value <= 30 ? 'yellowBright' : 'redBright', levelText)\n\t}\n\n\tclose(): void {\n\t}\n}\n"],"names":["styleText","LogLevels","inspect"],"mappings":";;;;;;;AAmBA,MAAM,qBAAqB,MAAe;AACzC,QAAM,aAAa,QAAQ,IAAI;AAC/B,MAAI,eAAe,QAAW;AAC7B,WAAO,eAAe,OAAO,eAAe;AAAA,EAC7C;AAEA,QAAM,SAAS,QAAQ;AACvB,SAAO,OAAO,UAAU,SAAS,OAAO,OAAO,cAAc,cAAc,OAAO;AACnF;AAEA,MAAM,eAAe,CAAC,WAAmC,CAAC,QAAQ,SAAS;AAC1E,MAAI,CAAC,QAAQ;AACZ,WAAO;AAAA,EACR;AACA,QAAM,OAAgC,OAAO,WAAW,WAAW,CAAC,MAAM,IAAI;AAE9E,SAAO,KAAK,YAAY,CAAC,QAAQ,YAAYA,UAAAA,UAAU,SAAS,QAAQ,EAAE,gBAAgB,MAAA,CAAO,GAAG,IAAI;AACzG;AAEO,MAAM,yBAAkD;AAAA,EAI9D,YACkB,QACjB,UAAoD,IACnD;AAFgB,SAAA,SAAA;AAJlB,kBAAA,MAAiB,SAAA;AACjB,kBAAA,MAAiB,SAAuB,aAAa,mBAAA,CAAoB,CAAA;AAMxE,SAAK,UAAU;AAAA,MACd,UAAUC,OAAAA,UAAU;AAAA,MACpB,YAAY,CAAA;AAAA,MACZ,GAAG;AAAA,IAAA;AAAA,EAEL;AAAA,EAE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xE;AAAA,EACD;AAAA,EAEQ,WAAW,MAAsB;AACxC,UAAM,SAAS,KAAK,MAAM,+BAA+B;AACzD,QAAI,CAAC,QAAQ;AACZ,aAAO;AAAA,IACR;AACA,WAAO,KAAK,MAAM,OAAO,OAAO,CAAC,IAAI,GAAG,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,OAAO,MAAM,OAAO,CAAC,IAAI,GAAG;AAAA,EAChG;AAAA,EAEQ,YAAY,OAAyB;AAC5C,UAAM,YAAY,GAAG,MAAM,IAAI,GAAG,IAAI,OAAO,IAAI,MAAM,KAAK,MAAM,CAAC;AACnE,QAAI,MAAM,SAAS,IAAI;AACtB,aAAO,KAAK,MAAM,OAAO,SAAS;AAAA,IACnC;AACA,QAAI,MAAM,SAAS,IAAI;AACtB,aAAO;AAAA,IACR;AACA,WAAO,KAAK,MAAM,MAAM,SAAS,KAAK,iBAAiB,aAAa,SAAS;AAAA,EAC9E;AAAA,EAEA,QAAc;AAAA,EACd;AACD;;"}
@@ -1,13 +1,28 @@
1
- import chalk from "chalk";
2
- import { inspect } from "node:util";
1
+ import { inspect, styleText } from "node:util";
3
2
  import { LogLevels } from "../levels.js";
4
3
  var __defProp = Object.defineProperty;
5
4
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
5
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+ const detectColorSupport = () => {
7
+ const forceColor = process.env.FORCE_COLOR;
8
+ if (forceColor !== void 0) {
9
+ return forceColor !== "0" && forceColor !== "false";
10
+ }
11
+ const stdout = process.stdout;
12
+ return stdout.isTTY === true && (typeof stdout.hasColors !== "function" || stdout.hasColors());
13
+ };
14
+ const createStyler = (colors) => (styles, text) => {
15
+ if (!colors) {
16
+ return text;
17
+ }
18
+ const list = typeof styles === "string" ? [styles] : styles;
19
+ return list.reduceRight((result, current) => styleText(current, result, { validateStream: false }), text);
20
+ };
7
21
  class PrettyPrintLoggerHandler {
8
22
  constructor(stream, options = {}) {
9
23
  this.stream = stream;
10
24
  __publicField(this, "options");
25
+ __publicField(this, "style", createStyler(detectColorSupport()));
11
26
  this.options = {
12
27
  logLevel: LogLevels.debug,
13
28
  formatters: {},
@@ -35,12 +50,12 @@ class PrettyPrintLoggerHandler {
35
50
  const formattedValue = inspect(value, {
36
51
  depth: 5
37
52
  }).replaceAll(/\n/g, "\n" + indent);
38
- const formattedValue2 = this.options.formatters[key] ? this.options.formatters[key]({ value, key, formattedValue, chalk, attributes: allAttributes }) : formattedValue;
53
+ const formattedValue2 = this.options.formatters[key] ? this.options.formatters[key]({ value, key, formattedValue, style: this.style, attributes: allAttributes }) : formattedValue;
39
54
  if (formattedValue2 === void 0) {
40
55
  continue;
41
56
  }
42
57
  if (typeof formattedValue2 === "string") {
43
- this.stream.write(indent + chalk.dim(`${key}: ${formattedValue2}
58
+ this.stream.write(indent + this.style("dim", `${key}: ${formattedValue2}
44
59
  `));
45
60
  } else {
46
61
  this.stream.write(indent + formattedValue2.line + "\n");
@@ -55,20 +70,17 @@ class PrettyPrintLoggerHandler {
55
70
  if (!result) {
56
71
  return date;
57
72
  }
58
- return chalk.dim(result[1] + "T") + result[2] + chalk.dim("." + result[3] + "Z");
73
+ return this.style("dim", result[1] + "T") + result[2] + this.style("dim", "." + result[3] + "Z");
59
74
  }
60
75
  formatLevel(level) {
61
76
  const levelText = `${level.name}${" ".repeat(5 - level.name.length)}`;
62
- let color = chalk;
63
77
  if (level.value <= 10) {
64
- color = color.dim;
65
- } else if (level.value <= 20) ;
66
- else if (level.value <= 30) {
67
- color = color.yellowBright;
68
- } else {
69
- color = color.redBright;
78
+ return this.style("dim", levelText);
79
+ }
80
+ if (level.value <= 20) {
81
+ return levelText;
70
82
  }
71
- return color(levelText);
83
+ return this.style(level.value <= 30 ? "yellowBright" : "redBright", levelText);
72
84
  }
73
85
  close() {
74
86
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PrettyPrintLoggerHandler.js","sources":["../../../../../packages/logger/src/handlers/PrettyPrintLoggerHandler.ts"],"sourcesContent":["import chalk from 'chalk'\nimport { inspect } from 'node:util'\nimport { LogEntry, LoggerAttributes, LoggerHandler, LogLevel } from '../types.js'\nimport { LogLevels } from '../levels.js'\n\nexport interface PrettyPrintLoggerHandlerOptions {\n\tlogLevel: LogLevel\n\tformatters: {\n\t\t[key: string]: (\n\t\t\targs: { value: any; formattedValue: string; key: string; chalk: typeof chalk; attributes: LoggerAttributes },\n\t\t) => undefined | string | { line: string }\n\t}\n}\n\nexport class PrettyPrintLoggerHandler implements LoggerHandler {\n\tprivate readonly options: PrettyPrintLoggerHandlerOptions\n\n\tconstructor(\n\t\tprivate readonly stream: NodeJS.WritableStream,\n\t\toptions: Partial<PrettyPrintLoggerHandlerOptions> = {},\n\t) {\n\t\tthis.options = {\n\t\t\tlogLevel: LogLevels.debug,\n\t\t\tformatters: {},\n\t\t\t...options,\n\t\t}\n\t}\n\n\tgetMinLevel(): number {\n\t\treturn this.options.logLevel.value\n\t}\n\n\thandle(entry: LogEntry) {\n\t\tif (entry.level.value < this.options.logLevel.value) {\n\t\t\treturn\n\t\t}\n\t\tconst startLength = entry.isoTime.length + 7\n\n\t\tthis.stream.write(`${this.formatTime(entry.isoTime)} ${this.formatLevel(entry.level)} `)\n\n\t\tconst indent = ' '.repeat(startLength)\n\t\tthis.stream.write(`${entry.message.replaceAll(/\\n/g, '\\n' + indent)}\\n`)\n\t\tconst allAttributes = { ...entry.loggerAttributes, ...entry.ownAttributes }\n\t\tfor (const key in allAttributes) {\n\t\t\tconst value = allAttributes[key]\n\t\t\tif (typeof key !== 'string' || value === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst formattedValue = inspect(value, {\n\t\t\t\tdepth: 5,\n\t\t\t}).replaceAll(/\\n/g, '\\n' + indent)\n\t\t\tconst formattedValue2 = this.options.formatters[key]\n\t\t\t\t? (this.options.formatters[key]({ value, key, formattedValue, chalk, attributes: allAttributes }))\n\t\t\t\t: formattedValue\n\t\t\tif (formattedValue2 === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (typeof formattedValue2 === 'string') {\n\t\t\t\tthis.stream.write(indent + chalk.dim(`${key}: ${formattedValue2}\\n`))\n\t\t\t} else {\n\t\t\t\tthis.stream.write(indent + formattedValue2.line + '\\n')\n\t\t\t}\n\t\t}\n\t\tif (entry.error) {\n\t\t\tthis.stream.write(inspect(entry.error).replaceAll(/^/gm, indent) + '\\n')\n\t\t}\n\t}\n\n\tprivate formatTime(date: string): string {\n\t\tconst result = date.match(/^([0-9-]+)T([0-9:]+)\\.(\\d+)Z$/)\n\t\tif (!result) {\n\t\t\treturn date\n\t\t}\n\t\treturn chalk.dim(result[1] + 'T') + result[2] + chalk.dim('.' + result[3] + 'Z')\n\t}\n\n\tprivate formatLevel(level: LogLevel): string {\n\t\tconst levelText = `${level.name}${' '.repeat(5 - level.name.length)}`\n\t\tlet color = chalk\n\t\tif (level.value <= 10) {\n\t\t\tcolor = color.dim\n\t\t} else if (level.value <= 20) {\n\t\t\t// nothing\n\t\t} else if (level.value <= 30) {\n\t\t\tcolor = color.yellowBright\n\t\t} else {\n\t\t\tcolor = color.redBright\n\t\t}\n\t\treturn color(levelText)\n\t}\n\n\tclose(): void {\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAcO,MAAM,yBAAkD;AAAA,EAG9D,YACkB,QACjB,UAAoD,IACnD;AAFgB,SAAA,SAAA;AAHlB,kBAAA,MAAiB,SAAA;AAMhB,SAAK,UAAU;AAAA,MACd,UAAU,UAAU;AAAA,MACpB,YAAY,CAAA;AAAA,MACZ,GAAG;AAAA,IAAA;AAAA,EAEL;AAAA,EAEA,cAAsB;AACrB,WAAO,KAAK,QAAQ,SAAS;AAAA,EAC9B;AAAA,EAEA,OAAO,OAAiB;AACvB,QAAI,MAAM,MAAM,QAAQ,KAAK,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AO,CAAC,IAAI,GAAG,IAAI,OAAO,CAAC,IAAI,MAAM,IAAI,MAAM,OAAO,CAAC,IAAI,GAAG;AAAA,EAChF;AAAA,EAEQ,YAAY,OAAyB;AAC5C,UAAM,YAAY,GAAG,MAAM,IAAI,GAAG,IAAI,OAAO,IAAI,MAAM,KAAK,MAAM,CAAC;AACnE,QAAI,QAAQ;AACZ,QAAI,MAAM,SAAS,IAAI;AACtB,cAAQ,MAAM;AAAA,IACf,WAAW,MAAM,SAAS,GAAI;AAAA,aAEnB,MAAM,SAAS,IAAI;AAC7B,cAAQ,MAAM;AAAA,IACf,OAAO;AACN,cAAQ,MAAM;AAAA,IACf;AACA,WAAO,MAAM,SAAS;AAAA,EACvB;AAAA,EAEA,QAAc;AAAA,EACd;AACD;"}
1
+ {"version":3,"file":"PrettyPrintLoggerHandler.js","sources":["../../../../../packages/logger/src/handlers/PrettyPrintLoggerHandler.ts"],"sourcesContent":["import { inspect, styleText } from 'node:util'\nimport { LogEntry, LoggerAttributes, LoggerHandler, LogLevel } from '../types.js'\nimport { LogLevels } from '../levels.js'\n\nexport type LogTextStyle = Exclude<Parameters<typeof styleText>[0], readonly unknown[]>\n\n/** Styles `text` with the given styles (outermost first); returns it unchanged when the terminal has no colors. */\nexport type LogTextStyler = (styles: LogTextStyle | readonly LogTextStyle[], text: string) => string\n\nexport interface PrettyPrintLoggerHandlerOptions {\n\tlogLevel: LogLevel\n\tformatters: {\n\t\t[key: string]: (\n\t\t\targs: { value: any; formattedValue: string; key: string; style: LogTextStyler; attributes: LoggerAttributes },\n\t\t) => undefined | string | { line: string }\n\t}\n}\n\n// Same detection as in @contember/cli-common colors.ts (logger cannot depend on it); keep them in sync.\nconst detectColorSupport = (): boolean => {\n\tconst forceColor = process.env.FORCE_COLOR\n\tif (forceColor !== undefined) {\n\t\treturn forceColor !== '0' && forceColor !== 'false'\n\t}\n\t// hasColors() honours NO_COLOR, NODE_DISABLE_COLORS and TERM=dumb; Bun's non-TTY stdout has no hasColors.\n\tconst stdout = process.stdout\n\treturn stdout.isTTY === true && (typeof stdout.hasColors !== 'function' || stdout.hasColors())\n}\n\nconst createStyler = (colors: boolean): LogTextStyler => (styles, text) => {\n\tif (!colors) {\n\t\treturn text\n\t}\n\tconst list: readonly LogTextStyle[] = typeof styles === 'string' ? [styles] : styles\n\t// validateStream is off because the decision is ours; Bun ignores the option and Node < 22.13 lacks it.\n\treturn list.reduceRight((result, current) => styleText(current, result, { validateStream: false }), text)\n}\n\nexport class PrettyPrintLoggerHandler implements LoggerHandler {\n\tprivate readonly options: PrettyPrintLoggerHandlerOptions\n\tprivate readonly style: LogTextStyler = createStyler(detectColorSupport())\n\n\tconstructor(\n\t\tprivate readonly stream: NodeJS.WritableStream,\n\t\toptions: Partial<PrettyPrintLoggerHandlerOptions> = {},\n\t) {\n\t\tthis.options = {\n\t\t\tlogLevel: LogLevels.debug,\n\t\t\tformatters: {},\n\t\t\t...options,\n\t\t}\n\t}\n\n\tgetMinLevel(): number {\n\t\treturn this.options.logLevel.value\n\t}\n\n\thandle(entry: LogEntry) {\n\t\tif (entry.level.value < this.options.logLevel.value) {\n\t\t\treturn\n\t\t}\n\t\tconst startLength = entry.isoTime.length + 7\n\n\t\tthis.stream.write(`${this.formatTime(entry.isoTime)} ${this.formatLevel(entry.level)} `)\n\n\t\tconst indent = ' '.repeat(startLength)\n\t\tthis.stream.write(`${entry.message.replaceAll(/\\n/g, '\\n' + indent)}\\n`)\n\t\tconst allAttributes = { ...entry.loggerAttributes, ...entry.ownAttributes }\n\t\tfor (const key in allAttributes) {\n\t\t\tconst value = allAttributes[key]\n\t\t\tif (typeof key !== 'string' || value === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst formattedValue = inspect(value, {\n\t\t\t\tdepth: 5,\n\t\t\t}).replaceAll(/\\n/g, '\\n' + indent)\n\t\t\tconst formattedValue2 = this.options.formatters[key]\n\t\t\t\t? (this.options.formatters[key]({ value, key, formattedValue, style: this.style, attributes: allAttributes }))\n\t\t\t\t: formattedValue\n\t\t\tif (formattedValue2 === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (typeof formattedValue2 === 'string') {\n\t\t\t\tthis.stream.write(indent + this.style('dim', `${key}: ${formattedValue2}\\n`))\n\t\t\t} else {\n\t\t\t\tthis.stream.write(indent + formattedValue2.line + '\\n')\n\t\t\t}\n\t\t}\n\t\tif (entry.error) {\n\t\t\tthis.stream.write(inspect(entry.error).replaceAll(/^/gm, indent) + '\\n')\n\t\t}\n\t}\n\n\tprivate formatTime(date: string): string {\n\t\tconst result = date.match(/^([0-9-]+)T([0-9:]+)\\.(\\d+)Z$/)\n\t\tif (!result) {\n\t\t\treturn date\n\t\t}\n\t\treturn this.style('dim', result[1] + 'T') + result[2] + this.style('dim', '.' + result[3] + 'Z')\n\t}\n\n\tprivate formatLevel(level: LogLevel): string {\n\t\tconst levelText = `${level.name}${' '.repeat(5 - level.name.length)}`\n\t\tif (level.value <= 10) {\n\t\t\treturn this.style('dim', levelText)\n\t\t}\n\t\tif (level.value <= 20) {\n\t\t\treturn levelText\n\t\t}\n\t\treturn this.style(level.value <= 30 ? 'yellowBright' : 'redBright', levelText)\n\t}\n\n\tclose(): void {\n\t}\n}\n"],"names":[],"mappings":";;;;;AAmBA,MAAM,qBAAqB,MAAe;AACzC,QAAM,aAAa,QAAQ,IAAI;AAC/B,MAAI,eAAe,QAAW;AAC7B,WAAO,eAAe,OAAO,eAAe;AAAA,EAC7C;AAEA,QAAM,SAAS,QAAQ;AACvB,SAAO,OAAO,UAAU,SAAS,OAAO,OAAO,cAAc,cAAc,OAAO;AACnF;AAEA,MAAM,eAAe,CAAC,WAAmC,CAAC,QAAQ,SAAS;AAC1E,MAAI,CAAC,QAAQ;AACZ,WAAO;AAAA,EACR;AACA,QAAM,OAAgC,OAAO,WAAW,WAAW,CAAC,MAAM,IAAI;AAE9E,SAAO,KAAK,YAAY,CAAC,QAAQ,YAAY,UAAU,SAAS,QAAQ,EAAE,gB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AAU;AACxC,aAAK,OAAO,MAAM,SAAS,KAAK,MAAM,OAAO,GAAG,GAAG,KAAK,eAAe;AAAA,CAAI,CAAC;AAAA,MAC7E,OAAO;AACN,aAAK,OAAO,MAAM,SAAS,gBAAgB,OAAO,IAAI;AAAA,MACvD;AAAA,IACD;AACA,QAAI,MAAM,OAAO;AAChB,WAAK,OAAO,MAAM,QAAQ,MAAM,KAAK,EAAE,WAAW,OAAO,MAAM,IAAI,IAAI;AAAA,IACxE;AAAA,EACD;AAAA,EAEQ,WAAW,MAAsB;AACxC,UAAM,SAAS,KAAK,MAAM,+BAA+B;AACzD,QAAI,CAAC,QAAQ;AACZ,aAAO;AAAA,IACR;AACA,WAAO,KAAK,MAAM,OAAO,OAAO,CAAC,IAAI,GAAG,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,OAAO,MAAM,OAAO,CAAC,IAAI,GAAG;AAAA,EAChG;AAAA,EAEQ,YAAY,OAAyB;AAC5C,UAAM,YAAY,GAAG,MAAM,IAAI,GAAG,IAAI,OAAO,IAAI,MAAM,KAAK,MAAM,CAAC;AACnE,QAAI,MAAM,SAAS,IAAI;AACtB,aAAO,KAAK,MAAM,OAAO,SAAS;AAAA,IACnC;AACA,QAAI,MAAM,SAAS,IAAI;AACtB,aAAO;AAAA,IACR;AACA,WAAO,KAAK,MAAM,MAAM,SAAS,KAAK,iBAAiB,aAAa,SAAS;AAAA,EAC9E;AAAA,EAEA,QAAc;AAAA,EACd;AACD;"}
@@ -48,7 +48,9 @@ const getLogger = () => {
48
48
  }
49
49
  return logger2;
50
50
  };
51
+ const tryGetLogger = () => loggerStore.getStore();
51
52
  exports.getLogger = getLogger;
52
53
  exports.logger = logger;
54
+ exports.tryGetLogger = tryGetLogger;
53
55
  exports.withLogger = withLogger;
54
56
  //# sourceMappingURL=proxy.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.cjs","sources":["../../../../packages/logger/src/proxy.ts"],"sourcesContent":["import { Logger, LoggerAttributes, LoggerHandler, LoggerOptions } from './types.js'\nimport { AsyncLocalStorage } from 'node:async_hooks'\n\nconst loggerStore = new AsyncLocalStorage<Logger>()\n\nclass CurrentLoggerProxy implements Logger {\n\tcrit(a: any, b?: any, c?: any) {\n\t\tgetLogger().crit(a, b)\n\t}\n\n\terror(a: any, b?: any, c?: any) {\n\t\tgetLogger().error(a, b)\n\t}\n\n\twarn(a: any, b?: any, c?: any) {\n\t\tgetLogger().warn(a, b)\n\t}\n\n\tinfo(a: any, b?: any, c?: any) {\n\t\tgetLogger().info(a, b)\n\t}\n\n\tdebug(a: any, b?: any, c?: any) {\n\t\tgetLogger().debug(a, b)\n\t}\n\n\tlog(level: any, a: any, b?: any, c?: any) {\n\t\tgetLogger().log(level, a, b)\n\t}\n\n\tchild(attributes?: LoggerAttributes, options?: Partial<LoggerOptions>): Logger {\n\t\treturn getLogger().child(attributes, options)\n\t}\n\n\tget attributes() {\n\t\treturn getLogger().attributes\n\t}\n\n\tclose(): void {\n\t\tgetLogger().close()\n\t}\n\n\tscope<T>(cb: (logger: Logger) => Promise<T> | T, attributes?: LoggerAttributes, options?: Partial<LoggerOptions>): Promise<T> {\n\t\treturn getLogger().scope(cb, attributes, options)\n\t}\n\n\taddHandler(handler: LoggerHandler): void {\n\t\tgetLogger().addHandler(handler)\n\t}\n}\n\nexport const logger: Logger = new CurrentLoggerProxy()\n\nexport const withLogger = <R>(logger: Logger, callback: () => R): R => {\n\treturn loggerStore.run(logger, callback)\n}\n\nexport const getLogger = (): Logger => {\n\tconst logger = loggerStore.getStore()\n\tif (!logger) {\n\t\tthrow new Error('Logger was not set')\n\t}\n\treturn logger\n}\n"],"names":["AsyncLocalStorage","logger"],"mappings":";;;AAGA,MAAM,cAAc,IAAIA,iBAAAA,kBAAA;AAExB,MAAM,mBAAqC;AAAA,EAC1C,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,MAAM,GAAQ,GAAS,GAAS;AAC/B,gBAAY,MAAM,GAAG,CAAC;AAAA,EACvB;AAAA,EAEA,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,MAAM,GAAQ,GAAS,GAAS;AAC/B,gBAAY,MAAM,GAAG,CAAC;AAAA,EACvB;AAAA,EAEA,IAAI,OAAY,GAAQ,GAAS,GAAS;AACzC,cAAA,EAAY,IAAI,OAAO,GAAG,CAAC;AAAA,EAC5B;AAAA,EAEA,MAAM,YAA+B,SAA0C;AAC9E,WAAO,UAAA,EAAY,MAAM,YAAY,OAAO;AAAA,EAC7C;AAAA,EAEA,IAAI,aAAa;AAChB,WAAO,YAAY;AAAA,EACpB;AAAA,EAEA,QAAc;AACb,cAAA,EAAY,MAAA;AAAA,EACb;AAAA,EAEA,MAAS,IAAwC,YAA+B,SAA8C;AAC7H,WAAO,UAAA,EAAY,MAAM,IAAI,YAAY,OAAO;AAAA,EACjD;AAAA,EAEA,WAAW,SAA8B;AACxC,cAAA,EAAY,WAAW,OAAO;AAAA,EAC/B;AACD;AAEO,MAAM,SAAiB,IAAI,mBAAA;AAE3B,MAAM,aAAa,CAAIC,SAAgB,aAAyB;AACtE,SAAO,YAAY,IAAIA,SAAQ,QAAQ;AACxC;AAEO,MAAM,YAAY,MAAc;AACtC,QAAMA,UAAS,YAAY,SAAA;AAC3B,MAAI,CAACA,SAAQ;AACZ,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACrC;AACA,SAAOA;AACR;;;;"}
1
+ {"version":3,"file":"proxy.cjs","sources":["../../../../packages/logger/src/proxy.ts"],"sourcesContent":["import { Logger, LoggerAttributes, LoggerHandler, LoggerOptions } from './types.js'\nimport { AsyncLocalStorage } from 'node:async_hooks'\n\nconst loggerStore = new AsyncLocalStorage<Logger>()\n\nclass CurrentLoggerProxy implements Logger {\n\tcrit(a: any, b?: any, c?: any) {\n\t\tgetLogger().crit(a, b)\n\t}\n\n\terror(a: any, b?: any, c?: any) {\n\t\tgetLogger().error(a, b)\n\t}\n\n\twarn(a: any, b?: any, c?: any) {\n\t\tgetLogger().warn(a, b)\n\t}\n\n\tinfo(a: any, b?: any, c?: any) {\n\t\tgetLogger().info(a, b)\n\t}\n\n\tdebug(a: any, b?: any, c?: any) {\n\t\tgetLogger().debug(a, b)\n\t}\n\n\tlog(level: any, a: any, b?: any, c?: any) {\n\t\tgetLogger().log(level, a, b)\n\t}\n\n\tchild(attributes?: LoggerAttributes, options?: Partial<LoggerOptions>): Logger {\n\t\treturn getLogger().child(attributes, options)\n\t}\n\n\tget attributes() {\n\t\treturn getLogger().attributes\n\t}\n\n\tclose(): void {\n\t\tgetLogger().close()\n\t}\n\n\tscope<T>(cb: (logger: Logger) => Promise<T> | T, attributes?: LoggerAttributes, options?: Partial<LoggerOptions>): Promise<T> {\n\t\treturn getLogger().scope(cb, attributes, options)\n\t}\n\n\taddHandler(handler: LoggerHandler): void {\n\t\tgetLogger().addHandler(handler)\n\t}\n}\n\nexport const logger: Logger = new CurrentLoggerProxy()\n\nexport const withLogger = <R>(logger: Logger, callback: () => R): R => {\n\treturn loggerStore.run(logger, callback)\n}\n\nexport const getLogger = (): Logger => {\n\tconst logger = loggerStore.getStore()\n\tif (!logger) {\n\t\tthrow new Error('Logger was not set')\n\t}\n\treturn logger\n}\n\nexport const tryGetLogger = (): Logger | undefined => loggerStore.getStore()\n"],"names":["AsyncLocalStorage","logger"],"mappings":";;;AAGA,MAAM,cAAc,IAAIA,iBAAAA,kBAAA;AAExB,MAAM,mBAAqC;AAAA,EAC1C,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,MAAM,GAAQ,GAAS,GAAS;AAC/B,gBAAY,MAAM,GAAG,CAAC;AAAA,EACvB;AAAA,EAEA,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,MAAM,GAAQ,GAAS,GAAS;AAC/B,gBAAY,MAAM,GAAG,CAAC;AAAA,EACvB;AAAA,EAEA,IAAI,OAAY,GAAQ,GAAS,GAAS;AACzC,cAAA,EAAY,IAAI,OAAO,GAAG,CAAC;AAAA,EAC5B;AAAA,EAEA,MAAM,YAA+B,SAA0C;AAC9E,WAAO,UAAA,EAAY,MAAM,YAAY,OAAO;AAAA,EAC7C;AAAA,EAEA,IAAI,aAAa;AAChB,WAAO,YAAY;AAAA,EACpB;AAAA,EAEA,QAAc;AACb,cAAA,EAAY,MAAA;AAAA,EACb;AAAA,EAEA,MAAS,IAAwC,YAA+B,SAA8C;AAC7H,WAAO,UAAA,EAAY,MAAM,IAAI,YAAY,OAAO;AAAA,EACjD;AAAA,EAEA,WAAW,SAA8B;AACxC,cAAA,EAAY,WAAW,OAAO;AAAA,EAC/B;AACD;AAEO,MAAM,SAAiB,IAAI,mBAAA;AAE3B,MAAM,aAAa,CAAIC,SAAgB,aAAyB;AACtE,SAAO,YAAY,IAAIA,SAAQ,QAAQ;AACxC;AAEO,MAAM,YAAY,MAAc;AACtC,QAAMA,UAAS,YAAY,SAAA;AAC3B,MAAI,CAACA,SAAQ;AACZ,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACrC;AACA,SAAOA;AACR;AAEO,MAAM,eAAe,MAA0B,YAAY,SAAA;;;;;"}
@@ -46,9 +46,11 @@ const getLogger = () => {
46
46
  }
47
47
  return logger2;
48
48
  };
49
+ const tryGetLogger = () => loggerStore.getStore();
49
50
  export {
50
51
  getLogger,
51
52
  logger,
53
+ tryGetLogger,
52
54
  withLogger
53
55
  };
54
56
  //# sourceMappingURL=proxy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.js","sources":["../../../../packages/logger/src/proxy.ts"],"sourcesContent":["import { Logger, LoggerAttributes, LoggerHandler, LoggerOptions } from './types.js'\nimport { AsyncLocalStorage } from 'node:async_hooks'\n\nconst loggerStore = new AsyncLocalStorage<Logger>()\n\nclass CurrentLoggerProxy implements Logger {\n\tcrit(a: any, b?: any, c?: any) {\n\t\tgetLogger().crit(a, b)\n\t}\n\n\terror(a: any, b?: any, c?: any) {\n\t\tgetLogger().error(a, b)\n\t}\n\n\twarn(a: any, b?: any, c?: any) {\n\t\tgetLogger().warn(a, b)\n\t}\n\n\tinfo(a: any, b?: any, c?: any) {\n\t\tgetLogger().info(a, b)\n\t}\n\n\tdebug(a: any, b?: any, c?: any) {\n\t\tgetLogger().debug(a, b)\n\t}\n\n\tlog(level: any, a: any, b?: any, c?: any) {\n\t\tgetLogger().log(level, a, b)\n\t}\n\n\tchild(attributes?: LoggerAttributes, options?: Partial<LoggerOptions>): Logger {\n\t\treturn getLogger().child(attributes, options)\n\t}\n\n\tget attributes() {\n\t\treturn getLogger().attributes\n\t}\n\n\tclose(): void {\n\t\tgetLogger().close()\n\t}\n\n\tscope<T>(cb: (logger: Logger) => Promise<T> | T, attributes?: LoggerAttributes, options?: Partial<LoggerOptions>): Promise<T> {\n\t\treturn getLogger().scope(cb, attributes, options)\n\t}\n\n\taddHandler(handler: LoggerHandler): void {\n\t\tgetLogger().addHandler(handler)\n\t}\n}\n\nexport const logger: Logger = new CurrentLoggerProxy()\n\nexport const withLogger = <R>(logger: Logger, callback: () => R): R => {\n\treturn loggerStore.run(logger, callback)\n}\n\nexport const getLogger = (): Logger => {\n\tconst logger = loggerStore.getStore()\n\tif (!logger) {\n\t\tthrow new Error('Logger was not set')\n\t}\n\treturn logger\n}\n"],"names":["logger"],"mappings":";AAGA,MAAM,cAAc,IAAI,kBAAA;AAExB,MAAM,mBAAqC;AAAA,EAC1C,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,MAAM,GAAQ,GAAS,GAAS;AAC/B,gBAAY,MAAM,GAAG,CAAC;AAAA,EACvB;AAAA,EAEA,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,MAAM,GAAQ,GAAS,GAAS;AAC/B,gBAAY,MAAM,GAAG,CAAC;AAAA,EACvB;AAAA,EAEA,IAAI,OAAY,GAAQ,GAAS,GAAS;AACzC,cAAA,EAAY,IAAI,OAAO,GAAG,CAAC;AAAA,EAC5B;AAAA,EAEA,MAAM,YAA+B,SAA0C;AAC9E,WAAO,UAAA,EAAY,MAAM,YAAY,OAAO;AAAA,EAC7C;AAAA,EAEA,IAAI,aAAa;AAChB,WAAO,YAAY;AAAA,EACpB;AAAA,EAEA,QAAc;AACb,cAAA,EAAY,MAAA;AAAA,EACb;AAAA,EAEA,MAAS,IAAwC,YAA+B,SAA8C;AAC7H,WAAO,UAAA,EAAY,MAAM,IAAI,YAAY,OAAO;AAAA,EACjD;AAAA,EAEA,WAAW,SAA8B;AACxC,cAAA,EAAY,WAAW,OAAO;AAAA,EAC/B;AACD;AAEO,MAAM,SAAiB,IAAI,mBAAA;AAE3B,MAAM,aAAa,CAAIA,SAAgB,aAAyB;AACtE,SAAO,YAAY,IAAIA,SAAQ,QAAQ;AACxC;AAEO,MAAM,YAAY,MAAc;AACtC,QAAMA,UAAS,YAAY,SAAA;AAC3B,MAAI,CAACA,SAAQ;AACZ,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACrC;AACA,SAAOA;AACR;"}
1
+ {"version":3,"file":"proxy.js","sources":["../../../../packages/logger/src/proxy.ts"],"sourcesContent":["import { Logger, LoggerAttributes, LoggerHandler, LoggerOptions } from './types.js'\nimport { AsyncLocalStorage } from 'node:async_hooks'\n\nconst loggerStore = new AsyncLocalStorage<Logger>()\n\nclass CurrentLoggerProxy implements Logger {\n\tcrit(a: any, b?: any, c?: any) {\n\t\tgetLogger().crit(a, b)\n\t}\n\n\terror(a: any, b?: any, c?: any) {\n\t\tgetLogger().error(a, b)\n\t}\n\n\twarn(a: any, b?: any, c?: any) {\n\t\tgetLogger().warn(a, b)\n\t}\n\n\tinfo(a: any, b?: any, c?: any) {\n\t\tgetLogger().info(a, b)\n\t}\n\n\tdebug(a: any, b?: any, c?: any) {\n\t\tgetLogger().debug(a, b)\n\t}\n\n\tlog(level: any, a: any, b?: any, c?: any) {\n\t\tgetLogger().log(level, a, b)\n\t}\n\n\tchild(attributes?: LoggerAttributes, options?: Partial<LoggerOptions>): Logger {\n\t\treturn getLogger().child(attributes, options)\n\t}\n\n\tget attributes() {\n\t\treturn getLogger().attributes\n\t}\n\n\tclose(): void {\n\t\tgetLogger().close()\n\t}\n\n\tscope<T>(cb: (logger: Logger) => Promise<T> | T, attributes?: LoggerAttributes, options?: Partial<LoggerOptions>): Promise<T> {\n\t\treturn getLogger().scope(cb, attributes, options)\n\t}\n\n\taddHandler(handler: LoggerHandler): void {\n\t\tgetLogger().addHandler(handler)\n\t}\n}\n\nexport const logger: Logger = new CurrentLoggerProxy()\n\nexport const withLogger = <R>(logger: Logger, callback: () => R): R => {\n\treturn loggerStore.run(logger, callback)\n}\n\nexport const getLogger = (): Logger => {\n\tconst logger = loggerStore.getStore()\n\tif (!logger) {\n\t\tthrow new Error('Logger was not set')\n\t}\n\treturn logger\n}\n\nexport const tryGetLogger = (): Logger | undefined => loggerStore.getStore()\n"],"names":["logger"],"mappings":";AAGA,MAAM,cAAc,IAAI,kBAAA;AAExB,MAAM,mBAAqC;AAAA,EAC1C,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,MAAM,GAAQ,GAAS,GAAS;AAC/B,gBAAY,MAAM,GAAG,CAAC;AAAA,EACvB;AAAA,EAEA,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,MAAM,GAAQ,GAAS,GAAS;AAC/B,gBAAY,MAAM,GAAG,CAAC;AAAA,EACvB;AAAA,EAEA,IAAI,OAAY,GAAQ,GAAS,GAAS;AACzC,cAAA,EAAY,IAAI,OAAO,GAAG,CAAC;AAAA,EAC5B;AAAA,EAEA,MAAM,YAA+B,SAA0C;AAC9E,WAAO,UAAA,EAAY,MAAM,YAAY,OAAO;AAAA,EAC7C;AAAA,EAEA,IAAI,aAAa;AAChB,WAAO,YAAY;AAAA,EACpB;AAAA,EAEA,QAAc;AACb,cAAA,EAAY,MAAA;AAAA,EACb;AAAA,EAEA,MAAS,IAAwC,YAA+B,SAA8C;AAC7H,WAAO,UAAA,EAAY,MAAM,IAAI,YAAY,OAAO;AAAA,EACjD;AAAA,EAEA,WAAW,SAA8B;AACxC,cAAA,EAAY,WAAW,OAAO;AAAA,EAC/B;AACD;AAEO,MAAM,SAAiB,IAAI,mBAAA;AAE3B,MAAM,aAAa,CAAIA,SAAgB,aAAyB;AACtE,SAAO,YAAY,IAAIA,SAAQ,QAAQ;AACxC;AAEO,MAAM,YAAY,MAAc;AACtC,QAAMA,UAAS,YAAY,SAAA;AAC3B,MAAI,CAACA,SAAQ;AACZ,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACrC;AACA,SAAOA;AACR;AAEO,MAAM,eAAe,MAA0B,YAAY,SAAA;"}
@@ -13,6 +13,7 @@ exports.createLogger = impl.createLogger;
13
13
  exports.LogLevels = levels.LogLevels;
14
14
  exports.getLogger = proxy.getLogger;
15
15
  exports.logger = proxy.logger;
16
+ exports.tryGetLogger = proxy.tryGetLogger;
16
17
  exports.withLogger = proxy.withLogger;
17
18
  exports.FingerCrossedLoggerHandler = FingerCrossedLoggerHandler.FingerCrossedLoggerHandler;
18
19
  exports.JsonStreamLoggerHandler = JsonStreamLoggerHandler.JsonStreamLoggerHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,6 +1,6 @@
1
1
  import { createLogger } from "./src/impl.js";
2
2
  import { LogLevels } from "./src/levels.js";
3
- import { getLogger, logger, withLogger } from "./src/proxy.js";
3
+ import { getLogger, logger, tryGetLogger, withLogger } from "./src/proxy.js";
4
4
  import { FingerCrossedLoggerHandler } from "./src/handlers/FingerCrossedLoggerHandler.js";
5
5
  import { JsonStreamLoggerHandler } from "./src/handlers/JsonStreamLoggerHandler.js";
6
6
  import { PrettyPrintLoggerHandler } from "./src/handlers/PrettyPrintLoggerHandler.js";
@@ -18,6 +18,7 @@ export {
18
18
  createLogger,
19
19
  getLogger,
20
20
  logger,
21
+ tryGetLogger,
21
22
  withLogger
22
23
  };
23
24
  //# sourceMappingURL=index.js.map
@@ -1,15 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const chalk = require("chalk");
4
3
  const node_util = require("node:util");
5
4
  const levels = require("../levels.cjs");
6
5
  var __defProp = Object.defineProperty;
7
6
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
7
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
+ const detectColorSupport = () => {
9
+ const forceColor = process.env.FORCE_COLOR;
10
+ if (forceColor !== void 0) {
11
+ return forceColor !== "0" && forceColor !== "false";
12
+ }
13
+ const stdout = process.stdout;
14
+ return stdout.isTTY === true && (typeof stdout.hasColors !== "function" || stdout.hasColors());
15
+ };
16
+ const createStyler = (colors) => (styles, text) => {
17
+ if (!colors) {
18
+ return text;
19
+ }
20
+ const list = typeof styles === "string" ? [styles] : styles;
21
+ return list.reduceRight((result, current) => node_util.styleText(current, result, { validateStream: false }), text);
22
+ };
9
23
  class PrettyPrintLoggerHandler {
10
24
  constructor(stream, options = {}) {
11
25
  this.stream = stream;
12
26
  __publicField(this, "options");
27
+ __publicField(this, "style", createStyler(detectColorSupport()));
13
28
  this.options = {
14
29
  logLevel: levels.LogLevels.debug,
15
30
  formatters: {},
@@ -37,12 +52,12 @@ class PrettyPrintLoggerHandler {
37
52
  const formattedValue = node_util.inspect(value, {
38
53
  depth: 5
39
54
  }).replaceAll(/\n/g, "\n" + indent);
40
- const formattedValue2 = this.options.formatters[key] ? this.options.formatters[key]({ value, key, formattedValue, chalk, attributes: allAttributes }) : formattedValue;
55
+ const formattedValue2 = this.options.formatters[key] ? this.options.formatters[key]({ value, key, formattedValue, style: this.style, attributes: allAttributes }) : formattedValue;
41
56
  if (formattedValue2 === void 0) {
42
57
  continue;
43
58
  }
44
59
  if (typeof formattedValue2 === "string") {
45
- this.stream.write(indent + chalk.dim(`${key}: ${formattedValue2}
60
+ this.stream.write(indent + this.style("dim", `${key}: ${formattedValue2}
46
61
  `));
47
62
  } else {
48
63
  this.stream.write(indent + formattedValue2.line + "\n");
@@ -57,20 +72,17 @@ class PrettyPrintLoggerHandler {
57
72
  if (!result) {
58
73
  return date;
59
74
  }
60
- return chalk.dim(result[1] + "T") + result[2] + chalk.dim("." + result[3] + "Z");
75
+ return this.style("dim", result[1] + "T") + result[2] + this.style("dim", "." + result[3] + "Z");
61
76
  }
62
77
  formatLevel(level) {
63
78
  const levelText = `${level.name}${" ".repeat(5 - level.name.length)}`;
64
- let color = chalk;
65
79
  if (level.value <= 10) {
66
- color = color.dim;
67
- } else if (level.value <= 20) ;
68
- else if (level.value <= 30) {
69
- color = color.yellowBright;
70
- } else {
71
- color = color.redBright;
80
+ return this.style("dim", levelText);
81
+ }
82
+ if (level.value <= 20) {
83
+ return levelText;
72
84
  }
73
- return color(levelText);
85
+ return this.style(level.value <= 30 ? "yellowBright" : "redBright", levelText);
74
86
  }
75
87
  close() {
76
88
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PrettyPrintLoggerHandler.cjs","sources":["../../../../../packages/logger/src/handlers/PrettyPrintLoggerHandler.ts"],"sourcesContent":["import chalk from 'chalk'\nimport { inspect } from 'node:util'\nimport { LogEntry, LoggerAttributes, LoggerHandler, LogLevel } from '../types.js'\nimport { LogLevels } from '../levels.js'\n\nexport interface PrettyPrintLoggerHandlerOptions {\n\tlogLevel: LogLevel\n\tformatters: {\n\t\t[key: string]: (\n\t\t\targs: { value: any; formattedValue: string; key: string; chalk: typeof chalk; attributes: LoggerAttributes },\n\t\t) => undefined | string | { line: string }\n\t}\n}\n\nexport class PrettyPrintLoggerHandler implements LoggerHandler {\n\tprivate readonly options: PrettyPrintLoggerHandlerOptions\n\n\tconstructor(\n\t\tprivate readonly stream: NodeJS.WritableStream,\n\t\toptions: Partial<PrettyPrintLoggerHandlerOptions> = {},\n\t) {\n\t\tthis.options = {\n\t\t\tlogLevel: LogLevels.debug,\n\t\t\tformatters: {},\n\t\t\t...options,\n\t\t}\n\t}\n\n\tgetMinLevel(): number {\n\t\treturn this.options.logLevel.value\n\t}\n\n\thandle(entry: LogEntry) {\n\t\tif (entry.level.value < this.options.logLevel.value) {\n\t\t\treturn\n\t\t}\n\t\tconst startLength = entry.isoTime.length + 7\n\n\t\tthis.stream.write(`${this.formatTime(entry.isoTime)} ${this.formatLevel(entry.level)} `)\n\n\t\tconst indent = ' '.repeat(startLength)\n\t\tthis.stream.write(`${entry.message.replaceAll(/\\n/g, '\\n' + indent)}\\n`)\n\t\tconst allAttributes = { ...entry.loggerAttributes, ...entry.ownAttributes }\n\t\tfor (const key in allAttributes) {\n\t\t\tconst value = allAttributes[key]\n\t\t\tif (typeof key !== 'string' || value === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst formattedValue = inspect(value, {\n\t\t\t\tdepth: 5,\n\t\t\t}).replaceAll(/\\n/g, '\\n' + indent)\n\t\t\tconst formattedValue2 = this.options.formatters[key]\n\t\t\t\t? (this.options.formatters[key]({ value, key, formattedValue, chalk, attributes: allAttributes }))\n\t\t\t\t: formattedValue\n\t\t\tif (formattedValue2 === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (typeof formattedValue2 === 'string') {\n\t\t\t\tthis.stream.write(indent + chalk.dim(`${key}: ${formattedValue2}\\n`))\n\t\t\t} else {\n\t\t\t\tthis.stream.write(indent + formattedValue2.line + '\\n')\n\t\t\t}\n\t\t}\n\t\tif (entry.error) {\n\t\t\tthis.stream.write(inspect(entry.error).replaceAll(/^/gm, indent) + '\\n')\n\t\t}\n\t}\n\n\tprivate formatTime(date: string): string {\n\t\tconst result = date.match(/^([0-9-]+)T([0-9:]+)\\.(\\d+)Z$/)\n\t\tif (!result) {\n\t\t\treturn date\n\t\t}\n\t\treturn chalk.dim(result[1] + 'T') + result[2] + chalk.dim('.' + result[3] + 'Z')\n\t}\n\n\tprivate formatLevel(level: LogLevel): string {\n\t\tconst levelText = `${level.name}${' '.repeat(5 - level.name.length)}`\n\t\tlet color = chalk\n\t\tif (level.value <= 10) {\n\t\t\tcolor = color.dim\n\t\t} else if (level.value <= 20) {\n\t\t\t// nothing\n\t\t} else if (level.value <= 30) {\n\t\t\tcolor = color.yellowBright\n\t\t} else {\n\t\t\tcolor = color.redBright\n\t\t}\n\t\treturn color(levelText)\n\t}\n\n\tclose(): void {\n\t}\n}\n"],"names":["LogLevels","inspect"],"mappings":";;;;;;;;AAcO,MAAM,yBAAkD;AAAA,EAG9D,YACkB,QACjB,UAAoD,IACnD;AAFgB,SAAA,SAAA;AAHlB,kBAAA,MAAiB,SAAA;AAMhB,SAAK,UAAU;AAAA,MACd,UAAUA,OAAAA,UAAU;AAAA,MACpB,YAAY,CAAA;AAAA,MACZ,GAAG;AAAA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;AAAA,IACxE;AAAA,EACD;AAAA,EAEQ,WAAW,MAAsB;AACxC,UAAM,SAAS,KAAK,MAAM,+BAA+B;AACzD,QAAI,CAAC,QAAQ;AACZ,aAAO;AAAA,IACR;AACA,WAAO,MAAM,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,OAAO,CAAC,IAAI,MAAM,IAAI,MAAM,OAAO,CAAC,IAAI,GAAG;AAAA,EAChF;AAAA,EAEQ,YAAY,OAAyB;AAC5C,UAAM,YAAY,GAAG,MAAM,IAAI,GAAG,IAAI,OAAO,IAAI,MAAM,KAAK,MAAM,CAAC;AACnE,QAAI,QAAQ;AACZ,QAAI,MAAM,SAAS,IAAI;AACtB,cAAQ,MAAM;AAAA,IACf,WAAW,MAAM,SAAS,GAAI;AAAA,aAEnB,MAAM,SAAS,IAAI;AAC7B,cAAQ,MAAM;AAAA,IACf,OAAO;AACN,cAAQ,MAAM;AAAA,IACf;AACA,WAAO,MAAM,SAAS;AAAA,EACvB;AAAA,EAEA,QAAc;AAAA,EACd;AACD;;"}
1
+ {"version":3,"file":"PrettyPrintLoggerHandler.cjs","sources":["../../../../../packages/logger/src/handlers/PrettyPrintLoggerHandler.ts"],"sourcesContent":["import { inspect, styleText } from 'node:util'\nimport { LogEntry, LoggerAttributes, LoggerHandler, LogLevel } from '../types.js'\nimport { LogLevels } from '../levels.js'\n\nexport type LogTextStyle = Exclude<Parameters<typeof styleText>[0], readonly unknown[]>\n\n/** Styles `text` with the given styles (outermost first); returns it unchanged when the terminal has no colors. */\nexport type LogTextStyler = (styles: LogTextStyle | readonly LogTextStyle[], text: string) => string\n\nexport interface PrettyPrintLoggerHandlerOptions {\n\tlogLevel: LogLevel\n\tformatters: {\n\t\t[key: string]: (\n\t\t\targs: { value: any; formattedValue: string; key: string; style: LogTextStyler; attributes: LoggerAttributes },\n\t\t) => undefined | string | { line: string }\n\t}\n}\n\n// Same detection as in @contember/cli-common colors.ts (logger cannot depend on it); keep them in sync.\nconst detectColorSupport = (): boolean => {\n\tconst forceColor = process.env.FORCE_COLOR\n\tif (forceColor !== undefined) {\n\t\treturn forceColor !== '0' && forceColor !== 'false'\n\t}\n\t// hasColors() honours NO_COLOR, NODE_DISABLE_COLORS and TERM=dumb; Bun's non-TTY stdout has no hasColors.\n\tconst stdout = process.stdout\n\treturn stdout.isTTY === true && (typeof stdout.hasColors !== 'function' || stdout.hasColors())\n}\n\nconst createStyler = (colors: boolean): LogTextStyler => (styles, text) => {\n\tif (!colors) {\n\t\treturn text\n\t}\n\tconst list: readonly LogTextStyle[] = typeof styles === 'string' ? [styles] : styles\n\t// validateStream is off because the decision is ours; Bun ignores the option and Node < 22.13 lacks it.\n\treturn list.reduceRight((result, current) => styleText(current, result, { validateStream: false }), text)\n}\n\nexport class PrettyPrintLoggerHandler implements LoggerHandler {\n\tprivate readonly options: PrettyPrintLoggerHandlerOptions\n\tprivate readonly style: LogTextStyler = createStyler(detectColorSupport())\n\n\tconstructor(\n\t\tprivate readonly stream: NodeJS.WritableStream,\n\t\toptions: Partial<PrettyPrintLoggerHandlerOptions> = {},\n\t) {\n\t\tthis.options = {\n\t\t\tlogLevel: LogLevels.debug,\n\t\t\tformatters: {},\n\t\t\t...options,\n\t\t}\n\t}\n\n\tgetMinLevel(): number {\n\t\treturn this.options.logLevel.value\n\t}\n\n\thandle(entry: LogEntry) {\n\t\tif (entry.level.value < this.options.logLevel.value) {\n\t\t\treturn\n\t\t}\n\t\tconst startLength = entry.isoTime.length + 7\n\n\t\tthis.stream.write(`${this.formatTime(entry.isoTime)} ${this.formatLevel(entry.level)} `)\n\n\t\tconst indent = ' '.repeat(startLength)\n\t\tthis.stream.write(`${entry.message.replaceAll(/\\n/g, '\\n' + indent)}\\n`)\n\t\tconst allAttributes = { ...entry.loggerAttributes, ...entry.ownAttributes }\n\t\tfor (const key in allAttributes) {\n\t\t\tconst value = allAttributes[key]\n\t\t\tif (typeof key !== 'string' || value === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst formattedValue = inspect(value, {\n\t\t\t\tdepth: 5,\n\t\t\t}).replaceAll(/\\n/g, '\\n' + indent)\n\t\t\tconst formattedValue2 = this.options.formatters[key]\n\t\t\t\t? (this.options.formatters[key]({ value, key, formattedValue, style: this.style, attributes: allAttributes }))\n\t\t\t\t: formattedValue\n\t\t\tif (formattedValue2 === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (typeof formattedValue2 === 'string') {\n\t\t\t\tthis.stream.write(indent + this.style('dim', `${key}: ${formattedValue2}\\n`))\n\t\t\t} else {\n\t\t\t\tthis.stream.write(indent + formattedValue2.line + '\\n')\n\t\t\t}\n\t\t}\n\t\tif (entry.error) {\n\t\t\tthis.stream.write(inspect(entry.error).replaceAll(/^/gm, indent) + '\\n')\n\t\t}\n\t}\n\n\tprivate formatTime(date: string): string {\n\t\tconst result = date.match(/^([0-9-]+)T([0-9:]+)\\.(\\d+)Z$/)\n\t\tif (!result) {\n\t\t\treturn date\n\t\t}\n\t\treturn this.style('dim', result[1] + 'T') + result[2] + this.style('dim', '.' + result[3] + 'Z')\n\t}\n\n\tprivate formatLevel(level: LogLevel): string {\n\t\tconst levelText = `${level.name}${' '.repeat(5 - level.name.length)}`\n\t\tif (level.value <= 10) {\n\t\t\treturn this.style('dim', levelText)\n\t\t}\n\t\tif (level.value <= 20) {\n\t\t\treturn levelText\n\t\t}\n\t\treturn this.style(level.value <= 30 ? 'yellowBright' : 'redBright', levelText)\n\t}\n\n\tclose(): void {\n\t}\n}\n"],"names":["styleText","LogLevels","inspect"],"mappings":";;;;;;;AAmBA,MAAM,qBAAqB,MAAe;AACzC,QAAM,aAAa,QAAQ,IAAI;AAC/B,MAAI,eAAe,QAAW;AAC7B,WAAO,eAAe,OAAO,eAAe;AAAA,EAC7C;AAEA,QAAM,SAAS,QAAQ;AACvB,SAAO,OAAO,UAAU,SAAS,OAAO,OAAO,cAAc,cAAc,OAAO;AACnF;AAEA,MAAM,eAAe,CAAC,WAAmC,CAAC,QAA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kBAAkB,KAAK,QAAQ,WAAW,GAAG,IAC/C,KAAK,QAAQ,WAAW,GAAG,EAAE,EAAE,OAAO,KAAK,gBAAgB,OAAO,KAAK,OAAO,YAAY,cAAA,CAAe,IAC1G;AACH,UAAI,oBAAoB,QAAW;AAClC;AAAA,MACD;AACA,UAAI,OAAO,oBAAoB,UAAU;AACxC,aAAK,OAAO,MAAM,SAAS,KAAK,MAAM,OAAO,GAAG,GAAG,KAAK,eAAe;AAAA,CAAI,CAAC;AAAA,MAC7E,OAAO;AACN,aAAK,OAAO,MAAM,SAAS,gBAAgB,OAAO,IAAI;AAAA,MACvD;AAAA,IACD;AACA,QAAI,MAAM,OAAO;AAChB,WAAK,OAAO,MAAMA,UAAAA,QAAQ,MAAM,KAAK,EAAE,WAAW,OAAO,MAAM,IAAI,IAAI;AAAA,IACxE;AAAA,EACD;AAAA,EAEQ,WAAW,MAAsB;AACxC,UAAM,SAAS,KAAK,MAAM,+BAA+B;AACzD,QAAI,CAAC,QAAQ;AACZ,aAAO;AAAA,IACR;AACA,WAAO,KAAK,MAAM,OAAO,OAAO,CAAC,IAAI,GAAG,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,OAAO,MAAM,OAAO,CAAC,IAAI,GAAG;AAAA,EAChG;AAAA,EAEQ,YAAY,OAAyB;AAC5C,UAAM,YAAY,GAAG,MAAM,IAAI,GAAG,IAAI,OAAO,IAAI,MAAM,KAAK,MAAM,CAAC;AACnE,QAAI,MAAM,SAAS,IAAI;AACtB,aAAO,KAAK,MAAM,OAAO,SAAS;AAAA,IACnC;AACA,QAAI,MAAM,SAAS,IAAI;AACtB,aAAO;AAAA,IACR;AACA,WAAO,KAAK,MAAM,MAAM,SAAS,KAAK,iBAAiB,aAAa,SAAS;AAAA,EAC9E;AAAA,EAEA,QAAc;AAAA,EACd;AACD;;"}
@@ -1,13 +1,28 @@
1
- import chalk from "chalk";
2
- import { inspect } from "node:util";
1
+ import { inspect, styleText } from "node:util";
3
2
  import { LogLevels } from "../levels.js";
4
3
  var __defProp = Object.defineProperty;
5
4
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
5
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+ const detectColorSupport = () => {
7
+ const forceColor = process.env.FORCE_COLOR;
8
+ if (forceColor !== void 0) {
9
+ return forceColor !== "0" && forceColor !== "false";
10
+ }
11
+ const stdout = process.stdout;
12
+ return stdout.isTTY === true && (typeof stdout.hasColors !== "function" || stdout.hasColors());
13
+ };
14
+ const createStyler = (colors) => (styles, text) => {
15
+ if (!colors) {
16
+ return text;
17
+ }
18
+ const list = typeof styles === "string" ? [styles] : styles;
19
+ return list.reduceRight((result, current) => styleText(current, result, { validateStream: false }), text);
20
+ };
7
21
  class PrettyPrintLoggerHandler {
8
22
  constructor(stream, options = {}) {
9
23
  this.stream = stream;
10
24
  __publicField(this, "options");
25
+ __publicField(this, "style", createStyler(detectColorSupport()));
11
26
  this.options = {
12
27
  logLevel: LogLevels.debug,
13
28
  formatters: {},
@@ -35,12 +50,12 @@ class PrettyPrintLoggerHandler {
35
50
  const formattedValue = inspect(value, {
36
51
  depth: 5
37
52
  }).replaceAll(/\n/g, "\n" + indent);
38
- const formattedValue2 = this.options.formatters[key] ? this.options.formatters[key]({ value, key, formattedValue, chalk, attributes: allAttributes }) : formattedValue;
53
+ const formattedValue2 = this.options.formatters[key] ? this.options.formatters[key]({ value, key, formattedValue, style: this.style, attributes: allAttributes }) : formattedValue;
39
54
  if (formattedValue2 === void 0) {
40
55
  continue;
41
56
  }
42
57
  if (typeof formattedValue2 === "string") {
43
- this.stream.write(indent + chalk.dim(`${key}: ${formattedValue2}
58
+ this.stream.write(indent + this.style("dim", `${key}: ${formattedValue2}
44
59
  `));
45
60
  } else {
46
61
  this.stream.write(indent + formattedValue2.line + "\n");
@@ -55,20 +70,17 @@ class PrettyPrintLoggerHandler {
55
70
  if (!result) {
56
71
  return date;
57
72
  }
58
- return chalk.dim(result[1] + "T") + result[2] + chalk.dim("." + result[3] + "Z");
73
+ return this.style("dim", result[1] + "T") + result[2] + this.style("dim", "." + result[3] + "Z");
59
74
  }
60
75
  formatLevel(level) {
61
76
  const levelText = `${level.name}${" ".repeat(5 - level.name.length)}`;
62
- let color = chalk;
63
77
  if (level.value <= 10) {
64
- color = color.dim;
65
- } else if (level.value <= 20) ;
66
- else if (level.value <= 30) {
67
- color = color.yellowBright;
68
- } else {
69
- color = color.redBright;
78
+ return this.style("dim", levelText);
79
+ }
80
+ if (level.value <= 20) {
81
+ return levelText;
70
82
  }
71
- return color(levelText);
83
+ return this.style(level.value <= 30 ? "yellowBright" : "redBright", levelText);
72
84
  }
73
85
  close() {
74
86
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PrettyPrintLoggerHandler.js","sources":["../../../../../packages/logger/src/handlers/PrettyPrintLoggerHandler.ts"],"sourcesContent":["import chalk from 'chalk'\nimport { inspect } from 'node:util'\nimport { LogEntry, LoggerAttributes, LoggerHandler, LogLevel } from '../types.js'\nimport { LogLevels } from '../levels.js'\n\nexport interface PrettyPrintLoggerHandlerOptions {\n\tlogLevel: LogLevel\n\tformatters: {\n\t\t[key: string]: (\n\t\t\targs: { value: any; formattedValue: string; key: string; chalk: typeof chalk; attributes: LoggerAttributes },\n\t\t) => undefined | string | { line: string }\n\t}\n}\n\nexport class PrettyPrintLoggerHandler implements LoggerHandler {\n\tprivate readonly options: PrettyPrintLoggerHandlerOptions\n\n\tconstructor(\n\t\tprivate readonly stream: NodeJS.WritableStream,\n\t\toptions: Partial<PrettyPrintLoggerHandlerOptions> = {},\n\t) {\n\t\tthis.options = {\n\t\t\tlogLevel: LogLevels.debug,\n\t\t\tformatters: {},\n\t\t\t...options,\n\t\t}\n\t}\n\n\tgetMinLevel(): number {\n\t\treturn this.options.logLevel.value\n\t}\n\n\thandle(entry: LogEntry) {\n\t\tif (entry.level.value < this.options.logLevel.value) {\n\t\t\treturn\n\t\t}\n\t\tconst startLength = entry.isoTime.length + 7\n\n\t\tthis.stream.write(`${this.formatTime(entry.isoTime)} ${this.formatLevel(entry.level)} `)\n\n\t\tconst indent = ' '.repeat(startLength)\n\t\tthis.stream.write(`${entry.message.replaceAll(/\\n/g, '\\n' + indent)}\\n`)\n\t\tconst allAttributes = { ...entry.loggerAttributes, ...entry.ownAttributes }\n\t\tfor (const key in allAttributes) {\n\t\t\tconst value = allAttributes[key]\n\t\t\tif (typeof key !== 'string' || value === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst formattedValue = inspect(value, {\n\t\t\t\tdepth: 5,\n\t\t\t}).replaceAll(/\\n/g, '\\n' + indent)\n\t\t\tconst formattedValue2 = this.options.formatters[key]\n\t\t\t\t? (this.options.formatters[key]({ value, key, formattedValue, chalk, attributes: allAttributes }))\n\t\t\t\t: formattedValue\n\t\t\tif (formattedValue2 === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (typeof formattedValue2 === 'string') {\n\t\t\t\tthis.stream.write(indent + chalk.dim(`${key}: ${formattedValue2}\\n`))\n\t\t\t} else {\n\t\t\t\tthis.stream.write(indent + formattedValue2.line + '\\n')\n\t\t\t}\n\t\t}\n\t\tif (entry.error) {\n\t\t\tthis.stream.write(inspect(entry.error).replaceAll(/^/gm, indent) + '\\n')\n\t\t}\n\t}\n\n\tprivate formatTime(date: string): string {\n\t\tconst result = date.match(/^([0-9-]+)T([0-9:]+)\\.(\\d+)Z$/)\n\t\tif (!result) {\n\t\t\treturn date\n\t\t}\n\t\treturn chalk.dim(result[1] + 'T') + result[2] + chalk.dim('.' + result[3] + 'Z')\n\t}\n\n\tprivate formatLevel(level: LogLevel): string {\n\t\tconst levelText = `${level.name}${' '.repeat(5 - level.name.length)}`\n\t\tlet color = chalk\n\t\tif (level.value <= 10) {\n\t\t\tcolor = color.dim\n\t\t} else if (level.value <= 20) {\n\t\t\t// nothing\n\t\t} else if (level.value <= 30) {\n\t\t\tcolor = color.yellowBright\n\t\t} else {\n\t\t\tcolor = color.redBright\n\t\t}\n\t\treturn color(levelText)\n\t}\n\n\tclose(): void {\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAcO,MAAM,yBAAkD;AAAA,EAG9D,YACkB,QACjB,UAAoD,IACnD;AAFgB,SAAA,SAAA;AAHlB,kBAAA,MAAiB,SAAA;AAMhB,SAAK,UAAU;AAAA,MACd,UAAU,UAAU;AAAA,MACpB,YAAY,CAAA;AAAA,MACZ,GAAG;AAAA,IAAA;AAAA,EAEL;AAAA,EAEA,cAAsB;AACrB,WAAO,KAAK,QAAQ,SAAS;AAAA,EAC9B;AAAA,EAEA,OAAO,OAAiB;AACvB,QAAI,MAAM,MAAM,QAAQ,KAAK,QAAQ,SAAS,OAAO;AACpD;AAAA,IACD;AACA,UAAM,cAAc,MAAM,QAAQ,SAAS;AAE3C,SAAK,OAAO,MAAM,GAAG,KAAK,WAAW,MAAM,OAAO,CAAC,IAAI,KAAK,YAAY,MAAM,KAAK,CAAC,GAAG;AAEvF,UAAM,SAAS,IAAI,OAAO,WAAW;AACrC,SAAK,OAAO,MAAM,GAAG,MAAM,QAAQ,WAAW,OAAO,OAAO,MAAM,CAAC;AAAA,CAAI;AACvE,UAAM,gBAAgB,EAAE,GAAG,MAAM,kBAAkB,GAAG,MAAM,cAAA;AAC5D,eAAW,OAAO,eAAe;AAChC,YAAM,QAAQ,cAAc,GAAG;AAC/B,UAAI,OAAO,QAAQ,YAAY,UAAU,QAAW;AACnD;AAAA,MACD;AACA,YAAM,iBAAiB,QAAQ,OAAO;AAAA,QACrC,OAAO;AAAA,MAAA,CACP,EAAE,WAAW,OAAO,OAAO,MAAM;AAClC,YAAM,kBAAkB,KAAK,QAAQ,WAAW,GAAG,IAC/C,KAAK,QAAQ,WAAW,GAAG,EAAE,EAAE,OAAO,KAAK,gBAAgB,OAAO,YAAY,cAAA,CAAe,IAC9F;AACH,UAAI,oBAAoB,QAAW;AAClC;AAAA,MACD;AACA,UAAI,OAAO,oBAAoB,UAAU;AACxC,aAAK,OAAO,MAAM,SAAS,MAAM,IAAI,GAAG,GAAG,KAAK,eAAe;AAAA,CAAI,CAAC;AAAA,MACrE,OAAO;AACN,aAAK,OAAO,MAAM,SAAS,gBAAgB,OAAO,IAAI;AAAA,MACvD;AAAA,IACD;AACA,QAAI,MAAM,OAAO;AAChB,WAAK,OAAO,MAAM,QAAQ,MAAM,KAAK,EAAE,WAAW,OAAO,MAAM,IAAI,IAAI;AAAA,IACxE;AAAA,EACD;AAAA,EAEQ,WAAW,MAAsB;AACxC,UAAM,SAAS,KAAK,MAAM,+BAA+B;AACzD,QAAI,CAAC,QAAQ;AACZ,aAAO;AAAA,IACR;AACA,WAAO,MAAM,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,OAAO,CAAC,IAAI,MAAM,IAAI,MAAM,OAAO,CAAC,IAAI,GAAG;AAAA,EAChF;AAAA,EAEQ,YAAY,OAAyB;AAC5C,UAAM,YAAY,GAAG,MAAM,IAAI,GAAG,IAAI,OAAO,IAAI,MAAM,KAAK,MAAM,CAAC;AACnE,QAAI,QAAQ;AACZ,QAAI,MAAM,SAAS,IAAI;AACtB,cAAQ,MAAM;AAAA,IACf,WAAW,MAAM,SAAS,GAAI;AAAA,aAEnB,MAAM,SAAS,IAAI;AAC7B,cAAQ,MAAM;AAAA,IACf,OAAO;AACN,cAAQ,MAAM;AAAA,IACf;AACA,WAAO,MAAM,SAAS;AAAA,EACvB;AAAA,EAEA,QAAc;AAAA,EACd;AACD;"}
1
+ {"version":3,"file":"PrettyPrintLoggerHandler.js","sources":["../../../../../packages/logger/src/handlers/PrettyPrintLoggerHandler.ts"],"sourcesContent":["import { inspect, styleText } from 'node:util'\nimport { LogEntry, LoggerAttributes, LoggerHandler, LogLevel } from '../types.js'\nimport { LogLevels } from '../levels.js'\n\nexport type LogTextStyle = Exclude<Parameters<typeof styleText>[0], readonly unknown[]>\n\n/** Styles `text` with the given styles (outermost first); returns it unchanged when the terminal has no colors. */\nexport type LogTextStyler = (styles: LogTextStyle | readonly LogTextStyle[], text: string) => string\n\nexport interface PrettyPrintLoggerHandlerOptions {\n\tlogLevel: LogLevel\n\tformatters: {\n\t\t[key: string]: (\n\t\t\targs: { value: any; formattedValue: string; key: string; style: LogTextStyler; attributes: LoggerAttributes },\n\t\t) => undefined | string | { line: string }\n\t}\n}\n\n// Same detection as in @contember/cli-common colors.ts (logger cannot depend on it); keep them in sync.\nconst detectColorSupport = (): boolean => {\n\tconst forceColor = process.env.FORCE_COLOR\n\tif (forceColor !== undefined) {\n\t\treturn forceColor !== '0' && forceColor !== 'false'\n\t}\n\t// hasColors() honours NO_COLOR, NODE_DISABLE_COLORS and TERM=dumb; Bun's non-TTY stdout has no hasColors.\n\tconst stdout = process.stdout\n\treturn stdout.isTTY === true && (typeof stdout.hasColors !== 'function' || stdout.hasColors())\n}\n\nconst createStyler = (colors: boolean): LogTextStyler => (styles, text) => {\n\tif (!colors) {\n\t\treturn text\n\t}\n\tconst list: readonly LogTextStyle[] = typeof styles === 'string' ? [styles] : styles\n\t// validateStream is off because the decision is ours; Bun ignores the option and Node < 22.13 lacks it.\n\treturn list.reduceRight((result, current) => styleText(current, result, { validateStream: false }), text)\n}\n\nexport class PrettyPrintLoggerHandler implements LoggerHandler {\n\tprivate readonly options: PrettyPrintLoggerHandlerOptions\n\tprivate readonly style: LogTextStyler = createStyler(detectColorSupport())\n\n\tconstructor(\n\t\tprivate readonly stream: NodeJS.WritableStream,\n\t\toptions: Partial<PrettyPrintLoggerHandlerOptions> = {},\n\t) {\n\t\tthis.options = {\n\t\t\tlogLevel: LogLevels.debug,\n\t\t\tformatters: {},\n\t\t\t...options,\n\t\t}\n\t}\n\n\tgetMinLevel(): number {\n\t\treturn this.options.logLevel.value\n\t}\n\n\thandle(entry: LogEntry) {\n\t\tif (entry.level.value < this.options.logLevel.value) {\n\t\t\treturn\n\t\t}\n\t\tconst startLength = entry.isoTime.length + 7\n\n\t\tthis.stream.write(`${this.formatTime(entry.isoTime)} ${this.formatLevel(entry.level)} `)\n\n\t\tconst indent = ' '.repeat(startLength)\n\t\tthis.stream.write(`${entry.message.replaceAll(/\\n/g, '\\n' + indent)}\\n`)\n\t\tconst allAttributes = { ...entry.loggerAttributes, ...entry.ownAttributes }\n\t\tfor (const key in allAttributes) {\n\t\t\tconst value = allAttributes[key]\n\t\t\tif (typeof key !== 'string' || value === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst formattedValue = inspect(value, {\n\t\t\t\tdepth: 5,\n\t\t\t}).replaceAll(/\\n/g, '\\n' + indent)\n\t\t\tconst formattedValue2 = this.options.formatters[key]\n\t\t\t\t? (this.options.formatters[key]({ value, key, formattedValue, style: this.style, attributes: allAttributes }))\n\t\t\t\t: formattedValue\n\t\t\tif (formattedValue2 === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (typeof formattedValue2 === 'string') {\n\t\t\t\tthis.stream.write(indent + this.style('dim', `${key}: ${formattedValue2}\\n`))\n\t\t\t} else {\n\t\t\t\tthis.stream.write(indent + formattedValue2.line + '\\n')\n\t\t\t}\n\t\t}\n\t\tif (entry.error) {\n\t\t\tthis.stream.write(inspect(entry.error).replaceAll(/^/gm, indent) + '\\n')\n\t\t}\n\t}\n\n\tprivate formatTime(date: string): string {\n\t\tconst result = date.match(/^([0-9-]+)T([0-9:]+)\\.(\\d+)Z$/)\n\t\tif (!result) {\n\t\t\treturn date\n\t\t}\n\t\treturn this.style('dim', result[1] + 'T') + result[2] + this.style('dim', '.' + result[3] + 'Z')\n\t}\n\n\tprivate formatLevel(level: LogLevel): string {\n\t\tconst levelText = `${level.name}${' '.repeat(5 - level.name.length)}`\n\t\tif (level.value <= 10) {\n\t\t\treturn this.style('dim', levelText)\n\t\t}\n\t\tif (level.value <= 20) {\n\t\t\treturn levelText\n\t\t}\n\t\treturn this.style(level.value <= 30 ? 'yellow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KAAK,MAAM,OAAO,SAAS;AAAA,IACnC;AACA,QAAI,MAAM,SAAS,IAAI;AACtB,aAAO;AAAA,IACR;AACA,WAAO,KAAK,MAAM,MAAM,SAAS,KAAK,iBAAiB,aAAa,SAAS;AAAA,EAC9E;AAAA,EAEA,QAAc;AAAA,EACd;AACD;"}
@@ -48,7 +48,9 @@ const getLogger = () => {
48
48
  }
49
49
  return logger2;
50
50
  };
51
+ const tryGetLogger = () => loggerStore.getStore();
51
52
  exports.getLogger = getLogger;
52
53
  exports.logger = logger;
54
+ exports.tryGetLogger = tryGetLogger;
53
55
  exports.withLogger = withLogger;
54
56
  //# sourceMappingURL=proxy.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.cjs","sources":["../../../../packages/logger/src/proxy.ts"],"sourcesContent":["import { Logger, LoggerAttributes, LoggerHandler, LoggerOptions } from './types.js'\nimport { AsyncLocalStorage } from 'node:async_hooks'\n\nconst loggerStore = new AsyncLocalStorage<Logger>()\n\nclass CurrentLoggerProxy implements Logger {\n\tcrit(a: any, b?: any, c?: any) {\n\t\tgetLogger().crit(a, b)\n\t}\n\n\terror(a: any, b?: any, c?: any) {\n\t\tgetLogger().error(a, b)\n\t}\n\n\twarn(a: any, b?: any, c?: any) {\n\t\tgetLogger().warn(a, b)\n\t}\n\n\tinfo(a: any, b?: any, c?: any) {\n\t\tgetLogger().info(a, b)\n\t}\n\n\tdebug(a: any, b?: any, c?: any) {\n\t\tgetLogger().debug(a, b)\n\t}\n\n\tlog(level: any, a: any, b?: any, c?: any) {\n\t\tgetLogger().log(level, a, b)\n\t}\n\n\tchild(attributes?: LoggerAttributes, options?: Partial<LoggerOptions>): Logger {\n\t\treturn getLogger().child(attributes, options)\n\t}\n\n\tget attributes() {\n\t\treturn getLogger().attributes\n\t}\n\n\tclose(): void {\n\t\tgetLogger().close()\n\t}\n\n\tscope<T>(cb: (logger: Logger) => Promise<T> | T, attributes?: LoggerAttributes, options?: Partial<LoggerOptions>): Promise<T> {\n\t\treturn getLogger().scope(cb, attributes, options)\n\t}\n\n\taddHandler(handler: LoggerHandler): void {\n\t\tgetLogger().addHandler(handler)\n\t}\n}\n\nexport const logger: Logger = new CurrentLoggerProxy()\n\nexport const withLogger = <R>(logger: Logger, callback: () => R): R => {\n\treturn loggerStore.run(logger, callback)\n}\n\nexport const getLogger = (): Logger => {\n\tconst logger = loggerStore.getStore()\n\tif (!logger) {\n\t\tthrow new Error('Logger was not set')\n\t}\n\treturn logger\n}\n"],"names":["AsyncLocalStorage","logger"],"mappings":";;;AAGA,MAAM,cAAc,IAAIA,iBAAAA,kBAAA;AAExB,MAAM,mBAAqC;AAAA,EAC1C,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,MAAM,GAAQ,GAAS,GAAS;AAC/B,gBAAY,MAAM,GAAG,CAAC;AAAA,EACvB;AAAA,EAEA,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,MAAM,GAAQ,GAAS,GAAS;AAC/B,gBAAY,MAAM,GAAG,CAAC;AAAA,EACvB;AAAA,EAEA,IAAI,OAAY,GAAQ,GAAS,GAAS;AACzC,cAAA,EAAY,IAAI,OAAO,GAAG,CAAC;AAAA,EAC5B;AAAA,EAEA,MAAM,YAA+B,SAA0C;AAC9E,WAAO,UAAA,EAAY,MAAM,YAAY,OAAO;AAAA,EAC7C;AAAA,EAEA,IAAI,aAAa;AAChB,WAAO,YAAY;AAAA,EACpB;AAAA,EAEA,QAAc;AACb,cAAA,EAAY,MAAA;AAAA,EACb;AAAA,EAEA,MAAS,IAAwC,YAA+B,SAA8C;AAC7H,WAAO,UAAA,EAAY,MAAM,IAAI,YAAY,OAAO;AAAA,EACjD;AAAA,EAEA,WAAW,SAA8B;AACxC,cAAA,EAAY,WAAW,OAAO;AAAA,EAC/B;AACD;AAEO,MAAM,SAAiB,IAAI,mBAAA;AAE3B,MAAM,aAAa,CAAIC,SAAgB,aAAyB;AACtE,SAAO,YAAY,IAAIA,SAAQ,QAAQ;AACxC;AAEO,MAAM,YAAY,MAAc;AACtC,QAAMA,UAAS,YAAY,SAAA;AAC3B,MAAI,CAACA,SAAQ;AACZ,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACrC;AACA,SAAOA;AACR;;;;"}
1
+ {"version":3,"file":"proxy.cjs","sources":["../../../../packages/logger/src/proxy.ts"],"sourcesContent":["import { Logger, LoggerAttributes, LoggerHandler, LoggerOptions } from './types.js'\nimport { AsyncLocalStorage } from 'node:async_hooks'\n\nconst loggerStore = new AsyncLocalStorage<Logger>()\n\nclass CurrentLoggerProxy implements Logger {\n\tcrit(a: any, b?: any, c?: any) {\n\t\tgetLogger().crit(a, b)\n\t}\n\n\terror(a: any, b?: any, c?: any) {\n\t\tgetLogger().error(a, b)\n\t}\n\n\twarn(a: any, b?: any, c?: any) {\n\t\tgetLogger().warn(a, b)\n\t}\n\n\tinfo(a: any, b?: any, c?: any) {\n\t\tgetLogger().info(a, b)\n\t}\n\n\tdebug(a: any, b?: any, c?: any) {\n\t\tgetLogger().debug(a, b)\n\t}\n\n\tlog(level: any, a: any, b?: any, c?: any) {\n\t\tgetLogger().log(level, a, b)\n\t}\n\n\tchild(attributes?: LoggerAttributes, options?: Partial<LoggerOptions>): Logger {\n\t\treturn getLogger().child(attributes, options)\n\t}\n\n\tget attributes() {\n\t\treturn getLogger().attributes\n\t}\n\n\tclose(): void {\n\t\tgetLogger().close()\n\t}\n\n\tscope<T>(cb: (logger: Logger) => Promise<T> | T, attributes?: LoggerAttributes, options?: Partial<LoggerOptions>): Promise<T> {\n\t\treturn getLogger().scope(cb, attributes, options)\n\t}\n\n\taddHandler(handler: LoggerHandler): void {\n\t\tgetLogger().addHandler(handler)\n\t}\n}\n\nexport const logger: Logger = new CurrentLoggerProxy()\n\nexport const withLogger = <R>(logger: Logger, callback: () => R): R => {\n\treturn loggerStore.run(logger, callback)\n}\n\nexport const getLogger = (): Logger => {\n\tconst logger = loggerStore.getStore()\n\tif (!logger) {\n\t\tthrow new Error('Logger was not set')\n\t}\n\treturn logger\n}\n\nexport const tryGetLogger = (): Logger | undefined => loggerStore.getStore()\n"],"names":["AsyncLocalStorage","logger"],"mappings":";;;AAGA,MAAM,cAAc,IAAIA,iBAAAA,kBAAA;AAExB,MAAM,mBAAqC;AAAA,EAC1C,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,MAAM,GAAQ,GAAS,GAAS;AAC/B,gBAAY,MAAM,GAAG,CAAC;AAAA,EACvB;AAAA,EAEA,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,MAAM,GAAQ,GAAS,GAAS;AAC/B,gBAAY,MAAM,GAAG,CAAC;AAAA,EACvB;AAAA,EAEA,IAAI,OAAY,GAAQ,GAAS,GAAS;AACzC,cAAA,EAAY,IAAI,OAAO,GAAG,CAAC;AAAA,EAC5B;AAAA,EAEA,MAAM,YAA+B,SAA0C;AAC9E,WAAO,UAAA,EAAY,MAAM,YAAY,OAAO;AAAA,EAC7C;AAAA,EAEA,IAAI,aAAa;AAChB,WAAO,YAAY;AAAA,EACpB;AAAA,EAEA,QAAc;AACb,cAAA,EAAY,MAAA;AAAA,EACb;AAAA,EAEA,MAAS,IAAwC,YAA+B,SAA8C;AAC7H,WAAO,UAAA,EAAY,MAAM,IAAI,YAAY,OAAO;AAAA,EACjD;AAAA,EAEA,WAAW,SAA8B;AACxC,cAAA,EAAY,WAAW,OAAO;AAAA,EAC/B;AACD;AAEO,MAAM,SAAiB,IAAI,mBAAA;AAE3B,MAAM,aAAa,CAAIC,SAAgB,aAAyB;AACtE,SAAO,YAAY,IAAIA,SAAQ,QAAQ;AACxC;AAEO,MAAM,YAAY,MAAc;AACtC,QAAMA,UAAS,YAAY,SAAA;AAC3B,MAAI,CAACA,SAAQ;AACZ,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACrC;AACA,SAAOA;AACR;AAEO,MAAM,eAAe,MAA0B,YAAY,SAAA;;;;;"}
@@ -46,9 +46,11 @@ const getLogger = () => {
46
46
  }
47
47
  return logger2;
48
48
  };
49
+ const tryGetLogger = () => loggerStore.getStore();
49
50
  export {
50
51
  getLogger,
51
52
  logger,
53
+ tryGetLogger,
52
54
  withLogger
53
55
  };
54
56
  //# sourceMappingURL=proxy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.js","sources":["../../../../packages/logger/src/proxy.ts"],"sourcesContent":["import { Logger, LoggerAttributes, LoggerHandler, LoggerOptions } from './types.js'\nimport { AsyncLocalStorage } from 'node:async_hooks'\n\nconst loggerStore = new AsyncLocalStorage<Logger>()\n\nclass CurrentLoggerProxy implements Logger {\n\tcrit(a: any, b?: any, c?: any) {\n\t\tgetLogger().crit(a, b)\n\t}\n\n\terror(a: any, b?: any, c?: any) {\n\t\tgetLogger().error(a, b)\n\t}\n\n\twarn(a: any, b?: any, c?: any) {\n\t\tgetLogger().warn(a, b)\n\t}\n\n\tinfo(a: any, b?: any, c?: any) {\n\t\tgetLogger().info(a, b)\n\t}\n\n\tdebug(a: any, b?: any, c?: any) {\n\t\tgetLogger().debug(a, b)\n\t}\n\n\tlog(level: any, a: any, b?: any, c?: any) {\n\t\tgetLogger().log(level, a, b)\n\t}\n\n\tchild(attributes?: LoggerAttributes, options?: Partial<LoggerOptions>): Logger {\n\t\treturn getLogger().child(attributes, options)\n\t}\n\n\tget attributes() {\n\t\treturn getLogger().attributes\n\t}\n\n\tclose(): void {\n\t\tgetLogger().close()\n\t}\n\n\tscope<T>(cb: (logger: Logger) => Promise<T> | T, attributes?: LoggerAttributes, options?: Partial<LoggerOptions>): Promise<T> {\n\t\treturn getLogger().scope(cb, attributes, options)\n\t}\n\n\taddHandler(handler: LoggerHandler): void {\n\t\tgetLogger().addHandler(handler)\n\t}\n}\n\nexport const logger: Logger = new CurrentLoggerProxy()\n\nexport const withLogger = <R>(logger: Logger, callback: () => R): R => {\n\treturn loggerStore.run(logger, callback)\n}\n\nexport const getLogger = (): Logger => {\n\tconst logger = loggerStore.getStore()\n\tif (!logger) {\n\t\tthrow new Error('Logger was not set')\n\t}\n\treturn logger\n}\n"],"names":["logger"],"mappings":";AAGA,MAAM,cAAc,IAAI,kBAAA;AAExB,MAAM,mBAAqC;AAAA,EAC1C,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,MAAM,GAAQ,GAAS,GAAS;AAC/B,gBAAY,MAAM,GAAG,CAAC;AAAA,EACvB;AAAA,EAEA,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,MAAM,GAAQ,GAAS,GAAS;AAC/B,gBAAY,MAAM,GAAG,CAAC;AAAA,EACvB;AAAA,EAEA,IAAI,OAAY,GAAQ,GAAS,GAAS;AACzC,cAAA,EAAY,IAAI,OAAO,GAAG,CAAC;AAAA,EAC5B;AAAA,EAEA,MAAM,YAA+B,SAA0C;AAC9E,WAAO,UAAA,EAAY,MAAM,YAAY,OAAO;AAAA,EAC7C;AAAA,EAEA,IAAI,aAAa;AAChB,WAAO,YAAY;AAAA,EACpB;AAAA,EAEA,QAAc;AACb,cAAA,EAAY,MAAA;AAAA,EACb;AAAA,EAEA,MAAS,IAAwC,YAA+B,SAA8C;AAC7H,WAAO,UAAA,EAAY,MAAM,IAAI,YAAY,OAAO;AAAA,EACjD;AAAA,EAEA,WAAW,SAA8B;AACxC,cAAA,EAAY,WAAW,OAAO;AAAA,EAC/B;AACD;AAEO,MAAM,SAAiB,IAAI,mBAAA;AAE3B,MAAM,aAAa,CAAIA,SAAgB,aAAyB;AACtE,SAAO,YAAY,IAAIA,SAAQ,QAAQ;AACxC;AAEO,MAAM,YAAY,MAAc;AACtC,QAAMA,UAAS,YAAY,SAAA;AAC3B,MAAI,CAACA,SAAQ;AACZ,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACrC;AACA,SAAOA;AACR;"}
1
+ {"version":3,"file":"proxy.js","sources":["../../../../packages/logger/src/proxy.ts"],"sourcesContent":["import { Logger, LoggerAttributes, LoggerHandler, LoggerOptions } from './types.js'\nimport { AsyncLocalStorage } from 'node:async_hooks'\n\nconst loggerStore = new AsyncLocalStorage<Logger>()\n\nclass CurrentLoggerProxy implements Logger {\n\tcrit(a: any, b?: any, c?: any) {\n\t\tgetLogger().crit(a, b)\n\t}\n\n\terror(a: any, b?: any, c?: any) {\n\t\tgetLogger().error(a, b)\n\t}\n\n\twarn(a: any, b?: any, c?: any) {\n\t\tgetLogger().warn(a, b)\n\t}\n\n\tinfo(a: any, b?: any, c?: any) {\n\t\tgetLogger().info(a, b)\n\t}\n\n\tdebug(a: any, b?: any, c?: any) {\n\t\tgetLogger().debug(a, b)\n\t}\n\n\tlog(level: any, a: any, b?: any, c?: any) {\n\t\tgetLogger().log(level, a, b)\n\t}\n\n\tchild(attributes?: LoggerAttributes, options?: Partial<LoggerOptions>): Logger {\n\t\treturn getLogger().child(attributes, options)\n\t}\n\n\tget attributes() {\n\t\treturn getLogger().attributes\n\t}\n\n\tclose(): void {\n\t\tgetLogger().close()\n\t}\n\n\tscope<T>(cb: (logger: Logger) => Promise<T> | T, attributes?: LoggerAttributes, options?: Partial<LoggerOptions>): Promise<T> {\n\t\treturn getLogger().scope(cb, attributes, options)\n\t}\n\n\taddHandler(handler: LoggerHandler): void {\n\t\tgetLogger().addHandler(handler)\n\t}\n}\n\nexport const logger: Logger = new CurrentLoggerProxy()\n\nexport const withLogger = <R>(logger: Logger, callback: () => R): R => {\n\treturn loggerStore.run(logger, callback)\n}\n\nexport const getLogger = (): Logger => {\n\tconst logger = loggerStore.getStore()\n\tif (!logger) {\n\t\tthrow new Error('Logger was not set')\n\t}\n\treturn logger\n}\n\nexport const tryGetLogger = (): Logger | undefined => loggerStore.getStore()\n"],"names":["logger"],"mappings":";AAGA,MAAM,cAAc,IAAI,kBAAA;AAExB,MAAM,mBAAqC;AAAA,EAC1C,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,MAAM,GAAQ,GAAS,GAAS;AAC/B,gBAAY,MAAM,GAAG,CAAC;AAAA,EACvB;AAAA,EAEA,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,KAAK,GAAQ,GAAS,GAAS;AAC9B,gBAAY,KAAK,GAAG,CAAC;AAAA,EACtB;AAAA,EAEA,MAAM,GAAQ,GAAS,GAAS;AAC/B,gBAAY,MAAM,GAAG,CAAC;AAAA,EACvB;AAAA,EAEA,IAAI,OAAY,GAAQ,GAAS,GAAS;AACzC,cAAA,EAAY,IAAI,OAAO,GAAG,CAAC;AAAA,EAC5B;AAAA,EAEA,MAAM,YAA+B,SAA0C;AAC9E,WAAO,UAAA,EAAY,MAAM,YAAY,OAAO;AAAA,EAC7C;AAAA,EAEA,IAAI,aAAa;AAChB,WAAO,YAAY;AAAA,EACpB;AAAA,EAEA,QAAc;AACb,cAAA,EAAY,MAAA;AAAA,EACb;AAAA,EAEA,MAAS,IAAwC,YAA+B,SAA8C;AAC7H,WAAO,UAAA,EAAY,MAAM,IAAI,YAAY,OAAO;AAAA,EACjD;AAAA,EAEA,WAAW,SAA8B;AACxC,cAAA,EAAY,WAAW,OAAO;AAAA,EAC/B;AACD;AAEO,MAAM,SAAiB,IAAI,mBAAA;AAE3B,MAAM,aAAa,CAAIA,SAAgB,aAAyB;AACtE,SAAO,YAAY,IAAIA,SAAQ,QAAQ;AACxC;AAEO,MAAM,YAAY,MAAc;AACtC,QAAMA,UAAS,YAAY,SAAA;AAC3B,MAAI,CAACA,SAAQ;AACZ,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACrC;AACA,SAAOA;AACR;AAEO,MAAM,eAAe,MAA0B,YAAY,SAAA;"}
@@ -1 +1 @@
1
- {"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../src/formatting.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAGvD,MAAM,MAAM,mBAAmB,GAAG;IACjC,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC3C,aAAa,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,kBAAkB,mBAAmB,GAAG,SAAS,EAAE,eAAe,gBAAgB,KAAG,mBAsB3H,CAAA;AAED,eAAO,MAAM,wBAAwB,GAAI,YAAY,mBAAmB,EAAE,OAAO,QAAQ,KAAG,MA6B3F,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,WAMvC,CAAA"}
1
+ {"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../src/formatting.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAGvD,MAAM,MAAM,mBAAmB,GAAG;IACjC,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC3C,aAAa,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,sBAAsB,qBAAsB,mBAAmB,GAAG,SAAS,iBAAiB,gBAAgB,KAAG,mBAsB3H,CAAA;AAED,eAAO,MAAM,wBAAwB,eAAgB,mBAAmB,SAAS,QAAQ,KAAG,MA6B3F,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,WAMvC,CAAA"}