@twin.org/logging-connector-console 0.0.3-next.4 → 0.0.3-next.6
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.
|
@@ -118,7 +118,7 @@ export class ConsoleLoggingConnector {
|
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
120
|
* Add color to a string.
|
|
121
|
-
* @param
|
|
121
|
+
* @param message The string to colorize.
|
|
122
122
|
* @param color The color to use.
|
|
123
123
|
* @returns The colorized string.
|
|
124
124
|
* @internal
|
|
@@ -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,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;IAE7C;;;OAGG;IACc,WAAW,CAAU;IAEtC;;;OAGG;IACK,UAAU,CAAU;IAE5B;;;OAGG;IACH,YAAY,OAAoD;QAC/D,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClE,IAAI,CAAC,kBAAkB,GAAG,OAAO,EAAE,M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,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
|
|
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,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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"]}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.6](https://github.com/iotaledger/twin-logging/compare/logging-connector-console-v0.0.3-next.5...logging-connector-console-v0.0.3-next.6) (2026-06-05)
|
|
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.5 to 0.0.3-next.6
|
|
16
|
+
|
|
17
|
+
## [0.0.3-next.5](https://github.com/iotaledger/twin-logging/compare/logging-connector-console-v0.0.3-next.4...logging-connector-console-v0.0.3-next.5) (2026-06-04)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Miscellaneous Chores
|
|
21
|
+
|
|
22
|
+
* **logging-connector-console:** Synchronize repo versions
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Dependencies
|
|
26
|
+
|
|
27
|
+
* The following workspace dependencies were updated
|
|
28
|
+
* dependencies
|
|
29
|
+
* @twin.org/logging-models bumped from 0.0.3-next.4 to 0.0.3-next.5
|
|
30
|
+
|
|
3
31
|
## [0.0.3-next.4](https://github.com/iotaledger/twin-logging/compare/logging-connector-console-v0.0.3-next.3...logging-connector-console-v0.0.3-next.4) (2026-05-20)
|
|
4
32
|
|
|
5
33
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/logging-connector-console",
|
|
3
|
-
"version": "0.0.3-next.
|
|
3
|
+
"version": "0.0.3-next.6",
|
|
4
4
|
"description": "Sends log events to the console for local development, debugging, and lightweight runtime diagnostics.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/iotaledger/logging.git",
|
|
7
|
+
"url": "git+https://github.com/iotaledger/twin-logging.git",
|
|
8
8
|
"directory": "packages/logging-connector-console"
|
|
9
9
|
},
|
|
10
10
|
"author": "martyn.janes@iota.org",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@twin.org/core": "next",
|
|
18
|
-
"@twin.org/logging-models": "0.0.3-next.
|
|
18
|
+
"@twin.org/logging-models": "0.0.3-next.6",
|
|
19
19
|
"@twin.org/nameof": "next"
|
|
20
20
|
},
|
|
21
21
|
"main": "./dist/es/index.js",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"integration"
|
|
47
47
|
],
|
|
48
48
|
"bugs": {
|
|
49
|
-
"url": "git+https://github.com/iotaledger/logging/issues"
|
|
49
|
+
"url": "git+https://github.com/iotaledger/twin-logging/issues"
|
|
50
50
|
},
|
|
51
51
|
"homepage": "https://twindev.org"
|
|
52
52
|
}
|