diff --git a/libs/common/src/tools/log/default-semantic-logger.spec.ts b/libs/common/src/tools/log/default-semantic-logger.spec.ts index 7f608fb40ef..98052b6268c 100644 --- a/libs/common/src/tools/log/default-semantic-logger.spec.ts +++ b/libs/common/src/tools/log/default-semantic-logger.spec.ts @@ -32,7 +32,7 @@ describe("DefaultSemanticLogger", () => { expect(logger.write).toHaveBeenCalledWith(LogLevelType.Debug, { "@timestamp": 0, - content: { example: "this is content" }, + labels: { example: "this is content" }, level: "debug", }); }); @@ -44,7 +44,7 @@ describe("DefaultSemanticLogger", () => { expect(logger.write).toHaveBeenCalledWith(LogLevelType.Info, { "@timestamp": 0, - content: { example: "this is content" }, + labels: { example: "this is content" }, message: "this is a message", level: "information", }); @@ -71,7 +71,7 @@ describe("DefaultSemanticLogger", () => { expect(logger.write).toHaveBeenCalledWith(LogLevelType.Info, { "@timestamp": 0, - content: { example: "this is content" }, + labels: { example: "this is content" }, level: "information", }); }); @@ -83,7 +83,7 @@ describe("DefaultSemanticLogger", () => { expect(logger.write).toHaveBeenCalledWith(LogLevelType.Info, { "@timestamp": 0, - content: { example: "this is content" }, + labels: { example: "this is content" }, message: "this is a message", level: "information", }); @@ -110,7 +110,7 @@ describe("DefaultSemanticLogger", () => { expect(logger.write).toHaveBeenCalledWith(LogLevelType.Warning, { "@timestamp": 0, - content: { example: "this is content" }, + labels: { example: "this is content" }, level: "warning", }); }); @@ -122,7 +122,7 @@ describe("DefaultSemanticLogger", () => { expect(logger.write).toHaveBeenCalledWith(LogLevelType.Warning, { "@timestamp": 0, - content: { example: "this is content" }, + labels: { example: "this is content" }, message: "this is a message", level: "warning", }); @@ -149,7 +149,7 @@ describe("DefaultSemanticLogger", () => { expect(logger.write).toHaveBeenCalledWith(LogLevelType.Error, { "@timestamp": 0, - content: { example: "this is content" }, + labels: { example: "this is content" }, level: "error", }); }); @@ -161,7 +161,7 @@ describe("DefaultSemanticLogger", () => { expect(logger.write).toHaveBeenCalledWith(LogLevelType.Error, { "@timestamp": 0, - content: { example: "this is content" }, + labels: { example: "this is content" }, message: "this is a message", level: "error", }); @@ -190,7 +190,7 @@ describe("DefaultSemanticLogger", () => { expect(logger.write).toHaveBeenCalledWith(LogLevelType.Error, { "@timestamp": 0, - content: { example: "this is content" }, + labels: { example: "this is content" }, message: "this is an error message", level: "error", }); @@ -205,7 +205,7 @@ describe("DefaultSemanticLogger", () => { expect(logger.write).toHaveBeenCalledWith(LogLevelType.Error, { "@timestamp": 0, - content: "this is content", + labels: "this is content", message: "this is an error message", level: "error", }); diff --git a/libs/common/src/tools/log/default-semantic-logger.ts b/libs/common/src/tools/log/default-semantic-logger.ts index eb1ecbe36c6..55bf92f2739 100644 --- a/libs/common/src/tools/log/default-semantic-logger.ts +++ b/libs/common/src/tools/log/default-semantic-logger.ts @@ -1,4 +1,4 @@ -import { Jsonify } from "type-fest"; +import { Jsonify, Primitive } from "type-fest"; import { LogService } from "../../platform/abstractions/log.service"; import { LogLevelType } from "../../platform/enums"; @@ -12,7 +12,7 @@ import { SemanticLogger } from "./semantic-logger.abstraction"; export class DefaultSemanticLogger implements SemanticLogger { /** Instantiates a console semantic logger * @param context a static payload that is cloned when the logger - * logs a message. The `messages`, `level`, and `content` fields + * logs a message. The `messages`, `level`, and `labels` fields * are reserved for use by loggers. */ constructor( @@ -25,41 +25,41 @@ export class DefaultSemanticLogger implements SemanticLo readonly context: object; - debug(content: Jsonify, message?: string): void { - this.log(content, LogLevelType.Debug, message); + debug(labels: Record | string, message?: string): void { + this.log(labels, LogLevelType.Debug, message); } - info(content: Jsonify, message?: string): void { - this.log(content, LogLevelType.Info, message); + info(labels: Record | string, message?: string): void { + this.log(labels, LogLevelType.Info, message); } - warn(content: Jsonify, message?: string): void { - this.log(content, LogLevelType.Warning, message); + warn(labels: Record | string, message?: string): void { + this.log(labels, LogLevelType.Warning, message); } - error(content: Jsonify, message?: string): void { - this.log(content, LogLevelType.Error, message); + error(labels: Record | string, message?: string): void { + this.log(labels, LogLevelType.Error, message); } - panic(content: Jsonify, message?: string): never { - this.log(content, LogLevelType.Error, message); + panic(labels: Record | string, message?: string): never { + this.log(labels, LogLevelType.Error, message); const panicMessage = - message ?? (typeof content === "string" ? content : "a fatal error occurred"); + message ?? (typeof labels === "string" ? labels : "a fatal error occurred"); throw new Error(panicMessage); } - private log(content: Jsonify, level: LogLevelType, message?: string) { + private log(labels: Record | string, level: LogLevelType, message?: string) { const log = { ...this.context, message, - content: content ?? undefined, + labels: labels as unknown, level: stringifyLevel(level), "@timestamp": this.now(), }; - if (typeof content === "string" && !message) { - log.message = content; - delete log.content; + if (typeof labels === "string" && !message) { + log.message = labels; + delete log.labels; } this.logger.write(level, log); diff --git a/libs/common/src/tools/log/disabled-semantic-logger.ts b/libs/common/src/tools/log/disabled-semantic-logger.ts index 054c3ed390b..470fde4dea5 100644 --- a/libs/common/src/tools/log/disabled-semantic-logger.ts +++ b/libs/common/src/tools/log/disabled-semantic-logger.ts @@ -1,18 +1,18 @@ -import { Jsonify } from "type-fest"; +import { Primitive } from "type-fest"; import { SemanticLogger } from "./semantic-logger.abstraction"; /** Disables semantic logs. Still panics. */ export class DisabledSemanticLogger implements SemanticLogger { - debug(_content: Jsonify, _message?: string): void {} + debug(_labels: Record | string, _message?: string): void {} - info(_content: Jsonify, _message?: string): void {} + info(_labels: Record | string, _message?: string): void {} - warn(_content: Jsonify, _message?: string): void {} + warn(_labels: Record | string, _message?: string): void {} - error(_content: Jsonify, _message?: string): void {} + error(_labels: Record | string, _message?: string): void {} - panic(_content: Jsonify, message?: string): never { + panic(_labels: Record | string, message?: string): never { throw new Error(message); } } diff --git a/libs/common/src/tools/log/semantic-logger.abstraction.ts b/libs/common/src/tools/log/semantic-logger.abstraction.ts index 196d1f3f12c..2a4d2a33bfd 100644 --- a/libs/common/src/tools/log/semantic-logger.abstraction.ts +++ b/libs/common/src/tools/log/semantic-logger.abstraction.ts @@ -1,4 +1,4 @@ -import { Jsonify } from "type-fest"; +import { Primitive } from "type-fest"; /** Semantic/structural logging component */ export interface SemanticLogger { @@ -12,13 +12,13 @@ export interface SemanticLogger { /** Logs the content at debug priority. * Debug messages are used for diagnostics, and are typically disabled * in production builds. - * @param content - JSON content included in the log's `content` field. + * @param labels - JSON content included in the log's `content` field. * @param message - a message to record in the log's `message` field. */ - debug(content: Jsonify, message?: string): void; + debug(labels: Record, message?: string): void; /** combined signature for overloaded methods */ - debug(content: Jsonify | string, message?: string): void; + debug(labels: Record | string, message?: string): void; /** Logs a message at informational priority. * Information messages are used for status reports. @@ -28,13 +28,13 @@ export interface SemanticLogger { /** Logs the content at informational priority. * Information messages are used for status reports. - * @param content - JSON content included in the log's `content` field. + * @param labels - JSON content included in the log's `content` field. * @param message - a message to record in the log's `message` field. */ - info(content: Jsonify, message?: string): void; + info(labels: Record, message?: string): void; /** combined signature for overloaded methods */ - info(content: Jsonify | string, message?: string): void; + info(labels: Record | string, message?: string): void; /** Logs a message at warn priority. * Warn messages are used to indicate a operation that may affect system @@ -46,13 +46,13 @@ export interface SemanticLogger { /** Logs the content at warn priority. * Warn messages are used to indicate a operation that may affect system * stability occurred. - * @param content - JSON content included in the log's `content` field. + * @param labels - JSON content included in the log's `content` field. * @param message - a message to record in the log's `message` field. */ - warn(content: Jsonify, message?: string): void; + warn(labels: Record, message?: string): void; /** combined signature for overloaded methods */ - warn(content: Jsonify | string, message?: string): void; + warn(labels: Record | string, message?: string): void; /** Logs a message at error priority. * Error messages are used to indicate a operation that affects system @@ -64,13 +64,13 @@ export interface SemanticLogger { /** Logs the content at debug priority. * Error messages are used to indicate a operation that affects system * stability occurred and the system was able to recover. - * @param content - JSON content included in the log's `content` field. + * @param labels - JSON content included in the log's `content` field. * @param message - a message to record in the log's `message` field. */ - error(content: Jsonify, message?: string): void; + error(labels: Record, message?: string): void; /** combined signature for overloaded methods */ - error(content: Jsonify | string, message?: string): void; + error(labels: Record | string, message?: string): void; /** Logs a message at panic priority and throws an error. * Panic messages are used to indicate a operation that affects system @@ -84,11 +84,11 @@ export interface SemanticLogger { * Panic messages are used to indicate a operation that affects system * stability occurred and the system cannot recover. Panic messages * log an error and throw an `Error`. - * @param content - JSON content included in the log's `content` field. + * @param labels - JSON content included in the log's `content` field. * @param message - a message to record in the log's `message` field. */ - panic(content: Jsonify, message?: string): never; + panic(labels: Record, message?: string): never; /** combined signature for overloaded methods */ - panic(content: Jsonify | string, message?: string): never; + panic(labels: Record | string, message?: string): never; } diff --git a/libs/common/src/tools/state/user-state-subject.ts b/libs/common/src/tools/state/user-state-subject.ts index dd88ec2fb20..e5f291bcf78 100644 --- a/libs/common/src/tools/state/user-state-subject.ts +++ b/libs/common/src/tools/state/user-state-subject.ts @@ -140,7 +140,7 @@ export class UserStateSubject< const encryptor$ = this.encryptor(account$); const constraints$ = (this.context.constraints$ ?? unconstrained$()).pipe( catchError((e: unknown) => { - this.log.error(e as object, "constraints$ dependency failed; using last-known constraints"); + this.log.error(e as any, "constraints$ dependency failed; using last-known constraints"); return EMPTY; }), shareReplay({ refCount: true, bufferSize: 1 }), @@ -516,7 +516,7 @@ export class UserStateSubject< return value; }) .catch((e: any) => { - this.log.error(e as object, "updating failed"); + this.log.error(e, "updating failed"); this.onError(e); }); } diff --git a/libs/tools/generator/core/src/services/generator-profile-provider.ts b/libs/tools/generator/core/src/services/generator-profile-provider.ts index 24835e948fd..84914893627 100644 --- a/libs/tools/generator/core/src/services/generator-profile-provider.ts +++ b/libs/tools/generator/core/src/services/generator-profile-provider.ts @@ -80,7 +80,7 @@ export class GeneratorProfileProvider { accountId: account.id, profileType: profile.type, policyType: profile.constraints.type ?? "N/A", - defaultConstraints: profile.constraints.default as object, + defaultConstraints: JSON.stringify(profile.constraints.default), }, "initializing constraints$", );