@twin.org/logging-connector-console 0.0.3-next.7 → 0.0.3-next.8

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.
@@ -64,7 +64,7 @@ export class ConsoleLoggingConnector {
64
64
  /**
65
65
  * Log an entry to the connector.
66
66
  * @param logEntry The entry to log.
67
- * @returns Nothing.
67
+ * @returns A promise that resolves when the entry has been written to the console.
68
68
  */
69
69
  async log(logEntry) {
70
70
  Guards.object(ConsoleLoggingConnector.CLASS_NAME, "logEntry", logEntry);
@@ -105,9 +105,9 @@ export class ConsoleLoggingConnector {
105
105
  }
106
106
  }
107
107
  /**
108
- * Convert a string to a color.
109
- * @param str The string to convert.
110
- * @returns The color.
108
+ * Derives an HSL color string from a source string using a hash of its characters.
109
+ * @param str The string to derive a color from.
110
+ * @returns An HSL color string suitable for use in CSS.
111
111
  * @internal
112
112
  */
113
113
  stringToColor(str) {
@@ -128,8 +128,8 @@ export class ConsoleLoggingConnector {
128
128
  return `\x1b[${ConsoleLoggingConnector._COLORS[color]}m${message}\x1b[39m`;
129
129
  }
130
130
  /**
131
- * Handle a group.
132
- * @param group The group.
131
+ * Opens or switches the console group when the active group changes.
132
+ * @param group The group identifier to display.
133
133
  * @internal
134
134
  */
135
135
  handleGroup(group) {
@@ -1 +1 @@
1
- {"version":3,"file":"consoleLoggingConnector.js","sourceRoot":"","sources":["../../src/consoleLoggingConnector.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACN,cAAc,EACd,QAAQ,EAGR,MAAM,0BAA0B,CAAC;AAIlC;;GAEG;AACH,MAAM,OAAO,uBAAuB;IACnC;;OAEG;IACI,MAAM,CAAU,UAAU,6BAA6C;IAE9E;;OAEG;IACI,MAAM,CAAU,SAAS,GAAW,SAAS,CAAC;IAErD;;;OAGG;IACK,MAAM,CAAU,O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O,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;QAC/C,CAAC;IACF,CAAC;IAED;;;;;OAKG;IACK,aAAa,CAAC,GAAW;QAChC,MAAM,gBAAgB,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,MAAM;QACvC,sCAAsC;QACtC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,EACtD,CAAC,CACD,CAAC;QACF,OAAO,OAAO,gBAAgB,GAAG,GAAG,aAAa,CAAC;IACnD,CAAC;IAED;;;;;;OAMG;IACK,QAAQ,CAAC,OAAe,EAAE,KAAoD;QACrF,qEAAqE;QACrE,OAAO,QAAQ,uBAAuB,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,UAAU,CAAC;IAC5E,CAAC;IAED;;;;OAIG;IACK,WAAW,CAAC,KAAa;QAChC,IAAI,IAAI,CAAC,UAAU,KAAK,KAAK,EAAE,CAAC;YAC/B,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;YACxB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACrB,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YAC/B,CAAC;YACD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACtB,UAAU,CAAC,OAAO,CAAC,KAAK,CACvB,KAAK,KAAK,EAAE,EACZ,+BAA+B,IAAI,CAAC,aAAa,CAChD,KAAK,CACL,4EAA4E,CAC7E,CAAC;YACH,CAAC;QACF,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Guards, Is } from \"@twin.org/core\";\nimport {\n\tLogEntryHelper,\n\tLogLevel,\n\ttype ILogEntry,\n\ttype ILoggingConnector\n} from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IConsoleLoggingConnectorConstructorOptions } from \"./models/IConsoleLoggingConnectorConstructorOptions.js\";\n\n/**\n * Class for performing logging operations in the console.\n */\nexport class ConsoleLoggingConnector implements ILoggingConnector {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<ConsoleLoggingConnector>();\n\n\t/**\n\t * The namespace for the logging connector.\n\t */\n\tpublic static readonly NAMESPACE: string = \"console\";\n\n\t/**\n\t * Colors for highlighting.\n\t * @internal\n\t */\n\tprivate static readonly _COLORS: { [id: string]: number } = {\n\t\tblue: 34,\n\t\tcyan: 36,\n\t\tgreen: 32,\n\t\tmagenta: 35,\n\t\tred: 31\n\t};\n\n\t/**\n\t * The log levels to display, will default to all.\n\t * @internal\n\t */\n\tprivate readonly _levels: LogLevel[];\n\n\t/**\n\t * Translate messages using the current locale.\n\t * @internal\n\t */\n\tprivate readonly _translateMessages: boolean;\n\n\t/**\n\t * Hide the groups.\n\t * @internal\n\t */\n\tprivate readonly _hideGroups: boolean;\n\n\t/**\n\t * The last group identity.\n\t * @internal\n\t */\n\tprivate _lastGroup?: string;\n\n\t/**\n\t * Create a new instance of ConsoleLoggingConnector.\n\t * @param options The options for the logging connector.\n\t */\n\tconstructor(options?: IConsoleLoggingConnectorConstructorOptions) {\n\t\tthis._levels = options?.config?.levels ?? Object.values(LogLevel);\n\t\tthis._translateMessages = options?.config?.translateMessages ?? false;\n\t\tthis._hideGroups = options?.config?.hideGroups ?? false;\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn ConsoleLoggingConnector.CLASS_NAME;\n\t}\n\n\t/**\n\t * Log an entry to the connector.\n\t * @param logEntry The entry to log.\n\t * @returns Nothing.\n\t */\n\tpublic async log(logEntry: ILogEntry): Promise<void> {\n\t\tGuards.object<ILogEntry>(ConsoleLoggingConnector.CLASS_NAME, nameof(logEntry), logEntry);\n\n\t\tif (this._levels.includes(logEntry.level)) {\n\t\t\tlogEntry.ts ??= Date.now();\n\n\t\t\tconst params: unknown[] = [\n\t\t\t\tthis.colorize(logEntry.level.toUpperCase(), logEntry.level === \"error\" ? \"red\" : \"green\"),\n\t\t\t\tthis.colorize(`[${new Date(logEntry.ts).toISOString()}]`, \"magenta\")\n\t\t\t];\n\n\t\t\tif (!this._hideGroups) {\n\t\t\t\tthis.handleGroup(logEntry.source);\n\t\t\t} else {\n\t\t\t\tparams.push(this.colorize(logEntry.source, \"blue\"));\n\t\t\t}\n\n\t\t\tlet message = logEntry.message;\n\t\t\tlet data = logEntry.data;\n\n\t\t\tif (this._translateMessages) {\n\t\t\t\tconst translatedMessage = LogEntryHelper.translate(logEntry);\n\t\t\t\tif (Is.stringValue(translatedMessage)) {\n\t\t\t\t\tmessage = translatedMessage;\n\t\t\t\t\tdata = undefined;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tparams.push(this.colorize(message, \"cyan\"));\n\n\t\t\tif (!Is.empty(data)) {\n\t\t\t\tif (Is.object(data) || Is.array(data)) {\n\t\t\t\t\tparams.push(JSON.stringify(data));\n\t\t\t\t} else {\n\t\t\t\t\tparams.push(data);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (logEntry.error) {\n\t\t\t\tparams.push(logEntry.error);\n\t\t\t}\n\n\t\t\tglobalThis.console[logEntry.level](...params);\n\t\t}\n\t}\n\n\t/**\n\t * Convert a string to a color.\n\t * @param str The string to convert.\n\t * @returns The color.\n\t * @internal\n\t */\n\tprivate stringToColor(str: string): string {\n\t\tconst stringUniqueHash = [...str].reduce(\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t(acc, char) => char.charCodeAt(0) + ((acc << 5) - acc),\n\t\t\t0\n\t\t);\n\t\treturn `hsl(${stringUniqueHash % 360}, 95%, 35%)`;\n\t}\n\n\t/**\n\t * Add color to a string.\n\t * @param message The string to colorize.\n\t * @param color The color to use.\n\t * @returns The colorized string.\n\t * @internal\n\t */\n\tprivate colorize(message: string, color: \"blue\" | \"cyan\" | \"green\" | \"magenta\" | \"red\"): string {\n\t\t// eslint-disable-next-line unicorn/escape-case,unicorn/no-hex-escape\n\t\treturn `\\x1b[${ConsoleLoggingConnector._COLORS[color]}m${message}\\x1b[39m`;\n\t}\n\n\t/**\n\t * Handle a group.\n\t * @param group The group.\n\t * @internal\n\t */\n\tprivate handleGroup(group: string): void {\n\t\tif (this._lastGroup !== group) {\n\t\t\tthis._lastGroup = group;\n\t\t\tif (this._lastGroup) {\n\t\t\t\tglobalThis.console.groupEnd();\n\t\t\t}\n\t\t\tif (group.length > 0) {\n\t\t\t\tglobalThis.console.group(\n\t\t\t\t\t`%c${group}`,\n\t\t\t\t\t`color: #ffffff; background: ${this.stringToColor(\n\t\t\t\t\t\tgroup\n\t\t\t\t\t)}; font-size: 10px; font-weight: bold; padding: 2px 4px; border-radius: 5px`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"consoleLoggingConnector.js","sourceRoot":"","sources":["../../src/consoleLoggingConnector.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACN,cAAc,EACd,QAAQ,EAGR,MAAM,0BAA0B,CAAC;AAIlC;;GAEG;AACH,MAAM,OAAO,uBAAuB;IACnC;;OAEG;IACI,MAAM,CAAU,UAAU,6BAA6C;IAE9E;;OAEG;IACI,MAAM,CAAU,SAAS,GAAW,SAAS,CAAC;IAErD;;;OAGG;IACK,MAAM,CAAU,OAAO,GAA6B;QAC3D,IAAI,EAAE,EAAE;QACR,IAAI,EAAE,EAAE;QACR,KAAK,EAAE,EAAE;QACT,OAAO,EAAE,EAAE;QACX,GAAG,EAAE,EAAE;KACP,CAAC;IAEF;;;OAGG;IACc,OAAO,CAAa;IAErC;;;OAGG;IACc,kBAAkB,CAAU;IAE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,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,EACtD,CAAC,CACD,CAAC;QACF,OAAO,OAAO,gBAAgB,GAAG,GAAG,aAAa,CAAC;IACnD,CAAC;IAED;;;;;;OAMG;IACK,QAAQ,CAAC,OAAe,EAAE,KAAoD;QACrF,qEAAqE;QACrE,OAAO,QAAQ,uBAAuB,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,UAAU,CAAC;IAC5E,CAAC;IAED;;;;OAIG;IACK,WAAW,CAAC,KAAa;QAChC,IAAI,IAAI,CAAC,UAAU,KAAK,KAAK,EAAE,CAAC;YAC/B,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;YACxB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACrB,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YAC/B,CAAC;YACD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACtB,UAAU,CAAC,OAAO,CAAC,KAAK,CACvB,KAAK,KAAK,EAAE,EACZ,+BAA+B,IAAI,CAAC,aAAa,CAChD,KAAK,CACL,4EAA4E,CAC7E,CAAC;YACH,CAAC;QACF,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Guards, Is } from \"@twin.org/core\";\nimport {\n\tLogEntryHelper,\n\tLogLevel,\n\ttype ILogEntry,\n\ttype ILoggingConnector\n} from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IConsoleLoggingConnectorConstructorOptions } from \"./models/IConsoleLoggingConnectorConstructorOptions.js\";\n\n/**\n * Class for performing logging operations in the console.\n */\nexport class ConsoleLoggingConnector implements ILoggingConnector {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<ConsoleLoggingConnector>();\n\n\t/**\n\t * The namespace for the logging connector.\n\t */\n\tpublic static readonly NAMESPACE: string = \"console\";\n\n\t/**\n\t * Colors for highlighting.\n\t * @internal\n\t */\n\tprivate static readonly _COLORS: { [id: string]: number } = {\n\t\tblue: 34,\n\t\tcyan: 36,\n\t\tgreen: 32,\n\t\tmagenta: 35,\n\t\tred: 31\n\t};\n\n\t/**\n\t * The log levels to display, will default to all.\n\t * @internal\n\t */\n\tprivate readonly _levels: LogLevel[];\n\n\t/**\n\t * Translate messages using the current locale.\n\t * @internal\n\t */\n\tprivate readonly _translateMessages: boolean;\n\n\t/**\n\t * Hide the groups.\n\t * @internal\n\t */\n\tprivate readonly _hideGroups: boolean;\n\n\t/**\n\t * The last group identity.\n\t * @internal\n\t */\n\tprivate _lastGroup?: string;\n\n\t/**\n\t * Create a new instance of ConsoleLoggingConnector.\n\t * @param options The options for the logging connector.\n\t */\n\tconstructor(options?: IConsoleLoggingConnectorConstructorOptions) {\n\t\tthis._levels = options?.config?.levels ?? Object.values(LogLevel);\n\t\tthis._translateMessages = options?.config?.translateMessages ?? false;\n\t\tthis._hideGroups = options?.config?.hideGroups ?? false;\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn ConsoleLoggingConnector.CLASS_NAME;\n\t}\n\n\t/**\n\t * Log an entry to the connector.\n\t * @param logEntry The entry to log.\n\t * @returns A promise that resolves when the entry has been written to the console.\n\t */\n\tpublic async log(logEntry: ILogEntry): Promise<void> {\n\t\tGuards.object<ILogEntry>(ConsoleLoggingConnector.CLASS_NAME, nameof(logEntry), logEntry);\n\n\t\tif (this._levels.includes(logEntry.level)) {\n\t\t\tlogEntry.ts ??= Date.now();\n\n\t\t\tconst params: unknown[] = [\n\t\t\t\tthis.colorize(logEntry.level.toUpperCase(), logEntry.level === \"error\" ? \"red\" : \"green\"),\n\t\t\t\tthis.colorize(`[${new Date(logEntry.ts).toISOString()}]`, \"magenta\")\n\t\t\t];\n\n\t\t\tif (!this._hideGroups) {\n\t\t\t\tthis.handleGroup(logEntry.source);\n\t\t\t} else {\n\t\t\t\tparams.push(this.colorize(logEntry.source, \"blue\"));\n\t\t\t}\n\n\t\t\tlet message = logEntry.message;\n\t\t\tlet data = logEntry.data;\n\n\t\t\tif (this._translateMessages) {\n\t\t\t\tconst translatedMessage = LogEntryHelper.translate(logEntry);\n\t\t\t\tif (Is.stringValue(translatedMessage)) {\n\t\t\t\t\tmessage = translatedMessage;\n\t\t\t\t\tdata = undefined;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tparams.push(this.colorize(message, \"cyan\"));\n\n\t\t\tif (!Is.empty(data)) {\n\t\t\t\tif (Is.object(data) || Is.array(data)) {\n\t\t\t\t\tparams.push(JSON.stringify(data));\n\t\t\t\t} else {\n\t\t\t\t\tparams.push(data);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (logEntry.error) {\n\t\t\t\tparams.push(logEntry.error);\n\t\t\t}\n\n\t\t\tglobalThis.console[logEntry.level](...params);\n\t\t}\n\t}\n\n\t/**\n\t * Derives an HSL color string from a source string using a hash of its characters.\n\t * @param str The string to derive a color from.\n\t * @returns An HSL color string suitable for use in CSS.\n\t * @internal\n\t */\n\tprivate stringToColor(str: string): string {\n\t\tconst stringUniqueHash = [...str].reduce(\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t(acc, char) => char.charCodeAt(0) + ((acc << 5) - acc),\n\t\t\t0\n\t\t);\n\t\treturn `hsl(${stringUniqueHash % 360}, 95%, 35%)`;\n\t}\n\n\t/**\n\t * Add color to a string.\n\t * @param message The string to colorize.\n\t * @param color The color to use.\n\t * @returns The colorized string.\n\t * @internal\n\t */\n\tprivate colorize(message: string, color: \"blue\" | \"cyan\" | \"green\" | \"magenta\" | \"red\"): string {\n\t\t// eslint-disable-next-line unicorn/escape-case,unicorn/no-hex-escape\n\t\treturn `\\x1b[${ConsoleLoggingConnector._COLORS[color]}m${message}\\x1b[39m`;\n\t}\n\n\t/**\n\t * Opens or switches the console group when the active group changes.\n\t * @param group The group identifier to display.\n\t * @internal\n\t */\n\tprivate handleGroup(group: string): void {\n\t\tif (this._lastGroup !== group) {\n\t\t\tthis._lastGroup = group;\n\t\t\tif (this._lastGroup) {\n\t\t\t\tglobalThis.console.groupEnd();\n\t\t\t}\n\t\t\tif (group.length > 0) {\n\t\t\t\tglobalThis.console.group(\n\t\t\t\t\t`%c${group}`,\n\t\t\t\t\t`color: #ffffff; background: ${this.stringToColor(\n\t\t\t\t\t\tgroup\n\t\t\t\t\t)}; font-size: 10px; font-weight: bold; padding: 2px 4px; border-radius: 5px`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -25,7 +25,7 @@ export declare class ConsoleLoggingConnector implements ILoggingConnector {
25
25
  /**
26
26
  * Log an entry to the connector.
27
27
  * @param logEntry The entry to log.
28
- * @returns Nothing.
28
+ * @returns A promise that resolves when the entry has been written to the console.
29
29
  */
30
30
  log(logEntry: ILogEntry): Promise<void>;
31
31
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.8](https://github.com/iotaledger/twin-logging/compare/logging-connector-console-v0.0.3-next.7...logging-connector-console-v0.0.3-next.8) (2026-06-19)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * **logging-connector-console:** Synchronize repo versions
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/logging-models bumped from 0.0.3-next.7 to 0.0.3-next.8
16
+
3
17
  ## [0.0.3-next.7](https://github.com/iotaledger/twin-logging/compare/logging-connector-console-v0.0.3-next.6...logging-connector-console-v0.0.3-next.7) (2026-06-11)
4
18
 
5
19
 
@@ -80,7 +80,7 @@ The entry to log.
80
80
 
81
81
  `Promise`\<`void`\>
82
82
 
83
- Nothing.
83
+ A promise that resolves when the entry has been written to the console.
84
84
 
85
85
  #### Implementation of
86
86
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/logging-connector-console",
3
- "version": "0.0.3-next.7",
3
+ "version": "0.0.3-next.8",
4
4
  "description": "Sends log events to the console for local development, debugging, and lightweight runtime diagnostics.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@twin.org/core": "next",
18
- "@twin.org/logging-models": "0.0.3-next.7",
18
+ "@twin.org/logging-models": "0.0.3-next.8",
19
19
  "@twin.org/nameof": "next"
20
20
  },
21
21
  "main": "./dist/es/index.js",