@twin.org/logging-models 0.0.2-next.3 → 0.0.2-next.4
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/es/connectors/multiLoggingConnector.js +81 -0
- package/dist/es/connectors/multiLoggingConnector.js.map +1 -0
- package/dist/es/connectors/silentLoggingConnector.js +42 -0
- package/dist/es/connectors/silentLoggingConnector.js.map +1 -0
- package/dist/es/factories/loggingConnectorFactory.js +9 -0
- package/dist/es/factories/loggingConnectorFactory.js.map +1 -0
- package/dist/es/helpers/logEntryHelper.js +31 -0
- package/dist/es/helpers/logEntryHelper.js.map +1 -0
- package/dist/es/index.js +16 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/ILogEntry.js +2 -0
- package/dist/es/models/ILogEntry.js.map +1 -0
- package/dist/es/models/ILoggingComponent.js +2 -0
- package/dist/es/models/ILoggingComponent.js.map +1 -0
- package/dist/es/models/ILoggingConnector.js +2 -0
- package/dist/es/models/ILoggingConnector.js.map +1 -0
- package/dist/es/models/ILoggingLevelsConfig.js +2 -0
- package/dist/es/models/ILoggingLevelsConfig.js.map +1 -0
- package/dist/es/models/IMultiLoggingConnectorConstructorOptions.js +2 -0
- package/dist/es/models/IMultiLoggingConnectorConstructorOptions.js.map +1 -0
- package/dist/es/models/api/ILoggingCreateRequest.js +2 -0
- package/dist/es/models/api/ILoggingCreateRequest.js.map +1 -0
- package/dist/es/models/api/ILoggingListRequest.js +2 -0
- package/dist/es/models/api/ILoggingListRequest.js.map +1 -0
- package/dist/es/models/api/ILoggingListResponse.js +2 -0
- package/dist/es/models/api/ILoggingListResponse.js.map +1 -0
- package/dist/es/models/logLevel.js +29 -0
- package/dist/es/models/logLevel.js.map +1 -0
- package/dist/types/connectors/multiLoggingConnector.d.ts +8 -3
- package/dist/types/connectors/silentLoggingConnector.d.ts +7 -2
- package/dist/types/factories/loggingConnectorFactory.d.ts +1 -1
- package/dist/types/helpers/logEntryHelper.d.ts +1 -1
- package/dist/types/index.d.ts +13 -13
- package/dist/types/models/ILogEntry.d.ts +1 -1
- package/dist/types/models/ILoggingComponent.d.ts +2 -2
- package/dist/types/models/ILoggingConnector.d.ts +1 -1
- package/dist/types/models/ILoggingLevelsConfig.d.ts +1 -1
- package/dist/types/models/IMultiLoggingConnectorConstructorOptions.d.ts +1 -1
- package/dist/types/models/api/ILoggingCreateRequest.d.ts +1 -1
- package/dist/types/models/api/ILoggingListRequest.d.ts +1 -1
- package/dist/types/models/api/ILoggingListResponse.d.ts +1 -1
- package/dist/types/models/logLevel.d.ts +27 -2
- package/docs/reference/classes/LogEntryHelper.md +2 -2
- package/docs/reference/classes/MultiLoggingConnector.md +18 -0
- package/docs/reference/classes/SilentLoggingConnector.md +18 -0
- package/docs/reference/index.md +1 -0
- package/docs/reference/interfaces/ILoggingComponent.md +0 -8
- package/docs/reference/interfaces/ILoggingConnector.md +0 -8
- package/docs/reference/type-aliases/LogLevel.md +2 -2
- package/docs/reference/variables/LogLevel.md +37 -0
- package/package.json +33 -7
- package/dist/cjs/index.cjs +0 -152
- package/dist/esm/index.mjs +0 -147
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Guards, Is } from "@twin.org/core";
|
|
4
|
+
import { LoggingConnectorFactory } from "../factories/loggingConnectorFactory.js";
|
|
5
|
+
import { LogLevel } from "../models/logLevel.js";
|
|
6
|
+
/**
|
|
7
|
+
* Class for performing logging operations on multiple connectors.
|
|
8
|
+
*/
|
|
9
|
+
export class MultiLoggingConnector {
|
|
10
|
+
/**
|
|
11
|
+
* The namespace for the logging connector.
|
|
12
|
+
*/
|
|
13
|
+
static NAMESPACE = "multi";
|
|
14
|
+
/**
|
|
15
|
+
* Runtime name for the class.
|
|
16
|
+
*/
|
|
17
|
+
static CLASS_NAME = "MultiLoggingConnector";
|
|
18
|
+
/**
|
|
19
|
+
* The connectors to send the log entries to.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
_loggingConnectors;
|
|
23
|
+
/**
|
|
24
|
+
* The log levels to display, will default to all.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
_levels;
|
|
28
|
+
/**
|
|
29
|
+
* Create a new instance of MultiLoggingConnector.
|
|
30
|
+
* @param options The options for the connector.
|
|
31
|
+
*/
|
|
32
|
+
constructor(options) {
|
|
33
|
+
Guards.object(MultiLoggingConnector.CLASS_NAME, "options", options);
|
|
34
|
+
Guards.arrayValue(MultiLoggingConnector.CLASS_NAME, "options.loggingConnectorTypes", options.loggingConnectorTypes);
|
|
35
|
+
this._levels = options?.config?.levels ?? Object.values(LogLevel);
|
|
36
|
+
this._loggingConnectors = options.loggingConnectorTypes.map(t => LoggingConnectorFactory.get(t));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns the class name of the component.
|
|
40
|
+
* @returns The class name of the component.
|
|
41
|
+
*/
|
|
42
|
+
className() {
|
|
43
|
+
return MultiLoggingConnector.CLASS_NAME;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Log an entry to the connector.
|
|
47
|
+
* @param logEntry The entry to log.
|
|
48
|
+
* @returns Nothing.
|
|
49
|
+
*/
|
|
50
|
+
async log(logEntry) {
|
|
51
|
+
Guards.object(MultiLoggingConnector.CLASS_NAME, "logEntry", logEntry);
|
|
52
|
+
if (this._levels.includes(logEntry.level)) {
|
|
53
|
+
logEntry.ts ??= Date.now();
|
|
54
|
+
await Promise.allSettled(this._loggingConnectors.map(async (loggingConnector) => loggingConnector.log(logEntry)));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Query the log entries.
|
|
59
|
+
* @param conditions The conditions to match for the entities.
|
|
60
|
+
* @param sortProperties The optional sort order.
|
|
61
|
+
* @param properties The optional keys to return, defaults to all.
|
|
62
|
+
* @param cursor The cursor to request the next chunk of entities.
|
|
63
|
+
* @param limit Limit the number of entities to return.
|
|
64
|
+
* @returns All the entities for the storage matching the conditions,
|
|
65
|
+
* and a cursor which can be used to request more entities.
|
|
66
|
+
*/
|
|
67
|
+
async query(conditions, sortProperties, properties, cursor, limit) {
|
|
68
|
+
// See if we can find a connector that supports querying.
|
|
69
|
+
// If it throws anything other than not implemented, we should throw it.
|
|
70
|
+
for (const loggingConnector of this._loggingConnectors) {
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
72
|
+
if (Is.function(loggingConnector.query)) {
|
|
73
|
+
return loggingConnector.query(conditions, sortProperties, properties, cursor, limit);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
entities: []
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=multiLoggingConnector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiLoggingConnector.js","sourceRoot":"","sources":["../../../src/connectors/multiLoggingConnector.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAG5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAIlF,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;GAEG;AACH,MAAM,OAAO,qBAAqB;IACjC;;OAEG;IACI,MAAM,CAAU,SAAS,GAAW,OAAO,CAAC;IAEnD;;OAEG;IACI,MAAM,CAAU,UAAU,2BAA2C;IAE5E;;;OAGG;IACc,kBAAkB,CAAsB;IAEzD;;;OAGG;IACc,OAAO,CAAa;IAErC;;;OAGG;IACH,YAAY,OAAiD;QAC5D,MAAM,CAAC,MAAM,CAAC,qBAAqB,CAAC,UAAU,aAAmB,OAAO,CAAC,CAAC;QAC1E,MAAM,CAAC,UAAU,CAChB,qBAAqB,CAAC,UAAU,mCAEhC,OAAO,CAAC,qBAAqB,CAC7B,CAAC;QACF,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClE,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAC/D,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC,CAC9B,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,qBAAqB,CAAC,UAAU,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,GAAG,CAAC,QAAmB;QACnC,MAAM,CAAC,MAAM,CAAY,qBAAqB,CAAC,UAAU,cAAoB,QAAQ,CAAC,CAAC;QAEvF,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3C,QAAQ,CAAC,EAAE,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC;YAE3B,MAAM,OAAO,CAAC,UAAU,CACvB,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,KAAK,EAAC,gBAAgB,EAAC,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CACrF,CAAC;QACH,CAAC;IACF,CAAC;IAED;;;;;;;;;OASG;IACI,KAAK,CAAC,KAAK,CACjB,UAAuC,EACvC,cAGG,EACH,UAAgC,EAChC,MAAe,EACf,KAAc;QAWd,yDAAyD;QACzD,wEAAwE;QACxE,KAAK,MAAM,gBAAgB,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACxD,6DAA6D;YAC7D,IAAI,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzC,OAAO,gBAAgB,CAAC,KAAK,CAAC,UAAU,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;YACtF,CAAC;QACF,CAAC;QAED,OAAO;YACN,QAAQ,EAAE,EAAE;SACZ,CAAC;IACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Guards, Is } from \"@twin.org/core\";\nimport type { EntityCondition, SortDirection } from \"@twin.org/entity\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { LoggingConnectorFactory } from \"../factories/loggingConnectorFactory.js\";\nimport type { ILogEntry } from \"../models/ILogEntry.js\";\nimport type { ILoggingConnector } from \"../models/ILoggingConnector.js\";\nimport type { IMultiLoggingConnectorConstructorOptions } from \"../models/IMultiLoggingConnectorConstructorOptions.js\";\nimport { LogLevel } from \"../models/logLevel.js\";\n\n/**\n * Class for performing logging operations on multiple connectors.\n */\nexport class MultiLoggingConnector implements ILoggingConnector {\n\t/**\n\t * The namespace for the logging connector.\n\t */\n\tpublic static readonly NAMESPACE: string = \"multi\";\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<MultiLoggingConnector>();\n\n\t/**\n\t * The connectors to send the log entries to.\n\t * @internal\n\t */\n\tprivate readonly _loggingConnectors: ILoggingConnector[];\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 * Create a new instance of MultiLoggingConnector.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options: IMultiLoggingConnectorConstructorOptions) {\n\t\tGuards.object(MultiLoggingConnector.CLASS_NAME, nameof(options), options);\n\t\tGuards.arrayValue(\n\t\t\tMultiLoggingConnector.CLASS_NAME,\n\t\t\tnameof(options.loggingConnectorTypes),\n\t\t\toptions.loggingConnectorTypes\n\t\t);\n\t\tthis._levels = options?.config?.levels ?? Object.values(LogLevel);\n\t\tthis._loggingConnectors = options.loggingConnectorTypes.map(t =>\n\t\t\tLoggingConnectorFactory.get(t)\n\t\t);\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 MultiLoggingConnector.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>(MultiLoggingConnector.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\tawait Promise.allSettled(\n\t\t\t\tthis._loggingConnectors.map(async loggingConnector => loggingConnector.log(logEntry))\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Query the log entries.\n\t * @param conditions The conditions to match for the entities.\n\t * @param sortProperties The optional sort order.\n\t * @param properties The optional keys to return, defaults to all.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t */\n\tpublic async query(\n\t\tconditions?: EntityCondition<ILogEntry>,\n\t\tsortProperties?: {\n\t\t\tproperty: keyof Omit<ILogEntry, \"error\" | \"data\">;\n\t\t\tsortDirection: SortDirection;\n\t\t}[],\n\t\tproperties?: (keyof ILogEntry)[],\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The entities, which can be partial if a limited keys list was provided.\n\t\t */\n\t\tentities: Partial<ILogEntry>[];\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more entities.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\t// See if we can find a connector that supports querying.\n\t\t// If it throws anything other than not implemented, we should throw it.\n\t\tfor (const loggingConnector of this._loggingConnectors) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\t\t\tif (Is.function(loggingConnector.query)) {\n\t\t\t\treturn loggingConnector.query(conditions, sortProperties, properties, cursor, limit);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tentities: []\n\t\t};\n\t}\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class for performing logging operations to nowhere.
|
|
3
|
+
*/
|
|
4
|
+
export class SilentLoggingConnector {
|
|
5
|
+
/**
|
|
6
|
+
* The namespace for the logging connector.
|
|
7
|
+
*/
|
|
8
|
+
static NAMESPACE = "silent";
|
|
9
|
+
/**
|
|
10
|
+
* Runtime name for the class.
|
|
11
|
+
*/
|
|
12
|
+
static CLASS_NAME = "SilentLoggingConnector";
|
|
13
|
+
/**
|
|
14
|
+
* Returns the class name of the component.
|
|
15
|
+
* @returns The class name of the component.
|
|
16
|
+
*/
|
|
17
|
+
className() {
|
|
18
|
+
return SilentLoggingConnector.CLASS_NAME;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Log an entry to the connector.
|
|
22
|
+
* @param logEntry The entry to log.
|
|
23
|
+
* @returns Nothing.
|
|
24
|
+
*/
|
|
25
|
+
async log(logEntry) { }
|
|
26
|
+
/**
|
|
27
|
+
* Query the log entries.
|
|
28
|
+
* @param conditions The conditions to match for the entities.
|
|
29
|
+
* @param sortProperties The optional sort order.
|
|
30
|
+
* @param properties The optional keys to return, defaults to all.
|
|
31
|
+
* @param cursor The cursor to request the next chunk of entities.
|
|
32
|
+
* @param limit Limit the number of entities to return.
|
|
33
|
+
* @returns All the entities for the storage matching the conditions,
|
|
34
|
+
* and a cursor which can be used to request more entities.
|
|
35
|
+
*/
|
|
36
|
+
async query(conditions, sortProperties, properties, cursor, limit) {
|
|
37
|
+
return {
|
|
38
|
+
entities: []
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=silentLoggingConnector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"silentLoggingConnector.js","sourceRoot":"","sources":["../../../src/connectors/silentLoggingConnector.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAClC;;OAEG;IACI,MAAM,CAAU,SAAS,GAAW,QAAQ,CAAC;IAEpD;;OAEG;IACI,MAAM,CAAU,UAAU,4BAA4C;IAE7E;;;OAGG;IACI,SAAS;QACf,OAAO,sBAAsB,CAAC,UAAU,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,GAAG,CAAC,QAAmB,IAAkB,CAAC;IAEvD;;;;;;;;;OASG;IACI,KAAK,CAAC,KAAK,CACjB,UAAuC,EACvC,cAGG,EACH,UAAgC,EAChC,MAAe,EACf,KAAc;QAWd,OAAO;YACN,QAAQ,EAAE,EAAE;SACZ,CAAC;IACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { EntityCondition, SortDirection } from \"@twin.org/entity\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { ILogEntry } from \"../models/ILogEntry.js\";\nimport type { ILoggingConnector } from \"../models/ILoggingConnector.js\";\n\n/**\n * Class for performing logging operations to nowhere.\n */\nexport class SilentLoggingConnector implements ILoggingConnector {\n\t/**\n\t * The namespace for the logging connector.\n\t */\n\tpublic static readonly NAMESPACE: string = \"silent\";\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<SilentLoggingConnector>();\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 SilentLoggingConnector.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\n\t/**\n\t * Query the log entries.\n\t * @param conditions The conditions to match for the entities.\n\t * @param sortProperties The optional sort order.\n\t * @param properties The optional keys to return, defaults to all.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t */\n\tpublic async query(\n\t\tconditions?: EntityCondition<ILogEntry>,\n\t\tsortProperties?: {\n\t\t\tproperty: keyof Omit<ILogEntry, \"error\" | \"data\">;\n\t\t\tsortDirection: SortDirection;\n\t\t}[],\n\t\tproperties?: (keyof ILogEntry)[],\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The entities, which can be partial if a limited keys list was provided.\n\t\t */\n\t\tentities: Partial<ILogEntry>[];\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more entities.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\treturn {\n\t\t\tentities: []\n\t\t};\n\t}\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Factory } from "@twin.org/core";
|
|
4
|
+
/**
|
|
5
|
+
* Factory for creating logging connectors.
|
|
6
|
+
*/
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
8
|
+
export const LoggingConnectorFactory = Factory.createFactory("logging");
|
|
9
|
+
//# sourceMappingURL=loggingConnectorFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loggingConnectorFactory.js","sourceRoot":"","sources":["../../../src/factories/loggingConnectorFactory.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,uBAAuB,GAAG,OAAO,CAAC,aAAa,CAAoB,SAAS,CAAC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Factory } from \"@twin.org/core\";\nimport type { ILoggingConnector } from \"../models/ILoggingConnector.js\";\n\n/**\n * Factory for creating logging connectors.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const LoggingConnectorFactory = Factory.createFactory<ILoggingConnector>(\"logging\");\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { I18n, Is, StringHelper } from "@twin.org/core";
|
|
4
|
+
/**
|
|
5
|
+
* Helper class for log entry operations.
|
|
6
|
+
*/
|
|
7
|
+
export class LogEntryHelper {
|
|
8
|
+
/**
|
|
9
|
+
* Translate the log entry.
|
|
10
|
+
* @param logEntry The log entry.
|
|
11
|
+
* @returns The translated log entry if a translation can be found.
|
|
12
|
+
*/
|
|
13
|
+
static translate(logEntry) {
|
|
14
|
+
if (Is.stringValue(logEntry.level) && Is.stringValue(logEntry.source)) {
|
|
15
|
+
const sourceMessage = `${logEntry.level}.${StringHelper.camelCase(logEntry.source)}.${logEntry.message}`;
|
|
16
|
+
if (I18n.hasMessage(sourceMessage)) {
|
|
17
|
+
return I18n.formatMessage(sourceMessage, logEntry.data);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (Is.stringValue(logEntry.source)) {
|
|
21
|
+
const sourceMessage = `${StringHelper.camelCase(logEntry.source)}.${logEntry.message}`;
|
|
22
|
+
if (I18n.hasMessage(sourceMessage)) {
|
|
23
|
+
return I18n.formatMessage(sourceMessage, logEntry.data);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (I18n.hasMessage(logEntry.message)) {
|
|
27
|
+
return I18n.formatMessage(logEntry.message, logEntry.data);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=logEntryHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logEntryHelper.js","sourceRoot":"","sources":["../../../src/helpers/logEntryHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGxD;;GAEG;AACH,MAAM,OAAO,cAAc;IAC1B;;;;OAIG;IACI,MAAM,CAAC,SAAS,CAAC,QAAmB;QAC1C,IAAI,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACvE,MAAM,aAAa,GAAG,GAAG,QAAQ,CAAC,KAAK,IAAI,YAAY,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;YACzG,IAAI,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;gBACpC,OAAO,IAAI,CAAC,aAAa,CACxB,aAAa,EACb,QAAQ,CAAC,IAER,CACD,CAAC;YACH,CAAC;QACF,CAAC;QAED,IAAI,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACrC,MAAM,aAAa,GAAG,GAAG,YAAY,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;YACvF,IAAI,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;gBACpC,OAAO,IAAI,CAAC,aAAa,CACxB,aAAa,EACb,QAAQ,CAAC,IAER,CACD,CAAC;YACH,CAAC;QACF,CAAC;QAED,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,OAAO,IAAI,CAAC,aAAa,CACxB,QAAQ,CAAC,OAAO,EAChB,QAAQ,CAAC,IAER,CACD,CAAC;QACH,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { I18n, Is, StringHelper } from \"@twin.org/core\";\nimport type { ILogEntry } from \"../models/ILogEntry.js\";\n\n/**\n * Helper class for log entry operations.\n */\nexport class LogEntryHelper {\n\t/**\n\t * Translate the log entry.\n\t * @param logEntry The log entry.\n\t * @returns The translated log entry if a translation can be found.\n\t */\n\tpublic static translate(logEntry: ILogEntry): string | undefined {\n\t\tif (Is.stringValue(logEntry.level) && Is.stringValue(logEntry.source)) {\n\t\t\tconst sourceMessage = `${logEntry.level}.${StringHelper.camelCase(logEntry.source)}.${logEntry.message}`;\n\t\t\tif (I18n.hasMessage(sourceMessage)) {\n\t\t\t\treturn I18n.formatMessage(\n\t\t\t\t\tsourceMessage,\n\t\t\t\t\tlogEntry.data as {\n\t\t\t\t\t\t[key: string]: unknown;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (Is.stringValue(logEntry.source)) {\n\t\t\tconst sourceMessage = `${StringHelper.camelCase(logEntry.source)}.${logEntry.message}`;\n\t\t\tif (I18n.hasMessage(sourceMessage)) {\n\t\t\t\treturn I18n.formatMessage(\n\t\t\t\t\tsourceMessage,\n\t\t\t\t\tlogEntry.data as {\n\t\t\t\t\t\t[key: string]: unknown;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (I18n.hasMessage(logEntry.message)) {\n\t\t\treturn I18n.formatMessage(\n\t\t\t\tlogEntry.message,\n\t\t\t\tlogEntry.data as {\n\t\t\t\t\t[key: string]: unknown;\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,16 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
export * from "./connectors/multiLoggingConnector.js";
|
|
4
|
+
export * from "./connectors/silentLoggingConnector.js";
|
|
5
|
+
export * from "./factories/loggingConnectorFactory.js";
|
|
6
|
+
export * from "./helpers/logEntryHelper.js";
|
|
7
|
+
export * from "./models/api/ILoggingCreateRequest.js";
|
|
8
|
+
export * from "./models/api/ILoggingListRequest.js";
|
|
9
|
+
export * from "./models/api/ILoggingListResponse.js";
|
|
10
|
+
export * from "./models/ILogEntry.js";
|
|
11
|
+
export * from "./models/ILoggingComponent.js";
|
|
12
|
+
export * from "./models/ILoggingConnector.js";
|
|
13
|
+
export * from "./models/ILoggingLevelsConfig.js";
|
|
14
|
+
export * from "./models/IMultiLoggingConnectorConstructorOptions.js";
|
|
15
|
+
export * from "./models/logLevel.js";
|
|
16
|
+
//# 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,uCAAuC,CAAC;AACtD,cAAc,wCAAwC,CAAC;AACvD,cAAc,wCAAwC,CAAC;AACvD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uCAAuC,CAAC;AACtD,cAAc,qCAAqC,CAAC;AACpD,cAAc,sCAAsC,CAAC;AACrD,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,sDAAsD,CAAC;AACrE,cAAc,sBAAsB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./connectors/multiLoggingConnector.js\";\nexport * from \"./connectors/silentLoggingConnector.js\";\nexport * from \"./factories/loggingConnectorFactory.js\";\nexport * from \"./helpers/logEntryHelper.js\";\nexport * from \"./models/api/ILoggingCreateRequest.js\";\nexport * from \"./models/api/ILoggingListRequest.js\";\nexport * from \"./models/api/ILoggingListResponse.js\";\nexport * from \"./models/ILogEntry.js\";\nexport * from \"./models/ILoggingComponent.js\";\nexport * from \"./models/ILoggingConnector.js\";\nexport * from \"./models/ILoggingLevelsConfig.js\";\nexport * from \"./models/IMultiLoggingConnectorConstructorOptions.js\";\nexport * from \"./models/logLevel.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ILogEntry.js","sourceRoot":"","sources":["../../../src/models/ILogEntry.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IError } from \"@twin.org/core\";\nimport type { LogLevel } from \"./logLevel.js\";\n\n/**\n * Interface describing a log entry.\n */\nexport interface ILogEntry {\n\t/**\n\t * The level of the error being logged.\n\t */\n\tlevel: LogLevel;\n\n\t/**\n\t * The source of the log entry.\n\t */\n\tsource: string;\n\n\t/**\n\t * The timestamp of the log entry, if left blank will be populated by the connector.\n\t */\n\tts?: number;\n\n\t/**\n\t * The message.\n\t */\n\tmessage: string;\n\n\t/**\n\t * Optional error details.\n\t */\n\terror?: IError;\n\n\t/**\n\t * Optional data for the message.\n\t */\n\tdata?: { [key: string]: unknown };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ILoggingComponent.js","sourceRoot":"","sources":["../../../src/models/ILoggingComponent.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IComponent } from \"@twin.org/core\";\nimport type { ILogEntry } from \"./ILogEntry.js\";\nimport type { LogLevel } from \"./logLevel.js\";\n\n/**\n * Interface describing a logging contract.\n */\nexport interface ILoggingComponent extends IComponent {\n\t/**\n\t * Log an entry to the component.\n\t * @param logEntry The entry to log.\n\t * @returns Nothing.\n\t */\n\tlog(logEntry: ILogEntry): Promise<void>;\n\n\t/**\n\t * Query the log entries.\n\t * @param level The level of the log entries.\n\t * @param source The source of the log entries.\n\t * @param timeStart The inclusive time as the start of the log entries.\n\t * @param timeEnd The inclusive time as the end of the log entries.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t */\n\tquery(\n\t\tlevel?: LogLevel,\n\t\tsource?: string,\n\t\ttimeStart?: number,\n\t\ttimeEnd?: number,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The entities, which can be partial if a limited keys list was provided.\n\t\t */\n\t\tentities: ILogEntry[];\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more entities.\n\t\t */\n\t\tcursor?: string;\n\t}>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ILoggingConnector.js","sourceRoot":"","sources":["../../../src/models/ILoggingConnector.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IComponent } from \"@twin.org/core\";\nimport type { EntityCondition, SortDirection } from \"@twin.org/entity\";\nimport type { ILogEntry } from \"./ILogEntry.js\";\n\n/**\n * Interface describing a logging connector.\n */\nexport interface ILoggingConnector extends IComponent {\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\tlog(logEntry: ILogEntry): Promise<void>;\n\n\t/**\n\t * Query the log entries.\n\t * @param conditions The conditions to match for the entities.\n\t * @param sortProperties The optional sort order.\n\t * @param properties The optional keys to return, defaults to all.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t */\n\tquery?(\n\t\tconditions?: EntityCondition<ILogEntry>,\n\t\tsortProperties?: {\n\t\t\tproperty: keyof Omit<ILogEntry, \"error\" | \"data\">;\n\t\t\tsortDirection: SortDirection;\n\t\t}[],\n\t\tproperties?: (keyof ILogEntry)[],\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The entities, which can be partial if a limited keys list was provided.\n\t\t */\n\t\tentities: Partial<ILogEntry>[];\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more entities.\n\t\t */\n\t\tcursor?: string;\n\t}>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ILoggingLevelsConfig.js","sourceRoot":"","sources":["../../../src/models/ILoggingLevelsConfig.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { LogLevel } from \"./logLevel.js\";\n\n/**\n * Configuration for the logging connectors to specify the levels to display.\n */\nexport interface ILoggingLevelsConfig {\n\t/**\n\t * The log levels to display, will default to all.\n\t */\n\tlevels?: LogLevel[];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IMultiLoggingConnectorConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IMultiLoggingConnectorConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ILoggingLevelsConfig } from \"../models/ILoggingLevelsConfig.js\";\n\n/**\n * Options for the multi logging connector.\n */\nexport interface IMultiLoggingConnectorConstructorOptions {\n\t/**\n\t * The logging connectors to multiplex.\n\t */\n\tloggingConnectorTypes: string[];\n\n\t/**\n\t * The configuration for the logging connector.\n\t */\n\tconfig?: ILoggingLevelsConfig;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ILoggingCreateRequest.js","sourceRoot":"","sources":["../../../../src/models/api/ILoggingCreateRequest.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ILogEntry } from \"../ILogEntry.js\";\n\n/**\n * Create a new log entry.\n */\nexport interface ILoggingCreateRequest {\n\t/**\n\t * The data to be used in the create.\n\t */\n\tbody: ILogEntry;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ILoggingListRequest.js","sourceRoot":"","sources":["../../../../src/models/api/ILoggingListRequest.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { LogLevel } from \"../logLevel.js\";\n\n/**\n * Get the a list of the log entries.\n */\nexport interface ILoggingListRequest {\n\t/**\n\t * The query parameters.\n\t */\n\tquery?: {\n\t\t/**\n\t\t * The level of the log entries to retrieve.\n\t\t */\n\t\tlevel?: LogLevel;\n\n\t\t/**\n\t\t * The source of the log entries to retrieve.\n\t\t */\n\t\tsource?: string;\n\n\t\t/**\n\t\t * The start time of the metrics to retrieve as a timestamp in ms.\n\t\t */\n\t\ttimeStart?: number | string;\n\n\t\t/**\n\t\t * The end time of the metrics to retrieve as a timestamp in ms.\n\t\t */\n\t\ttimeEnd?: number | string;\n\n\t\t/**\n\t\t * The optional cursor to get next chunk.\n\t\t */\n\t\tcursor?: string;\n\n\t\t/**\n\t\t * Limit the number of entities to return.\n\t\t */\n\t\tlimit?: string;\n\t};\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ILoggingListResponse.js","sourceRoot":"","sources":["../../../../src/models/api/ILoggingListResponse.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ILogEntry } from \"../ILogEntry.js\";\n\n/**\n * Response for log entry list request.\n */\nexport interface ILoggingListResponse {\n\t/**\n\t * The response payload.\n\t */\n\tbody: {\n\t\t/**\n\t\t * The entities, which can be partial if a limited keys list was provided.\n\t\t */\n\t\tentities: ILogEntry[];\n\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more entities.\n\t\t */\n\t\tcursor?: string;\n\t};\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/**
|
|
4
|
+
* The log levels.
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
export const LogLevel = {
|
|
8
|
+
/**
|
|
9
|
+
* Info.
|
|
10
|
+
*/
|
|
11
|
+
Info: "info",
|
|
12
|
+
/**
|
|
13
|
+
* Error.
|
|
14
|
+
*/
|
|
15
|
+
Error: "error",
|
|
16
|
+
/**
|
|
17
|
+
* Warn.
|
|
18
|
+
*/
|
|
19
|
+
Warn: "warn",
|
|
20
|
+
/**
|
|
21
|
+
* Trace.
|
|
22
|
+
*/
|
|
23
|
+
Trace: "trace",
|
|
24
|
+
/**
|
|
25
|
+
* Debug.
|
|
26
|
+
*/
|
|
27
|
+
Debug: "debug"
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=logLevel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logLevel.js","sourceRoot":"","sources":["../../../src/models/logLevel.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB;;OAEG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,KAAK,EAAE,OAAO;IAEd;;OAEG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,KAAK,EAAE,OAAO;IAEd;;OAEG;IACH,KAAK,EAAE,OAAO;CACL,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The log levels.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const LogLevel = {\n\t/**\n\t * Info.\n\t */\n\tInfo: \"info\",\n\n\t/**\n\t * Error.\n\t */\n\tError: \"error\",\n\n\t/**\n\t * Warn.\n\t */\n\tWarn: \"warn\",\n\n\t/**\n\t * Trace.\n\t */\n\tTrace: \"trace\",\n\n\t/**\n\t * Debug.\n\t */\n\tDebug: \"debug\"\n} as const;\n\n/**\n * The log levels.\n */\nexport type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { EntityCondition, SortDirection } from "@twin.org/entity";
|
|
2
|
-
import type { ILogEntry } from "../models/ILogEntry";
|
|
3
|
-
import type { ILoggingConnector } from "../models/ILoggingConnector";
|
|
4
|
-
import type { IMultiLoggingConnectorConstructorOptions } from "../models/IMultiLoggingConnectorConstructorOptions";
|
|
2
|
+
import type { ILogEntry } from "../models/ILogEntry.js";
|
|
3
|
+
import type { ILoggingConnector } from "../models/ILoggingConnector.js";
|
|
4
|
+
import type { IMultiLoggingConnectorConstructorOptions } from "../models/IMultiLoggingConnectorConstructorOptions.js";
|
|
5
5
|
/**
|
|
6
6
|
* Class for performing logging operations on multiple connectors.
|
|
7
7
|
*/
|
|
@@ -19,6 +19,11 @@ export declare class MultiLoggingConnector implements ILoggingConnector {
|
|
|
19
19
|
* @param options The options for the connector.
|
|
20
20
|
*/
|
|
21
21
|
constructor(options: IMultiLoggingConnectorConstructorOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Returns the class name of the component.
|
|
24
|
+
* @returns The class name of the component.
|
|
25
|
+
*/
|
|
26
|
+
className(): string;
|
|
22
27
|
/**
|
|
23
28
|
* Log an entry to the connector.
|
|
24
29
|
* @param logEntry The entry to log.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EntityCondition, SortDirection } from "@twin.org/entity";
|
|
2
|
-
import type { ILogEntry } from "../models/ILogEntry";
|
|
3
|
-
import type { ILoggingConnector } from "../models/ILoggingConnector";
|
|
2
|
+
import type { ILogEntry } from "../models/ILogEntry.js";
|
|
3
|
+
import type { ILoggingConnector } from "../models/ILoggingConnector.js";
|
|
4
4
|
/**
|
|
5
5
|
* Class for performing logging operations to nowhere.
|
|
6
6
|
*/
|
|
@@ -13,6 +13,11 @@ export declare class SilentLoggingConnector implements ILoggingConnector {
|
|
|
13
13
|
* Runtime name for the class.
|
|
14
14
|
*/
|
|
15
15
|
static readonly CLASS_NAME: string;
|
|
16
|
+
/**
|
|
17
|
+
* Returns the class name of the component.
|
|
18
|
+
* @returns The class name of the component.
|
|
19
|
+
*/
|
|
20
|
+
className(): string;
|
|
16
21
|
/**
|
|
17
22
|
* Log an entry to the connector.
|
|
18
23
|
* @param logEntry The entry to log.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export * from "./connectors/multiLoggingConnector";
|
|
2
|
-
export * from "./connectors/silentLoggingConnector";
|
|
3
|
-
export * from "./factories/loggingConnectorFactory";
|
|
4
|
-
export * from "./helpers/logEntryHelper";
|
|
5
|
-
export * from "./models/api/ILoggingCreateRequest";
|
|
6
|
-
export * from "./models/api/ILoggingListRequest";
|
|
7
|
-
export * from "./models/api/ILoggingListResponse";
|
|
8
|
-
export * from "./models/ILogEntry";
|
|
9
|
-
export * from "./models/ILoggingComponent";
|
|
10
|
-
export * from "./models/ILoggingConnector";
|
|
11
|
-
export * from "./models/ILoggingLevelsConfig";
|
|
12
|
-
export * from "./models/IMultiLoggingConnectorConstructorOptions";
|
|
13
|
-
export * from "./models/logLevel";
|
|
1
|
+
export * from "./connectors/multiLoggingConnector.js";
|
|
2
|
+
export * from "./connectors/silentLoggingConnector.js";
|
|
3
|
+
export * from "./factories/loggingConnectorFactory.js";
|
|
4
|
+
export * from "./helpers/logEntryHelper.js";
|
|
5
|
+
export * from "./models/api/ILoggingCreateRequest.js";
|
|
6
|
+
export * from "./models/api/ILoggingListRequest.js";
|
|
7
|
+
export * from "./models/api/ILoggingListResponse.js";
|
|
8
|
+
export * from "./models/ILogEntry.js";
|
|
9
|
+
export * from "./models/ILoggingComponent.js";
|
|
10
|
+
export * from "./models/ILoggingConnector.js";
|
|
11
|
+
export * from "./models/ILoggingLevelsConfig.js";
|
|
12
|
+
export * from "./models/IMultiLoggingConnectorConstructorOptions.js";
|
|
13
|
+
export * from "./models/logLevel.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IComponent } from "@twin.org/core";
|
|
2
|
-
import type { ILogEntry } from "./ILogEntry";
|
|
3
|
-
import type { LogLevel } from "./logLevel";
|
|
2
|
+
import type { ILogEntry } from "./ILogEntry.js";
|
|
3
|
+
import type { LogLevel } from "./logLevel.js";
|
|
4
4
|
/**
|
|
5
5
|
* Interface describing a logging contract.
|
|
6
6
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IComponent } from "@twin.org/core";
|
|
2
2
|
import type { EntityCondition, SortDirection } from "@twin.org/entity";
|
|
3
|
-
import type { ILogEntry } from "./ILogEntry";
|
|
3
|
+
import type { ILogEntry } from "./ILogEntry.js";
|
|
4
4
|
/**
|
|
5
5
|
* Interface describing a logging connector.
|
|
6
6
|
*/
|
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The log levels.
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
4
|
+
export declare const LogLevel: {
|
|
5
|
+
/**
|
|
6
|
+
* Info.
|
|
7
|
+
*/
|
|
8
|
+
readonly Info: "info";
|
|
9
|
+
/**
|
|
10
|
+
* Error.
|
|
11
|
+
*/
|
|
12
|
+
readonly Error: "error";
|
|
13
|
+
/**
|
|
14
|
+
* Warn.
|
|
15
|
+
*/
|
|
16
|
+
readonly Warn: "warn";
|
|
17
|
+
/**
|
|
18
|
+
* Trace.
|
|
19
|
+
*/
|
|
20
|
+
readonly Trace: "trace";
|
|
21
|
+
/**
|
|
22
|
+
* Debug.
|
|
23
|
+
*/
|
|
24
|
+
readonly Debug: "debug";
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The log levels.
|
|
28
|
+
*/
|
|
29
|
+
export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
|
|
@@ -16,7 +16,7 @@ Helper class for log entry operations.
|
|
|
16
16
|
|
|
17
17
|
### translate()
|
|
18
18
|
|
|
19
|
-
> `static` **translate**(`logEntry`): `
|
|
19
|
+
> `static` **translate**(`logEntry`): `string` \| `undefined`
|
|
20
20
|
|
|
21
21
|
Translate the log entry.
|
|
22
22
|
|
|
@@ -30,6 +30,6 @@ The log entry.
|
|
|
30
30
|
|
|
31
31
|
#### Returns
|
|
32
32
|
|
|
33
|
-
`
|
|
33
|
+
`string` \| `undefined`
|
|
34
34
|
|
|
35
35
|
The translated log entry if a translation can be found.
|
|
@@ -44,6 +44,24 @@ Runtime name for the class.
|
|
|
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`\>
|
|
@@ -34,6 +34,24 @@ Runtime name for the class.
|
|
|
34
34
|
|
|
35
35
|
## Methods
|
|
36
36
|
|
|
37
|
+
### className()
|
|
38
|
+
|
|
39
|
+
> **className**(): `string`
|
|
40
|
+
|
|
41
|
+
Returns the class name of the component.
|
|
42
|
+
|
|
43
|
+
#### Returns
|
|
44
|
+
|
|
45
|
+
`string`
|
|
46
|
+
|
|
47
|
+
The class name of the component.
|
|
48
|
+
|
|
49
|
+
#### Implementation of
|
|
50
|
+
|
|
51
|
+
`ILoggingConnector.className`
|
|
52
|
+
|
|
53
|
+
***
|
|
54
|
+
|
|
37
55
|
### log()
|
|
38
56
|
|
|
39
57
|
> **log**(`logEntry`): `Promise`\<`void`\>
|
package/docs/reference/index.md
CHANGED
|
@@ -6,14 +6,6 @@ Interface describing a logging contract.
|
|
|
6
6
|
|
|
7
7
|
- `IComponent`
|
|
8
8
|
|
|
9
|
-
## Indexable
|
|
10
|
-
|
|
11
|
-
\[`key`: `string`\]: `any`
|
|
12
|
-
|
|
13
|
-
All methods are optional, so we introduce an index signature to allow
|
|
14
|
-
any additional properties or methods, which removes the TypeScript error where
|
|
15
|
-
the class has no properties in common with the type.
|
|
16
|
-
|
|
17
9
|
## Methods
|
|
18
10
|
|
|
19
11
|
### log()
|
|
@@ -6,14 +6,6 @@ Interface describing a logging connector.
|
|
|
6
6
|
|
|
7
7
|
- `IComponent`
|
|
8
8
|
|
|
9
|
-
## Indexable
|
|
10
|
-
|
|
11
|
-
\[`key`: `string`\]: `any`
|
|
12
|
-
|
|
13
|
-
All methods are optional, so we introduce an index signature to allow
|
|
14
|
-
any additional properties or methods, which removes the TypeScript error where
|
|
15
|
-
the class has no properties in common with the type.
|
|
16
|
-
|
|
17
9
|
## Methods
|
|
18
10
|
|
|
19
11
|
### log()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Variable: LogLevel
|
|
2
|
+
|
|
3
|
+
> `const` **LogLevel**: `object`
|
|
4
|
+
|
|
5
|
+
The log levels.
|
|
6
|
+
|
|
7
|
+
## Type Declaration
|
|
8
|
+
|
|
9
|
+
### Info
|
|
10
|
+
|
|
11
|
+
> `readonly` **Info**: `"info"` = `"info"`
|
|
12
|
+
|
|
13
|
+
Info.
|
|
14
|
+
|
|
15
|
+
### Error
|
|
16
|
+
|
|
17
|
+
> `readonly` **Error**: `"error"` = `"error"`
|
|
18
|
+
|
|
19
|
+
Error.
|
|
20
|
+
|
|
21
|
+
### Warn
|
|
22
|
+
|
|
23
|
+
> `readonly` **Warn**: `"warn"` = `"warn"`
|
|
24
|
+
|
|
25
|
+
Warn.
|
|
26
|
+
|
|
27
|
+
### Trace
|
|
28
|
+
|
|
29
|
+
> `readonly` **Trace**: `"trace"` = `"trace"`
|
|
30
|
+
|
|
31
|
+
Trace.
|
|
32
|
+
|
|
33
|
+
### Debug
|
|
34
|
+
|
|
35
|
+
> `readonly` **Debug**: `"debug"` = `"debug"`
|
|
36
|
+
|
|
37
|
+
Debug.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/logging-models",
|
|
3
|
-
"version": "0.0.2-next.
|
|
3
|
+
"version": "0.0.2-next.4",
|
|
4
4
|
"description": "Models which define the structure of the logging connectors and services",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,25 +13,51 @@
|
|
|
13
13
|
"engines": {
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"clean": "rimraf dist coverage docs/reference",
|
|
18
|
+
"build": "tspc",
|
|
19
|
+
"dev": "nodemon --watch src --ext ts --exec \"npm run build\"",
|
|
20
|
+
"test": "vitest --run --config ./vitest.config.ts --no-cache",
|
|
21
|
+
"test:build": "tspc -p ./tests/tsconfig.json --noEmit",
|
|
22
|
+
"validate-locales": "validate-locales",
|
|
23
|
+
"test:coverage": "vitest --run --coverage --config ./vitest.config.ts --no-cache",
|
|
24
|
+
"docs:clean": "rimraf docs/reference",
|
|
25
|
+
"docs:generate": "typedoc",
|
|
26
|
+
"docs": "npm run docs:clean && npm run docs:generate",
|
|
27
|
+
"dist": "npm run clean && npm run build && npm run validate-locales && npm run test:build && npm run test && npm run docs",
|
|
28
|
+
"dist:no-test": "npm run clean && npm run build && npm run test:build && npm run docs"
|
|
29
|
+
},
|
|
16
30
|
"dependencies": {
|
|
17
31
|
"@twin.org/core": "next",
|
|
18
32
|
"@twin.org/entity": "next",
|
|
19
33
|
"@twin.org/nameof": "next"
|
|
20
34
|
},
|
|
21
|
-
"
|
|
22
|
-
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@twin.org/nameof-transformer": "next",
|
|
37
|
+
"@twin.org/nameof-vitest-plugin": "next",
|
|
38
|
+
"@twin.org/validate-locales": "next",
|
|
39
|
+
"@vitest/coverage-v8": "4.0.8",
|
|
40
|
+
"copyfiles": "2.4.1",
|
|
41
|
+
"nodemon": "3.1.10",
|
|
42
|
+
"rimraf": "6.1.0",
|
|
43
|
+
"ts-patch": "3.3.0",
|
|
44
|
+
"typedoc": "0.28.14",
|
|
45
|
+
"typedoc-plugin-markdown": "4.9.0",
|
|
46
|
+
"typescript": "5.9.3",
|
|
47
|
+
"vitest": "4.0.8"
|
|
48
|
+
},
|
|
49
|
+
"main": "./dist/es/index.js",
|
|
23
50
|
"types": "./dist/types/index.d.ts",
|
|
24
51
|
"exports": {
|
|
25
52
|
".": {
|
|
26
53
|
"types": "./dist/types/index.d.ts",
|
|
27
|
-
"
|
|
28
|
-
"
|
|
54
|
+
"import": "./dist/es/index.js",
|
|
55
|
+
"default": "./dist/es/index.js"
|
|
29
56
|
},
|
|
30
57
|
"./locales/*.json": "./locales/*.json"
|
|
31
58
|
},
|
|
32
59
|
"files": [
|
|
33
|
-
"dist/
|
|
34
|
-
"dist/esm",
|
|
60
|
+
"dist/es",
|
|
35
61
|
"dist/types",
|
|
36
62
|
"locales",
|
|
37
63
|
"docs"
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var core = require('@twin.org/core');
|
|
4
|
-
|
|
5
|
-
// Copyright 2024 IOTA Stiftung.
|
|
6
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
7
|
-
/**
|
|
8
|
-
* Factory for creating logging connectors.
|
|
9
|
-
*/
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
11
|
-
const LoggingConnectorFactory = core.Factory.createFactory("logging");
|
|
12
|
-
|
|
13
|
-
// Copyright 2024 IOTA Stiftung.
|
|
14
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
15
|
-
/**
|
|
16
|
-
* Class for performing logging operations on multiple connectors.
|
|
17
|
-
*/
|
|
18
|
-
class MultiLoggingConnector {
|
|
19
|
-
/**
|
|
20
|
-
* The namespace for the logging connector.
|
|
21
|
-
*/
|
|
22
|
-
static NAMESPACE = "multi";
|
|
23
|
-
/**
|
|
24
|
-
* Runtime name for the class.
|
|
25
|
-
*/
|
|
26
|
-
static CLASS_NAME = "MultiLoggingConnector";
|
|
27
|
-
/**
|
|
28
|
-
* The connectors to send the log entries to.
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
_loggingConnectors;
|
|
32
|
-
/**
|
|
33
|
-
* The log levels to display, will default to all.
|
|
34
|
-
* @internal
|
|
35
|
-
*/
|
|
36
|
-
_levels;
|
|
37
|
-
/**
|
|
38
|
-
* Create a new instance of MultiLoggingConnector.
|
|
39
|
-
* @param options The options for the connector.
|
|
40
|
-
*/
|
|
41
|
-
constructor(options) {
|
|
42
|
-
core.Guards.object(MultiLoggingConnector.CLASS_NAME, "options", options);
|
|
43
|
-
core.Guards.arrayValue(MultiLoggingConnector.CLASS_NAME, "options.loggingConnectorTypes", options.loggingConnectorTypes);
|
|
44
|
-
this._levels = options?.config?.levels ?? ["debug", "info", "warn", "error", "trace"];
|
|
45
|
-
this._loggingConnectors = options.loggingConnectorTypes.map(t => LoggingConnectorFactory.get(t));
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Log an entry to the connector.
|
|
49
|
-
* @param logEntry The entry to log.
|
|
50
|
-
* @returns Nothing.
|
|
51
|
-
*/
|
|
52
|
-
async log(logEntry) {
|
|
53
|
-
core.Guards.object(MultiLoggingConnector.CLASS_NAME, "logEntry", logEntry);
|
|
54
|
-
if (this._levels.includes(logEntry.level)) {
|
|
55
|
-
logEntry.ts ??= Date.now();
|
|
56
|
-
await Promise.allSettled(this._loggingConnectors.map(async (loggingConnector) => loggingConnector.log(logEntry)));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Query the log entries.
|
|
61
|
-
* @param conditions The conditions to match for the entities.
|
|
62
|
-
* @param sortProperties The optional sort order.
|
|
63
|
-
* @param properties The optional keys to return, defaults to all.
|
|
64
|
-
* @param cursor The cursor to request the next chunk of entities.
|
|
65
|
-
* @param limit Limit the number of entities to return.
|
|
66
|
-
* @returns All the entities for the storage matching the conditions,
|
|
67
|
-
* and a cursor which can be used to request more entities.
|
|
68
|
-
*/
|
|
69
|
-
async query(conditions, sortProperties, properties, cursor, limit) {
|
|
70
|
-
// See if we can find a connector that supports querying.
|
|
71
|
-
// If it throws anything other than not implemented, we should throw it.
|
|
72
|
-
for (const loggingConnector of this._loggingConnectors) {
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
74
|
-
if (core.Is.function(loggingConnector.query)) {
|
|
75
|
-
return loggingConnector.query(conditions, sortProperties, properties, cursor, limit);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
entities: []
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Class for performing logging operations to nowhere.
|
|
86
|
-
*/
|
|
87
|
-
class SilentLoggingConnector {
|
|
88
|
-
/**
|
|
89
|
-
* The namespace for the logging connector.
|
|
90
|
-
*/
|
|
91
|
-
static NAMESPACE = "silent";
|
|
92
|
-
/**
|
|
93
|
-
* Runtime name for the class.
|
|
94
|
-
*/
|
|
95
|
-
static CLASS_NAME = "SilentLoggingConnector";
|
|
96
|
-
/**
|
|
97
|
-
* Log an entry to the connector.
|
|
98
|
-
* @param logEntry The entry to log.
|
|
99
|
-
* @returns Nothing.
|
|
100
|
-
*/
|
|
101
|
-
async log(logEntry) { }
|
|
102
|
-
/**
|
|
103
|
-
* Query the log entries.
|
|
104
|
-
* @param conditions The conditions to match for the entities.
|
|
105
|
-
* @param sortProperties The optional sort order.
|
|
106
|
-
* @param properties The optional keys to return, defaults to all.
|
|
107
|
-
* @param cursor The cursor to request the next chunk of entities.
|
|
108
|
-
* @param limit Limit the number of entities to return.
|
|
109
|
-
* @returns All the entities for the storage matching the conditions,
|
|
110
|
-
* and a cursor which can be used to request more entities.
|
|
111
|
-
*/
|
|
112
|
-
async query(conditions, sortProperties, properties, cursor, limit) {
|
|
113
|
-
return {
|
|
114
|
-
entities: []
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Copyright 2024 IOTA Stiftung.
|
|
120
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
121
|
-
/**
|
|
122
|
-
* Helper class for log entry operations.
|
|
123
|
-
*/
|
|
124
|
-
class LogEntryHelper {
|
|
125
|
-
/**
|
|
126
|
-
* Translate the log entry.
|
|
127
|
-
* @param logEntry The log entry.
|
|
128
|
-
* @returns The translated log entry if a translation can be found.
|
|
129
|
-
*/
|
|
130
|
-
static translate(logEntry) {
|
|
131
|
-
if (core.Is.stringValue(logEntry.level) && core.Is.stringValue(logEntry.source)) {
|
|
132
|
-
const sourceMessage = `${logEntry.level}.${core.StringHelper.camelCase(logEntry.source)}.${logEntry.message}`;
|
|
133
|
-
if (core.I18n.hasMessage(sourceMessage)) {
|
|
134
|
-
return core.I18n.formatMessage(sourceMessage, logEntry.data);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (core.Is.stringValue(logEntry.source)) {
|
|
138
|
-
const sourceMessage = `${core.StringHelper.camelCase(logEntry.source)}.${logEntry.message}`;
|
|
139
|
-
if (core.I18n.hasMessage(sourceMessage)) {
|
|
140
|
-
return core.I18n.formatMessage(sourceMessage, logEntry.data);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (core.I18n.hasMessage(logEntry.message)) {
|
|
144
|
-
return core.I18n.formatMessage(logEntry.message, logEntry.data);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
exports.LogEntryHelper = LogEntryHelper;
|
|
150
|
-
exports.LoggingConnectorFactory = LoggingConnectorFactory;
|
|
151
|
-
exports.MultiLoggingConnector = MultiLoggingConnector;
|
|
152
|
-
exports.SilentLoggingConnector = SilentLoggingConnector;
|
package/dist/esm/index.mjs
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { Factory, Guards, Is, StringHelper, I18n } from '@twin.org/core';
|
|
2
|
-
|
|
3
|
-
// Copyright 2024 IOTA Stiftung.
|
|
4
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
5
|
-
/**
|
|
6
|
-
* Factory for creating logging connectors.
|
|
7
|
-
*/
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
9
|
-
const LoggingConnectorFactory = Factory.createFactory("logging");
|
|
10
|
-
|
|
11
|
-
// Copyright 2024 IOTA Stiftung.
|
|
12
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
13
|
-
/**
|
|
14
|
-
* Class for performing logging operations on multiple connectors.
|
|
15
|
-
*/
|
|
16
|
-
class MultiLoggingConnector {
|
|
17
|
-
/**
|
|
18
|
-
* The namespace for the logging connector.
|
|
19
|
-
*/
|
|
20
|
-
static NAMESPACE = "multi";
|
|
21
|
-
/**
|
|
22
|
-
* Runtime name for the class.
|
|
23
|
-
*/
|
|
24
|
-
static CLASS_NAME = "MultiLoggingConnector";
|
|
25
|
-
/**
|
|
26
|
-
* The connectors to send the log entries to.
|
|
27
|
-
* @internal
|
|
28
|
-
*/
|
|
29
|
-
_loggingConnectors;
|
|
30
|
-
/**
|
|
31
|
-
* The log levels to display, will default to all.
|
|
32
|
-
* @internal
|
|
33
|
-
*/
|
|
34
|
-
_levels;
|
|
35
|
-
/**
|
|
36
|
-
* Create a new instance of MultiLoggingConnector.
|
|
37
|
-
* @param options The options for the connector.
|
|
38
|
-
*/
|
|
39
|
-
constructor(options) {
|
|
40
|
-
Guards.object(MultiLoggingConnector.CLASS_NAME, "options", options);
|
|
41
|
-
Guards.arrayValue(MultiLoggingConnector.CLASS_NAME, "options.loggingConnectorTypes", options.loggingConnectorTypes);
|
|
42
|
-
this._levels = options?.config?.levels ?? ["debug", "info", "warn", "error", "trace"];
|
|
43
|
-
this._loggingConnectors = options.loggingConnectorTypes.map(t => LoggingConnectorFactory.get(t));
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Log an entry to the connector.
|
|
47
|
-
* @param logEntry The entry to log.
|
|
48
|
-
* @returns Nothing.
|
|
49
|
-
*/
|
|
50
|
-
async log(logEntry) {
|
|
51
|
-
Guards.object(MultiLoggingConnector.CLASS_NAME, "logEntry", logEntry);
|
|
52
|
-
if (this._levels.includes(logEntry.level)) {
|
|
53
|
-
logEntry.ts ??= Date.now();
|
|
54
|
-
await Promise.allSettled(this._loggingConnectors.map(async (loggingConnector) => loggingConnector.log(logEntry)));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Query the log entries.
|
|
59
|
-
* @param conditions The conditions to match for the entities.
|
|
60
|
-
* @param sortProperties The optional sort order.
|
|
61
|
-
* @param properties The optional keys to return, defaults to all.
|
|
62
|
-
* @param cursor The cursor to request the next chunk of entities.
|
|
63
|
-
* @param limit Limit the number of entities to return.
|
|
64
|
-
* @returns All the entities for the storage matching the conditions,
|
|
65
|
-
* and a cursor which can be used to request more entities.
|
|
66
|
-
*/
|
|
67
|
-
async query(conditions, sortProperties, properties, cursor, limit) {
|
|
68
|
-
// See if we can find a connector that supports querying.
|
|
69
|
-
// If it throws anything other than not implemented, we should throw it.
|
|
70
|
-
for (const loggingConnector of this._loggingConnectors) {
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
72
|
-
if (Is.function(loggingConnector.query)) {
|
|
73
|
-
return loggingConnector.query(conditions, sortProperties, properties, cursor, limit);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
entities: []
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Class for performing logging operations to nowhere.
|
|
84
|
-
*/
|
|
85
|
-
class SilentLoggingConnector {
|
|
86
|
-
/**
|
|
87
|
-
* The namespace for the logging connector.
|
|
88
|
-
*/
|
|
89
|
-
static NAMESPACE = "silent";
|
|
90
|
-
/**
|
|
91
|
-
* Runtime name for the class.
|
|
92
|
-
*/
|
|
93
|
-
static CLASS_NAME = "SilentLoggingConnector";
|
|
94
|
-
/**
|
|
95
|
-
* Log an entry to the connector.
|
|
96
|
-
* @param logEntry The entry to log.
|
|
97
|
-
* @returns Nothing.
|
|
98
|
-
*/
|
|
99
|
-
async log(logEntry) { }
|
|
100
|
-
/**
|
|
101
|
-
* Query the log entries.
|
|
102
|
-
* @param conditions The conditions to match for the entities.
|
|
103
|
-
* @param sortProperties The optional sort order.
|
|
104
|
-
* @param properties The optional keys to return, defaults to all.
|
|
105
|
-
* @param cursor The cursor to request the next chunk of entities.
|
|
106
|
-
* @param limit Limit the number of entities to return.
|
|
107
|
-
* @returns All the entities for the storage matching the conditions,
|
|
108
|
-
* and a cursor which can be used to request more entities.
|
|
109
|
-
*/
|
|
110
|
-
async query(conditions, sortProperties, properties, cursor, limit) {
|
|
111
|
-
return {
|
|
112
|
-
entities: []
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Copyright 2024 IOTA Stiftung.
|
|
118
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
119
|
-
/**
|
|
120
|
-
* Helper class for log entry operations.
|
|
121
|
-
*/
|
|
122
|
-
class LogEntryHelper {
|
|
123
|
-
/**
|
|
124
|
-
* Translate the log entry.
|
|
125
|
-
* @param logEntry The log entry.
|
|
126
|
-
* @returns The translated log entry if a translation can be found.
|
|
127
|
-
*/
|
|
128
|
-
static translate(logEntry) {
|
|
129
|
-
if (Is.stringValue(logEntry.level) && Is.stringValue(logEntry.source)) {
|
|
130
|
-
const sourceMessage = `${logEntry.level}.${StringHelper.camelCase(logEntry.source)}.${logEntry.message}`;
|
|
131
|
-
if (I18n.hasMessage(sourceMessage)) {
|
|
132
|
-
return I18n.formatMessage(sourceMessage, logEntry.data);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (Is.stringValue(logEntry.source)) {
|
|
136
|
-
const sourceMessage = `${StringHelper.camelCase(logEntry.source)}.${logEntry.message}`;
|
|
137
|
-
if (I18n.hasMessage(sourceMessage)) {
|
|
138
|
-
return I18n.formatMessage(sourceMessage, logEntry.data);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
if (I18n.hasMessage(logEntry.message)) {
|
|
142
|
-
return I18n.formatMessage(logEntry.message, logEntry.data);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export { LogEntryHelper, LoggingConnectorFactory, MultiLoggingConnector, SilentLoggingConnector };
|