@twin.org/logging-connector-console 0.0.2-next.3 → 0.0.3-next.2

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.
@@ -1,12 +1,11 @@
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 {
10
9
  /**
11
10
  * Runtime name for the class.
12
11
  */
@@ -51,10 +50,17 @@ class ConsoleLoggingConnector {
51
50
  * @param options The options for the logging connector.
52
51
  */
53
52
  constructor(options) {
54
- this._levels = options?.config?.levels ?? ["debug", "info", "warn", "error", "trace"];
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.
@@ -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"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACN,cAAc,EACd,QAAQ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;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"]}
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IConsoleLoggingConnectorConfig.js.map
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IConsoleLoggingConnectorConstructorOptions.js.map
@@ -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,5 +1,5 @@
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
  */
@@ -17,6 +17,11 @@ export declare class ConsoleLoggingConnector implements ILoggingConnector {
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.
@@ -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";
@@ -1,4 +1,4 @@
1
- import type { IConsoleLoggingConnectorConfig } from "./IConsoleLoggingConnectorConfig";
1
+ import type { IConsoleLoggingConnectorConfig } from "./IConsoleLoggingConnectorConfig.js";
2
2
  /**
3
3
  * Options for the console logging connector constructor.
4
4
  */
package/docs/changelog.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # @twin.org/logging-connector-console - Changelog
2
2
 
3
+ ## [0.0.3-next.2](https://github.com/twinfoundation/logging/compare/logging-connector-console-v0.0.3-next.1...logging-connector-console-v0.0.3-next.2) (2026-03-02)
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.1 to 0.0.3-next.2
16
+
17
+ ## [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)
18
+
19
+
20
+ ### Features
21
+
22
+ * add context id features ([#33](https://github.com/twinfoundation/logging/issues/33)) ([38e982c](https://github.com/twinfoundation/logging/commit/38e982c9f009019fc02b67d919444b52657c9021))
23
+ * add validate-locales ([df53f13](https://github.com/twinfoundation/logging/commit/df53f1331394f2f9333e91e4995a88dded90e484))
24
+ * eslint migration to flat config ([1f9fdde](https://github.com/twinfoundation/logging/commit/1f9fddedfdcce9942afed431d9460a0f22092744))
25
+ * update dependencies ([976fc06](https://github.com/twinfoundation/logging/commit/976fc06976c4899769486b7cb2e827c407d7fc89))
26
+ * update framework core ([aac823c](https://github.com/twinfoundation/logging/commit/aac823c2ead88843618b8a82b308d5a793411764))
27
+ * use shared store mechanism ([#20](https://github.com/twinfoundation/logging/issues/20)) ([bbacd31](https://github.com/twinfoundation/logging/commit/bbacd31af991d82d84294ad432a40830692880ca))
28
+
29
+
30
+ ### Dependencies
31
+
32
+ * The following workspace dependencies were updated
33
+ * dependencies
34
+ * @twin.org/logging-models bumped from 0.0.3-next.0 to 0.0.3-next.1
35
+
3
36
  ## [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)
4
37
 
5
38
 
@@ -44,6 +44,24 @@ The namespace for the logging connector.
44
44
 
45
45
  ## Methods
46
46
 
47
+ ### className()
48
+
49
+ > **className**(): `string`
50
+
51
+ Returns the class name of the component.
52
+
53
+ #### Returns
54
+
55
+ `string`
56
+
57
+ The class name of the component.
58
+
59
+ #### Implementation of
60
+
61
+ `ILoggingConnector.className`
62
+
63
+ ***
64
+
47
65
  ### log()
48
66
 
49
67
  > **log**(`logEntry`): `Promise`\<`void`\>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/logging-connector-console",
3
- "version": "0.0.2-next.3",
3
+ "version": "0.0.3-next.2",
4
4
  "description": "Logging connector implementation using the console",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,23 +15,21 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@twin.org/core": "next",
18
- "@twin.org/logging-models": "0.0.2-next.3",
18
+ "@twin.org/logging-models": "0.0.3-next.2",
19
19
  "@twin.org/nameof": "next"
20
20
  },
21
- "main": "./dist/cjs/index.cjs",
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
- "require": "./dist/cjs/index.cjs",
28
- "import": "./dist/esm/index.mjs"
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/cjs",
34
- "dist/esm",
32
+ "dist/es",
35
33
  "dist/types",
36
34
  "locales",
37
35
  "docs"
@@ -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
- * Runtime name for the class.
14
- */
15
- static CLASS_NAME = "ConsoleLoggingConnector";
16
- /**
17
- * The namespace for the logging connector.
18
- */
19
- static NAMESPACE = "console";
20
- /**
21
- * Colors for highlighting.
22
- * @internal
23
- */
24
- static _COLORS = {
25
- blue: 34,
26
- cyan: 36,
27
- green: 32,
28
- magenta: 35,
29
- red: 31
30
- };
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(ConsoleLoggingConnector.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;