1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-10 13:40:06 +00:00

align content parameter with ECS labels

This commit is contained in:
✨ Audrey ✨
2025-03-10 15:38:59 -04:00
parent b448dd2255
commit e7752ee4e6
6 changed files with 53 additions and 53 deletions

View File

@@ -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",
});

View File

@@ -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<Context extends object> 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<Context extends object> implements SemanticLo
readonly context: object;
debug<T>(content: Jsonify<T>, message?: string): void {
this.log(content, LogLevelType.Debug, message);
debug(labels: Record<string, Primitive> | string, message?: string): void {
this.log(labels, LogLevelType.Debug, message);
}
info<T>(content: Jsonify<T>, message?: string): void {
this.log(content, LogLevelType.Info, message);
info(labels: Record<string, Primitive> | string, message?: string): void {
this.log(labels, LogLevelType.Info, message);
}
warn<T>(content: Jsonify<T>, message?: string): void {
this.log(content, LogLevelType.Warning, message);
warn(labels: Record<string, Primitive> | string, message?: string): void {
this.log(labels, LogLevelType.Warning, message);
}
error<T>(content: Jsonify<T>, message?: string): void {
this.log(content, LogLevelType.Error, message);
error(labels: Record<string, Primitive> | string, message?: string): void {
this.log(labels, LogLevelType.Error, message);
}
panic<T>(content: Jsonify<T>, message?: string): never {
this.log(content, LogLevelType.Error, message);
panic(labels: Record<string, Primitive> | 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<T>(content: Jsonify<T>, level: LogLevelType, message?: string) {
private log(labels: Record<string, Primitive> | 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);

View File

@@ -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<T>(_content: Jsonify<T>, _message?: string): void {}
debug(_labels: Record<string, Primitive> | string, _message?: string): void {}
info<T>(_content: Jsonify<T>, _message?: string): void {}
info(_labels: Record<string, Primitive> | string, _message?: string): void {}
warn<T>(_content: Jsonify<T>, _message?: string): void {}
warn(_labels: Record<string, Primitive> | string, _message?: string): void {}
error<T>(_content: Jsonify<T>, _message?: string): void {}
error(_labels: Record<string, Primitive> | string, _message?: string): void {}
panic<T>(_content: Jsonify<T>, message?: string): never {
panic(_labels: Record<string, Primitive> | string, message?: string): never {
throw new Error(message);
}
}

View File

@@ -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<T>(content: Jsonify<T>, message?: string): void;
debug(labels: Record<string, Primitive>, message?: string): void;
/** combined signature for overloaded methods */
debug<T>(content: Jsonify<T> | string, message?: string): void;
debug(labels: Record<string, Primitive> | 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<T>(content: Jsonify<T>, message?: string): void;
info(labels: Record<string, Primitive>, message?: string): void;
/** combined signature for overloaded methods */
info<T>(content: Jsonify<T> | string, message?: string): void;
info(labels: Record<string, Primitive> | 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<T>(content: Jsonify<T>, message?: string): void;
warn(labels: Record<string, Primitive>, message?: string): void;
/** combined signature for overloaded methods */
warn<T>(content: Jsonify<T> | string, message?: string): void;
warn(labels: Record<string, Primitive> | 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<T>(content: Jsonify<T>, message?: string): void;
error(labels: Record<string, Primitive>, message?: string): void;
/** combined signature for overloaded methods */
error<T>(content: Jsonify<T> | string, message?: string): void;
error(labels: Record<string, Primitive> | 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<T>(content: Jsonify<T>, message?: string): never;
panic(labels: Record<string, Primitive>, message?: string): never;
/** combined signature for overloaded methods */
panic<T>(content: Jsonify<T> | string, message?: string): never;
panic(labels: Record<string, Primitive> | string, message?: string): never;
}

View File

@@ -140,7 +140,7 @@ export class UserStateSubject<
const encryptor$ = this.encryptor(account$);
const constraints$ = (this.context.constraints$ ?? unconstrained$<State>()).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);
});
}

View File

@@ -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$",
);