@twin.org/logging-connector-console 0.0.2-next.2 → 0.0.3-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{esm/index.mjs → es/consoleLoggingConnector.js} +17 -12
- package/dist/es/consoleLoggingConnector.js.map +1 -0
- package/dist/es/index.js +6 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/IConsoleLoggingConnectorConfig.js +2 -0
- package/dist/es/models/IConsoleLoggingConnectorConfig.js.map +1 -0
- package/dist/es/models/IConsoleLoggingConnectorConstructorOptions.js +2 -0
- package/dist/es/models/IConsoleLoggingConnectorConstructorOptions.js.map +1 -0
- package/dist/types/consoleLoggingConnector.d.ts +10 -5
- package/dist/types/index.d.ts +3 -3
- package/dist/types/models/IConsoleLoggingConnectorConstructorOptions.d.ts +1 -1
- package/docs/changelog.md +33 -0
- package/docs/reference/classes/ConsoleLoggingConnector.md +20 -6
- package/package.json +22 -9
- package/dist/cjs/index.cjs +0 -144
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { Guards, Is } from '@twin.org/core';
|
|
2
|
-
import { LogEntryHelper } from '@twin.org/logging-models';
|
|
3
|
-
|
|
4
1
|
// Copyright 2024 IOTA Stiftung.
|
|
5
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Guards, Is } from "@twin.org/core";
|
|
4
|
+
import { LogEntryHelper, LogLevel } from "@twin.org/logging-models";
|
|
6
5
|
/**
|
|
7
6
|
* Class for performing logging operations in the console.
|
|
8
7
|
*/
|
|
9
|
-
class ConsoleLoggingConnector {
|
|
8
|
+
export class ConsoleLoggingConnector {
|
|
9
|
+
/**
|
|
10
|
+
* Runtime name for the class.
|
|
11
|
+
*/
|
|
12
|
+
static CLASS_NAME = "ConsoleLoggingConnector";
|
|
10
13
|
/**
|
|
11
14
|
* The namespace for the logging connector.
|
|
12
15
|
*/
|
|
@@ -22,10 +25,6 @@ class ConsoleLoggingConnector {
|
|
|
22
25
|
magenta: 35,
|
|
23
26
|
red: 31
|
|
24
27
|
};
|
|
25
|
-
/**
|
|
26
|
-
* Runtime name for the class.
|
|
27
|
-
*/
|
|
28
|
-
CLASS_NAME = "ConsoleLoggingConnector";
|
|
29
28
|
/**
|
|
30
29
|
* The log levels to display, will default to all.
|
|
31
30
|
* @internal
|
|
@@ -51,17 +50,24 @@ class ConsoleLoggingConnector {
|
|
|
51
50
|
* @param options The options for the logging connector.
|
|
52
51
|
*/
|
|
53
52
|
constructor(options) {
|
|
54
|
-
this._levels = options?.config?.levels ??
|
|
53
|
+
this._levels = options?.config?.levels ?? Object.values(LogLevel);
|
|
55
54
|
this._translateMessages = options?.config?.translateMessages ?? false;
|
|
56
55
|
this._hideGroups = options?.config?.hideGroups ?? false;
|
|
57
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Returns the class name of the component.
|
|
59
|
+
* @returns The class name of the component.
|
|
60
|
+
*/
|
|
61
|
+
className() {
|
|
62
|
+
return ConsoleLoggingConnector.CLASS_NAME;
|
|
63
|
+
}
|
|
58
64
|
/**
|
|
59
65
|
* Log an entry to the connector.
|
|
60
66
|
* @param logEntry The entry to log.
|
|
61
67
|
* @returns Nothing.
|
|
62
68
|
*/
|
|
63
69
|
async log(logEntry) {
|
|
64
|
-
Guards.object(
|
|
70
|
+
Guards.object(ConsoleLoggingConnector.CLASS_NAME, "logEntry", logEntry);
|
|
65
71
|
if (this._levels.includes(logEntry.level)) {
|
|
66
72
|
logEntry.ts ??= Date.now();
|
|
67
73
|
const params = [
|
|
@@ -138,5 +144,4 @@ class ConsoleLoggingConnector {
|
|
|
138
144
|
}
|
|
139
145
|
}
|
|
140
146
|
}
|
|
141
|
-
|
|
142
|
-
export { ConsoleLoggingConnector };
|
|
147
|
+
//# sourceMappingURL=consoleLoggingConnector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consoleLoggingConnector.js","sourceRoot":"","sources":["../../src/consoleLoggingConnector.ts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BACtB,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 string 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/dist/es/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
export * from "./consoleLoggingConnector.js";
|
|
4
|
+
export * from "./models/IConsoleLoggingConnectorConfig.js";
|
|
5
|
+
export * from "./models/IConsoleLoggingConnectorConstructorOptions.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wDAAwD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./consoleLoggingConnector.js\";\nexport * from \"./models/IConsoleLoggingConnectorConfig.js\";\nexport * from \"./models/IConsoleLoggingConnectorConstructorOptions.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IConsoleLoggingConnectorConfig.js","sourceRoot":"","sources":["../../../src/models/IConsoleLoggingConnectorConfig.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ILoggingLevelsConfig } from \"@twin.org/logging-models\";\n\n/**\n * Configuration for the Console Logging Connector.\n */\nexport interface IConsoleLoggingConnectorConfig extends ILoggingLevelsConfig {\n\t/**\n\t * Translate message using the current locale.\n\t */\n\ttranslateMessages?: boolean;\n\n\t/**\n\t * Hide the group display.\n\t */\n\thideGroups?: boolean;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IConsoleLoggingConnectorConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IConsoleLoggingConnectorConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IConsoleLoggingConnectorConfig } from \"./IConsoleLoggingConnectorConfig.js\";\n\n/**\n * Options for the console logging connector constructor.\n */\nexport interface IConsoleLoggingConnectorConstructorOptions {\n\t/**\n\t * The configuration for the console logging connector.\n\t */\n\tconfig?: IConsoleLoggingConnectorConfig;\n}\n"]}
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
import { type ILogEntry, type ILoggingConnector } from "@twin.org/logging-models";
|
|
2
|
-
import type { IConsoleLoggingConnectorConstructorOptions } from "./models/IConsoleLoggingConnectorConstructorOptions";
|
|
2
|
+
import type { IConsoleLoggingConnectorConstructorOptions } from "./models/IConsoleLoggingConnectorConstructorOptions.js";
|
|
3
3
|
/**
|
|
4
4
|
* Class for performing logging operations in the console.
|
|
5
5
|
*/
|
|
6
6
|
export declare class ConsoleLoggingConnector implements ILoggingConnector {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Runtime name for the class.
|
|
9
9
|
*/
|
|
10
|
-
static readonly
|
|
10
|
+
static readonly CLASS_NAME: string;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* The namespace for the logging connector.
|
|
13
13
|
*/
|
|
14
|
-
readonly
|
|
14
|
+
static readonly NAMESPACE: string;
|
|
15
15
|
/**
|
|
16
16
|
* Create a new instance of ConsoleLoggingConnector.
|
|
17
17
|
* @param options The options for the logging connector.
|
|
18
18
|
*/
|
|
19
19
|
constructor(options?: IConsoleLoggingConnectorConstructorOptions);
|
|
20
|
+
/**
|
|
21
|
+
* Returns the class name of the component.
|
|
22
|
+
* @returns The class name of the component.
|
|
23
|
+
*/
|
|
24
|
+
className(): string;
|
|
20
25
|
/**
|
|
21
26
|
* Log an entry to the connector.
|
|
22
27
|
* @param logEntry The entry to log.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./consoleLoggingConnector";
|
|
2
|
-
export * from "./models/IConsoleLoggingConnectorConfig";
|
|
3
|
-
export * from "./models/IConsoleLoggingConnectorConstructorOptions";
|
|
1
|
+
export * from "./consoleLoggingConnector.js";
|
|
2
|
+
export * from "./models/IConsoleLoggingConnectorConfig.js";
|
|
3
|
+
export * from "./models/IConsoleLoggingConnectorConstructorOptions.js";
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @twin.org/logging-connector-console - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.1](https://github.com/twinfoundation/logging/compare/logging-connector-console-v0.0.3-next.0...logging-connector-console-v0.0.3-next.1) (2025-11-10)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add context id features ([#33](https://github.com/twinfoundation/logging/issues/33)) ([38e982c](https://github.com/twinfoundation/logging/commit/38e982c9f009019fc02b67d919444b52657c9021))
|
|
9
|
+
* add validate-locales ([df53f13](https://github.com/twinfoundation/logging/commit/df53f1331394f2f9333e91e4995a88dded90e484))
|
|
10
|
+
* eslint migration to flat config ([1f9fdde](https://github.com/twinfoundation/logging/commit/1f9fddedfdcce9942afed431d9460a0f22092744))
|
|
11
|
+
* update dependencies ([976fc06](https://github.com/twinfoundation/logging/commit/976fc06976c4899769486b7cb2e827c407d7fc89))
|
|
12
|
+
* update framework core ([aac823c](https://github.com/twinfoundation/logging/commit/aac823c2ead88843618b8a82b308d5a793411764))
|
|
13
|
+
* use shared store mechanism ([#20](https://github.com/twinfoundation/logging/issues/20)) ([bbacd31](https://github.com/twinfoundation/logging/commit/bbacd31af991d82d84294ad432a40830692880ca))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Dependencies
|
|
17
|
+
|
|
18
|
+
* The following workspace dependencies were updated
|
|
19
|
+
* dependencies
|
|
20
|
+
* @twin.org/logging-models bumped from 0.0.3-next.0 to 0.0.3-next.1
|
|
21
|
+
|
|
22
|
+
## [0.0.2-next.3](https://github.com/twinfoundation/logging/compare/logging-connector-console-v0.0.2-next.2...logging-connector-console-v0.0.2-next.3) (2025-10-09)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* add validate-locales ([df53f13](https://github.com/twinfoundation/logging/commit/df53f1331394f2f9333e91e4995a88dded90e484))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Dependencies
|
|
31
|
+
|
|
32
|
+
* The following workspace dependencies were updated
|
|
33
|
+
* dependencies
|
|
34
|
+
* @twin.org/logging-models bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
35
|
+
|
|
3
36
|
## [0.0.2-next.2](https://github.com/twinfoundation/logging/compare/logging-connector-console-v0.0.2-next.1...logging-connector-console-v0.0.2-next.2) (2025-08-29)
|
|
4
37
|
|
|
5
38
|
|
|
@@ -28,25 +28,39 @@ The options for the logging connector.
|
|
|
28
28
|
|
|
29
29
|
## Properties
|
|
30
30
|
|
|
31
|
+
### CLASS\_NAME
|
|
32
|
+
|
|
33
|
+
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
34
|
+
|
|
35
|
+
Runtime name for the class.
|
|
36
|
+
|
|
37
|
+
***
|
|
38
|
+
|
|
31
39
|
### NAMESPACE
|
|
32
40
|
|
|
33
41
|
> `readonly` `static` **NAMESPACE**: `string` = `"console"`
|
|
34
42
|
|
|
35
43
|
The namespace for the logging connector.
|
|
36
44
|
|
|
37
|
-
|
|
45
|
+
## Methods
|
|
38
46
|
|
|
39
|
-
###
|
|
47
|
+
### className()
|
|
40
48
|
|
|
41
|
-
>
|
|
49
|
+
> **className**(): `string`
|
|
42
50
|
|
|
43
|
-
|
|
51
|
+
Returns the class name of the component.
|
|
52
|
+
|
|
53
|
+
#### Returns
|
|
54
|
+
|
|
55
|
+
`string`
|
|
56
|
+
|
|
57
|
+
The class name of the component.
|
|
44
58
|
|
|
45
59
|
#### Implementation of
|
|
46
60
|
|
|
47
|
-
`ILoggingConnector.
|
|
61
|
+
`ILoggingConnector.className`
|
|
48
62
|
|
|
49
|
-
|
|
63
|
+
***
|
|
50
64
|
|
|
51
65
|
### log()
|
|
52
66
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/logging-connector-console",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-next.1",
|
|
4
4
|
"description": "Logging connector implementation using the console",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,25 +15,38 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@twin.org/core": "next",
|
|
18
|
-
"@twin.org/logging-models": "0.0.
|
|
18
|
+
"@twin.org/logging-models": "0.0.3-next.1",
|
|
19
19
|
"@twin.org/nameof": "next"
|
|
20
20
|
},
|
|
21
|
-
"main": "./dist/
|
|
22
|
-
"module": "./dist/esm/index.mjs",
|
|
21
|
+
"main": "./dist/es/index.js",
|
|
23
22
|
"types": "./dist/types/index.d.ts",
|
|
24
23
|
"exports": {
|
|
25
24
|
".": {
|
|
26
25
|
"types": "./dist/types/index.d.ts",
|
|
27
|
-
"
|
|
28
|
-
"
|
|
26
|
+
"import": "./dist/es/index.js",
|
|
27
|
+
"default": "./dist/es/index.js"
|
|
29
28
|
},
|
|
30
29
|
"./locales/*.json": "./locales/*.json"
|
|
31
30
|
},
|
|
32
31
|
"files": [
|
|
33
|
-
"dist/
|
|
34
|
-
"dist/esm",
|
|
32
|
+
"dist/es",
|
|
35
33
|
"dist/types",
|
|
36
34
|
"locales",
|
|
37
35
|
"docs"
|
|
38
|
-
]
|
|
36
|
+
],
|
|
37
|
+
"keywords": [
|
|
38
|
+
"twin",
|
|
39
|
+
"trade",
|
|
40
|
+
"iota",
|
|
41
|
+
"framework",
|
|
42
|
+
"blockchain",
|
|
43
|
+
"logging",
|
|
44
|
+
"connector",
|
|
45
|
+
"adapter",
|
|
46
|
+
"integration"
|
|
47
|
+
],
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "git+https://github.com/twinfoundation/logging/issues"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://twindev.org"
|
|
39
52
|
}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var core = require('@twin.org/core');
|
|
4
|
-
var loggingModels = require('@twin.org/logging-models');
|
|
5
|
-
|
|
6
|
-
// Copyright 2024 IOTA Stiftung.
|
|
7
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
8
|
-
/**
|
|
9
|
-
* Class for performing logging operations in the console.
|
|
10
|
-
*/
|
|
11
|
-
class ConsoleLoggingConnector {
|
|
12
|
-
/**
|
|
13
|
-
* The namespace for the logging connector.
|
|
14
|
-
*/
|
|
15
|
-
static NAMESPACE = "console";
|
|
16
|
-
/**
|
|
17
|
-
* Colors for highlighting.
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
|
-
static _COLORS = {
|
|
21
|
-
blue: 34,
|
|
22
|
-
cyan: 36,
|
|
23
|
-
green: 32,
|
|
24
|
-
magenta: 35,
|
|
25
|
-
red: 31
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Runtime name for the class.
|
|
29
|
-
*/
|
|
30
|
-
CLASS_NAME = "ConsoleLoggingConnector";
|
|
31
|
-
/**
|
|
32
|
-
* The log levels to display, will default to all.
|
|
33
|
-
* @internal
|
|
34
|
-
*/
|
|
35
|
-
_levels;
|
|
36
|
-
/**
|
|
37
|
-
* Translate messages using the current locale.
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
_translateMessages;
|
|
41
|
-
/**
|
|
42
|
-
* Hide the groups.
|
|
43
|
-
* @internal
|
|
44
|
-
*/
|
|
45
|
-
_hideGroups;
|
|
46
|
-
/**
|
|
47
|
-
* The last group identity.
|
|
48
|
-
* @internal
|
|
49
|
-
*/
|
|
50
|
-
_lastGroup;
|
|
51
|
-
/**
|
|
52
|
-
* Create a new instance of ConsoleLoggingConnector.
|
|
53
|
-
* @param options The options for the logging connector.
|
|
54
|
-
*/
|
|
55
|
-
constructor(options) {
|
|
56
|
-
this._levels = options?.config?.levels ?? ["debug", "info", "warn", "error", "trace"];
|
|
57
|
-
this._translateMessages = options?.config?.translateMessages ?? false;
|
|
58
|
-
this._hideGroups = options?.config?.hideGroups ?? false;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Log an entry to the connector.
|
|
62
|
-
* @param logEntry The entry to log.
|
|
63
|
-
* @returns Nothing.
|
|
64
|
-
*/
|
|
65
|
-
async log(logEntry) {
|
|
66
|
-
core.Guards.object(this.CLASS_NAME, "logEntry", logEntry);
|
|
67
|
-
if (this._levels.includes(logEntry.level)) {
|
|
68
|
-
logEntry.ts ??= Date.now();
|
|
69
|
-
const params = [
|
|
70
|
-
this.colorize(logEntry.level.toUpperCase(), logEntry.level === "error" ? "red" : "green"),
|
|
71
|
-
this.colorize(`[${new Date(logEntry.ts).toISOString()}]`, "magenta")
|
|
72
|
-
];
|
|
73
|
-
if (!this._hideGroups) {
|
|
74
|
-
this.handleGroup(logEntry.source);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
params.push(this.colorize(logEntry.source, "blue"));
|
|
78
|
-
}
|
|
79
|
-
let message = logEntry.message;
|
|
80
|
-
let data = logEntry.data;
|
|
81
|
-
if (this._translateMessages) {
|
|
82
|
-
const translatedMessage = loggingModels.LogEntryHelper.translate(logEntry);
|
|
83
|
-
if (core.Is.stringValue(translatedMessage)) {
|
|
84
|
-
message = translatedMessage;
|
|
85
|
-
data = undefined;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
params.push(this.colorize(message, "cyan"));
|
|
89
|
-
if (!core.Is.empty(data)) {
|
|
90
|
-
if (core.Is.object(data) || core.Is.array(data)) {
|
|
91
|
-
params.push(JSON.stringify(data));
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
params.push(data);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (logEntry.error) {
|
|
98
|
-
params.push(logEntry.error);
|
|
99
|
-
}
|
|
100
|
-
globalThis.console[logEntry.level](...params);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Convert a string to a color.
|
|
105
|
-
* @param str The string to convert.
|
|
106
|
-
* @returns The color.
|
|
107
|
-
* @internal
|
|
108
|
-
*/
|
|
109
|
-
stringToColor(str) {
|
|
110
|
-
const stringUniqueHash = [...str].reduce(
|
|
111
|
-
// eslint-disable-next-line no-bitwise
|
|
112
|
-
(acc, char) => char.charCodeAt(0) + ((acc << 5) - acc), 0);
|
|
113
|
-
return `hsl(${stringUniqueHash % 360}, 95%, 35%)`;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Add color to a string.
|
|
117
|
-
* @param string The string to colorize.
|
|
118
|
-
* @param color The color to use.
|
|
119
|
-
* @returns The colorized string.
|
|
120
|
-
* @internal
|
|
121
|
-
*/
|
|
122
|
-
colorize(message, color) {
|
|
123
|
-
// eslint-disable-next-line unicorn/escape-case,unicorn/no-hex-escape
|
|
124
|
-
return `\x1b[${ConsoleLoggingConnector._COLORS[color]}m${message}\x1b[39m`;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Handle a group.
|
|
128
|
-
* @param group The group.
|
|
129
|
-
* @internal
|
|
130
|
-
*/
|
|
131
|
-
handleGroup(group) {
|
|
132
|
-
if (this._lastGroup !== group) {
|
|
133
|
-
this._lastGroup = group;
|
|
134
|
-
if (this._lastGroup) {
|
|
135
|
-
globalThis.console.groupEnd();
|
|
136
|
-
}
|
|
137
|
-
if (group.length > 0) {
|
|
138
|
-
globalThis.console.group(`%c${group}`, `color: #ffffff; background: ${this.stringToColor(group)}; font-size: 10px; font-weight: bold; padding: 2px 4px; border-radius: 5px`);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
exports.ConsoleLoggingConnector = ConsoleLoggingConnector;
|