mirror of
https://github.com/bitwarden/browser
synced 2026-02-21 03:43:58 +00:00
Move the LogProvider and SemanticLogger to @bitwarden/logging
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { shareReplay } from "rxjs";
|
||||
|
||||
import { SemanticLogger } from "@bitwarden/logging";
|
||||
|
||||
import { Account } from "../../auth/abstractions/account.service";
|
||||
import { BoundDependency } from "../dependencies";
|
||||
import { SemanticLogger } from "../log";
|
||||
import { UserStateSubject } from "../state/user-state-subject";
|
||||
import { UserStateSubjectDependencyProvider } from "../state/user-state-subject-dependency-provider";
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Jsonify } from "type-fest";
|
||||
|
||||
import { SemanticLogger } from "@bitwarden/logging";
|
||||
|
||||
import { LogService } from "../../platform/abstractions/log.service";
|
||||
import { LogLevelType } from "../../platform/enums";
|
||||
|
||||
import { SemanticLogger } from "./semantic-logger.abstraction";
|
||||
|
||||
/** Sends semantic logs to the console.
|
||||
* @remarks the behavior of this logger is based on `LogService`; it
|
||||
* replaces dynamic messages (`%s`) with a JSON-formatted semantic log.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Jsonify } from "type-fest";
|
||||
|
||||
import { deepFreeze } from "../util";
|
||||
import { SemanticLogger } from "@bitwarden/logging";
|
||||
|
||||
import { SemanticLogger } from "./semantic-logger.abstraction";
|
||||
import { deepFreeze } from "../util";
|
||||
|
||||
/** All disabled loggers emitted by this module are `===` to this logger. */
|
||||
export const DISABLED_LOGGER: SemanticLogger = deepFreeze({
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Jsonify } from "type-fest";
|
||||
|
||||
import { SemanticLogger, LogProvider } from "@bitwarden/logging";
|
||||
|
||||
import { LogService } from "../../platform/abstractions/log.service";
|
||||
|
||||
import { DefaultSemanticLogger } from "./default-semantic-logger";
|
||||
import { DISABLED_LOGGER } from "./disabled-logger";
|
||||
import { SemanticLogger } from "./semantic-logger.abstraction";
|
||||
import { LogProvider } from "./types";
|
||||
import { warnLoggingEnabled } from "./util";
|
||||
|
||||
/** Instantiates a semantic logger that emits nothing when a message
|
||||
|
||||
@@ -1,4 +1,2 @@
|
||||
export * from "./factory";
|
||||
export * from "./disabled-logger";
|
||||
export { LogProvider } from "./types";
|
||||
export { SemanticLogger } from "./semantic-logger.abstraction";
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
import { Jsonify } from "type-fest";
|
||||
|
||||
/** Semantic/structural logging component */
|
||||
export interface SemanticLogger {
|
||||
/** Logs a message at debug priority.
|
||||
* Debug messages are used for diagnostics, and are typically disabled
|
||||
* in production builds.
|
||||
* @param message - a message to record in the log's `message` field.
|
||||
*/
|
||||
debug(message: string): void;
|
||||
|
||||
// FIXME: replace Jsonify<T> parameter with structural logging schema type
|
||||
/** 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 message - a message to record in the log's `message` field.
|
||||
*/
|
||||
debug<T>(content: Jsonify<T>, message?: string): void;
|
||||
|
||||
/** combined signature for overloaded methods */
|
||||
debug<T>(content: Jsonify<T> | string, message?: string): void;
|
||||
|
||||
/** Logs a message at informational priority.
|
||||
* Information messages are used for status reports.
|
||||
* @param message - a message to record in the log's `message` field.
|
||||
*/
|
||||
info(message: string): void;
|
||||
|
||||
/** 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 message - a message to record in the log's `message` field.
|
||||
*/
|
||||
info<T>(content: Jsonify<T>, message?: string): void;
|
||||
|
||||
/** combined signature for overloaded methods */
|
||||
info<T>(content: Jsonify<T> | string, message?: string): void;
|
||||
|
||||
/** Logs a message at warn priority.
|
||||
* Warn messages are used to indicate a operation that may affect system
|
||||
* stability occurred.
|
||||
* @param message - a message to record in the log's `message` field.
|
||||
*/
|
||||
warn(message: string): void;
|
||||
|
||||
/** 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 message - a message to record in the log's `message` field.
|
||||
*/
|
||||
warn<T>(content: Jsonify<T>, message?: string): void;
|
||||
|
||||
/** combined signature for overloaded methods */
|
||||
warn<T>(content: Jsonify<T> | string, message?: string): void;
|
||||
|
||||
/** Logs a message at error priority.
|
||||
* Error messages are used to indicate a operation that affects system
|
||||
* stability occurred and the system was able to recover.
|
||||
* @param message - a message to record in the log's `message` field.
|
||||
*/
|
||||
error(message: string): void;
|
||||
|
||||
/** 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 message - a message to record in the log's `message` field.
|
||||
*/
|
||||
error<T>(content: Jsonify<T>, message?: string): void;
|
||||
|
||||
/** combined signature for overloaded methods */
|
||||
error<T>(content: Jsonify<T> | 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
|
||||
* stability occurred and the system cannot recover. Panic messages
|
||||
* log an error and throw an `Error`.
|
||||
* @param message - a message to record in the log's `message` field.
|
||||
*/
|
||||
panic(message: string): never;
|
||||
|
||||
/** Logs the content at debug priority and throws an error.
|
||||
* 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 message - a message to record in the log's `message` field.
|
||||
*/
|
||||
panic<T>(content: Jsonify<T>, message?: string): never;
|
||||
|
||||
/** combined signature for overloaded methods */
|
||||
panic<T>(content: Jsonify<T> | string, message?: string): never;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { Jsonify } from "type-fest";
|
||||
|
||||
import { SemanticLogger } from "./semantic-logger.abstraction";
|
||||
|
||||
/** Creates a semantic logger.
|
||||
* @param context all logs emitted by the logger are extended with
|
||||
* these fields.
|
||||
* @remarks The `message`, `level`, `provider`, and `content` fields
|
||||
* are reserved for use by the semantic logging system.
|
||||
*/
|
||||
export type LogProvider = <Context extends object>(context: Jsonify<Context>) => SemanticLogger;
|
||||
@@ -1,4 +1,4 @@
|
||||
import { LogService } from "@bitwarden/logging";
|
||||
import { LogService, LogProvider } from "@bitwarden/logging";
|
||||
import { BitwardenClient } from "@bitwarden/sdk-internal";
|
||||
import { StateProvider } from "@bitwarden/state";
|
||||
|
||||
@@ -9,7 +9,7 @@ import { PlatformUtilsService } from "../platform/abstractions/platform-utils.se
|
||||
import { LegacyEncryptorProvider } from "./cryptography/legacy-encryptor-provider";
|
||||
import { ExtensionRegistry } from "./extension/extension-registry.abstraction";
|
||||
import { ExtensionService } from "./extension/extension.service";
|
||||
import { disabledSemanticLoggerProvider, enableLogForTypes, LogProvider } from "./log";
|
||||
import { disabledSemanticLoggerProvider, enableLogForTypes } from "./log";
|
||||
|
||||
/** Provides access to commonly-used cross-cutting services. */
|
||||
export type SystemServiceProvider = {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Jsonify } from "type-fest";
|
||||
|
||||
import { SemanticLogger } from "@bitwarden/logging";
|
||||
|
||||
import { StateProvider } from "../../platform/state";
|
||||
import { LegacyEncryptorProvider } from "../cryptography/legacy-encryptor-provider";
|
||||
import { SemanticLogger } from "../log";
|
||||
|
||||
/** Aggregates user state subject dependencies */
|
||||
export abstract class UserStateSubjectDependencyProvider {
|
||||
|
||||
@@ -29,11 +29,12 @@ import {
|
||||
switchMap,
|
||||
} from "rxjs";
|
||||
|
||||
import { SemanticLogger } from "@bitwarden/logging";
|
||||
|
||||
import { Account } from "../../auth/abstractions/account.service";
|
||||
import { EncString } from "../../key-management/crypto/models/enc-string";
|
||||
import { SingleUserState, UserKeyDefinition } from "../../platform/state";
|
||||
import { UserEncryptor } from "../cryptography/user-encryptor.abstraction";
|
||||
import { SemanticLogger } from "../log";
|
||||
import { anyComplete, pin, ready, withLatestReady } from "../rx";
|
||||
import { Constraints, SubjectConstraints, WithConstraints } from "../types";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user