mirror of
https://github.com/bitwarden/browser
synced 2026-02-15 07:54:55 +00:00
address requested changes:
• updated import paths to import from @bitwarden/logging • deleted barrel export file from libs/common/src/tools/log and updated all imports to use @bitwarden/logging
This commit is contained in:
@@ -1 +0,0 @@
|
||||
export * from "@bitwarden/logging";
|
||||
@@ -1,5 +1,7 @@
|
||||
import { mock, MockProxy } from "jest-mock-extended";
|
||||
|
||||
import { disabledSemanticLoggerProvider } from "@bitwarden/logging";
|
||||
|
||||
import { PolicyService } from "../admin-console/abstractions/policy/policy.service.abstraction";
|
||||
import { ConfigService } from "../platform/abstractions/config/config.service";
|
||||
import { LogService } from "../platform/abstractions/log.service";
|
||||
@@ -9,7 +11,6 @@ import { StateProvider } from "../platform/state";
|
||||
import { LegacyEncryptorProvider } from "./cryptography/legacy-encryptor-provider";
|
||||
import { ExtensionRegistry } from "./extension/extension-registry.abstraction";
|
||||
import { ExtensionService } from "./extension/extension.service";
|
||||
import { disabledSemanticLoggerProvider } from "./log";
|
||||
import { createSystemServiceProvider } from "./providers";
|
||||
|
||||
describe("SystemServiceProvider", () => {
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { LogService } from "@bitwarden/logging";
|
||||
import {
|
||||
disabledSemanticLoggerProvider,
|
||||
enableLogForTypes,
|
||||
LogProvider,
|
||||
LogService,
|
||||
} from "@bitwarden/logging";
|
||||
import { BitwardenClient } from "@bitwarden/sdk-internal";
|
||||
import { StateProvider } from "@bitwarden/state";
|
||||
|
||||
@@ -9,7 +14,6 @@ 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";
|
||||
|
||||
/** Provides access to commonly-used cross-cutting services. */
|
||||
export type SystemServiceProvider = {
|
||||
|
||||
@@ -20,7 +20,6 @@ import { KvpRequest } from "@bitwarden/common/models/request/kvp.request";
|
||||
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||
import { SemanticLogger } from "@bitwarden/common/tools/log";
|
||||
import { SystemServiceProvider } from "@bitwarden/common/tools/providers";
|
||||
import { OrganizationId } from "@bitwarden/common/types/guid";
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
@@ -32,6 +31,7 @@ import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
|
||||
import { RestrictedItemTypesService } from "@bitwarden/common/vault/services/restricted-item-types.service";
|
||||
import { KeyService } from "@bitwarden/key-management";
|
||||
import { SemanticLogger } from "@bitwarden/logging";
|
||||
|
||||
import {
|
||||
AscendoCsvImporter,
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { mock } from "jest-mock-extended";
|
||||
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { LogLevelType } from "@bitwarden/common/platform/enums";
|
||||
|
||||
import { DefaultSemanticLogger } from "./default-semantic-logger";
|
||||
import { LogLevel } from "./log-level";
|
||||
import { LogService } from "./log.service";
|
||||
|
||||
const logger = mock<LogService>();
|
||||
|
||||
@@ -18,7 +17,7 @@ describe("DefaultSemanticLogger", () => {
|
||||
|
||||
log.debug("this is a debug message");
|
||||
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevelType.Debug, {
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevel.Debug, {
|
||||
"@timestamp": 0,
|
||||
message: "this is a debug message",
|
||||
level: "debug",
|
||||
@@ -30,7 +29,7 @@ describe("DefaultSemanticLogger", () => {
|
||||
|
||||
log.debug({ example: "this is content" });
|
||||
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevelType.Debug, {
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevel.Debug, {
|
||||
"@timestamp": 0,
|
||||
content: { example: "this is content" },
|
||||
level: "debug",
|
||||
@@ -42,7 +41,7 @@ describe("DefaultSemanticLogger", () => {
|
||||
|
||||
log.info({ example: "this is content" }, "this is a message");
|
||||
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevelType.Info, {
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevel.Info, {
|
||||
"@timestamp": 0,
|
||||
content: { example: "this is content" },
|
||||
message: "this is a message",
|
||||
@@ -57,7 +56,7 @@ describe("DefaultSemanticLogger", () => {
|
||||
|
||||
log.info("this is an info message");
|
||||
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevelType.Info, {
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevel.Info, {
|
||||
"@timestamp": 0,
|
||||
message: "this is an info message",
|
||||
level: "information",
|
||||
@@ -69,7 +68,7 @@ describe("DefaultSemanticLogger", () => {
|
||||
|
||||
log.info({ example: "this is content" });
|
||||
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevelType.Info, {
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevel.Info, {
|
||||
"@timestamp": 0,
|
||||
content: { example: "this is content" },
|
||||
level: "information",
|
||||
@@ -81,7 +80,7 @@ describe("DefaultSemanticLogger", () => {
|
||||
|
||||
log.info({ example: "this is content" }, "this is a message");
|
||||
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevelType.Info, {
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevel.Info, {
|
||||
"@timestamp": 0,
|
||||
content: { example: "this is content" },
|
||||
message: "this is a message",
|
||||
@@ -96,7 +95,7 @@ describe("DefaultSemanticLogger", () => {
|
||||
|
||||
log.warn("this is a warning message");
|
||||
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevelType.Warning, {
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevel.Warning, {
|
||||
"@timestamp": 0,
|
||||
message: "this is a warning message",
|
||||
level: "warning",
|
||||
@@ -108,7 +107,7 @@ describe("DefaultSemanticLogger", () => {
|
||||
|
||||
log.warn({ example: "this is content" });
|
||||
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevelType.Warning, {
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevel.Warning, {
|
||||
"@timestamp": 0,
|
||||
content: { example: "this is content" },
|
||||
level: "warning",
|
||||
@@ -120,7 +119,7 @@ describe("DefaultSemanticLogger", () => {
|
||||
|
||||
log.warn({ example: "this is content" }, "this is a message");
|
||||
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevelType.Warning, {
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevel.Warning, {
|
||||
"@timestamp": 0,
|
||||
content: { example: "this is content" },
|
||||
message: "this is a message",
|
||||
@@ -135,7 +134,7 @@ describe("DefaultSemanticLogger", () => {
|
||||
|
||||
log.error("this is an error message");
|
||||
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevelType.Error, {
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevel.Error, {
|
||||
"@timestamp": 0,
|
||||
message: "this is an error message",
|
||||
level: "error",
|
||||
@@ -147,7 +146,7 @@ describe("DefaultSemanticLogger", () => {
|
||||
|
||||
log.error({ example: "this is content" });
|
||||
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevelType.Error, {
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevel.Error, {
|
||||
"@timestamp": 0,
|
||||
content: { example: "this is content" },
|
||||
level: "error",
|
||||
@@ -159,7 +158,7 @@ describe("DefaultSemanticLogger", () => {
|
||||
|
||||
log.error({ example: "this is content" }, "this is a message");
|
||||
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevelType.Error, {
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevel.Error, {
|
||||
"@timestamp": 0,
|
||||
content: { example: "this is content" },
|
||||
message: "this is a message",
|
||||
@@ -174,7 +173,7 @@ describe("DefaultSemanticLogger", () => {
|
||||
|
||||
expect(() => log.panic("this is an error message")).toThrow("this is an error message");
|
||||
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevelType.Error, {
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevel.Error, {
|
||||
"@timestamp": 0,
|
||||
message: "this is an error message",
|
||||
level: "error",
|
||||
@@ -188,7 +187,7 @@ describe("DefaultSemanticLogger", () => {
|
||||
"this is an error message",
|
||||
);
|
||||
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevelType.Error, {
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevel.Error, {
|
||||
"@timestamp": 0,
|
||||
content: { example: "this is content" },
|
||||
message: "this is an error message",
|
||||
@@ -203,7 +202,7 @@ describe("DefaultSemanticLogger", () => {
|
||||
"this is an error message",
|
||||
);
|
||||
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevelType.Error, {
|
||||
expect(logger.write).toHaveBeenCalledWith(LogLevel.Error, {
|
||||
"@timestamp": 0,
|
||||
content: "this is content",
|
||||
message: "this is an error message",
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { Jsonify } from "type-fest";
|
||||
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { LogLevelType } from "@bitwarden/common/platform/enums";
|
||||
|
||||
import { LogLevel } from "./log-level";
|
||||
import { LogService } from "./log.service";
|
||||
import { SemanticLogger } from "./semantic-logger.abstraction";
|
||||
|
||||
/** Sends semantic logs to the console.
|
||||
@@ -26,29 +25,29 @@ 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);
|
||||
this.log(content, LogLevel.Debug, message);
|
||||
}
|
||||
|
||||
info<T>(content: Jsonify<T>, message?: string): void {
|
||||
this.log(content, LogLevelType.Info, message);
|
||||
this.log(content, LogLevel.Info, message);
|
||||
}
|
||||
|
||||
warn<T>(content: Jsonify<T>, message?: string): void {
|
||||
this.log(content, LogLevelType.Warning, message);
|
||||
this.log(content, LogLevel.Warning, message);
|
||||
}
|
||||
|
||||
error<T>(content: Jsonify<T>, message?: string): void {
|
||||
this.log(content, LogLevelType.Error, message);
|
||||
this.log(content, LogLevel.Error, message);
|
||||
}
|
||||
|
||||
panic<T>(content: Jsonify<T>, message?: string): never {
|
||||
this.log(content, LogLevelType.Error, message);
|
||||
this.log(content, LogLevel.Error, message);
|
||||
const panicMessage =
|
||||
message ?? (typeof content === "string" ? content : "a fatal error occurred");
|
||||
throw new Error(panicMessage);
|
||||
}
|
||||
|
||||
private log<T>(content: Jsonify<T>, level: LogLevelType, message?: string) {
|
||||
private log<T>(content: Jsonify<T>, level: LogLevel, message?: string) {
|
||||
const log = {
|
||||
...this.context,
|
||||
message,
|
||||
@@ -66,15 +65,15 @@ export class DefaultSemanticLogger<Context extends object> implements SemanticLo
|
||||
}
|
||||
}
|
||||
|
||||
function stringifyLevel(level: LogLevelType) {
|
||||
function stringifyLevel(level: LogLevel) {
|
||||
switch (level) {
|
||||
case LogLevelType.Debug:
|
||||
case LogLevel.Debug:
|
||||
return "debug";
|
||||
case LogLevelType.Info:
|
||||
case LogLevel.Info:
|
||||
return "information";
|
||||
case LogLevelType.Warning:
|
||||
case LogLevel.Warning:
|
||||
return "warning";
|
||||
case LogLevelType.Error:
|
||||
case LogLevel.Error:
|
||||
return "error";
|
||||
default:
|
||||
return `${level}`;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { Jsonify } from "type-fest";
|
||||
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
|
||||
import { DefaultSemanticLogger } from "./default-semantic-logger";
|
||||
import { DISABLED_LOGGER } from "./disabled-logger";
|
||||
import { LogService } from "./log.service";
|
||||
import { SemanticLogger } from "./semantic-logger.abstraction";
|
||||
import { LogProvider } from "./types";
|
||||
import { warnLoggingEnabled } from "./util";
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
import { Jsonify } from "type-fest";
|
||||
|
||||
import { SemanticLogger } from "./semantic-logger.abstraction";
|
||||
|
||||
export { LogService } from "./log.service";
|
||||
export { LogLevel } from "./log-level";
|
||||
export { ConsoleLogService } from "./console-log.service";
|
||||
@@ -13,38 +9,4 @@ export {
|
||||
enableLogForTypes,
|
||||
ifEnabledSemanticLoggerProvider,
|
||||
} from "./factory";
|
||||
|
||||
/**
|
||||
* Creates a semantic logger with a fixed context that is included in all log messages.
|
||||
*
|
||||
* @param context - Contextual metadata that will be included in every log entry
|
||||
* emitted by the returned logger. This is used to identify the source or scope
|
||||
* of log messages (e.g., `{ type: "ImportService" }` or `{ accountId: "123" }`).
|
||||
*
|
||||
* @returns A SemanticLogger instance that includes the provided context in all log output.
|
||||
*
|
||||
* @remarks
|
||||
* By convention, avoid using the following field names in the context object, as they
|
||||
* may conflict with fields added by the semantic logging implementation:
|
||||
* - `message` - The log message text
|
||||
* - `level` - The log level (debug, info, warn, error, panic)
|
||||
* - `provider` - The logging provider identifier
|
||||
* - `content` - Additional data passed to individual log calls
|
||||
*
|
||||
* Note: These field names are not enforced at compile-time or runtime, but using them
|
||||
* may result in unexpected behavior or field name collisions in log output.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Create a logger for a service
|
||||
* const log = logProvider({ type: "ImportService" });
|
||||
*
|
||||
* // All logs from this logger will include { type: "ImportService" }
|
||||
* log.debug("Starting import");
|
||||
* // Output: { type: "ImportService", level: "debug", message: "Starting import" }
|
||||
*
|
||||
* log.info({ itemCount: 42 }, "Import complete");
|
||||
* // Output: { type: "ImportService", level: "info", content: { itemCount: 42 }, message: "Import complete" }
|
||||
* ```
|
||||
*/
|
||||
export type LogProvider = <Context extends object>(context: Jsonify<Context>) => SemanticLogger;
|
||||
export type { LogProvider } from "./types";
|
||||
|
||||
@@ -22,11 +22,6 @@ import { DefaultFields, DefaultSites, Extension } from "@bitwarden/common/tools/
|
||||
import { RuntimeExtensionRegistry } from "@bitwarden/common/tools/extension/runtime-extension-registry";
|
||||
import { VendorExtensions, Vendors } from "@bitwarden/common/tools/extension/vendor";
|
||||
import { RestClient } from "@bitwarden/common/tools/integration/rpc";
|
||||
import {
|
||||
LogProvider,
|
||||
disabledSemanticLoggerProvider,
|
||||
enableLogForTypes,
|
||||
} from "@bitwarden/common/tools/log";
|
||||
import { SystemServiceProvider } from "@bitwarden/common/tools/providers";
|
||||
import { UserStateSubjectDependencyProvider } from "@bitwarden/common/tools/state/user-state-subject-dependency-provider";
|
||||
import {
|
||||
@@ -38,6 +33,7 @@ import {
|
||||
DefaultCredentialGeneratorService,
|
||||
} from "@bitwarden/generator-core";
|
||||
import { KeyService } from "@bitwarden/key-management";
|
||||
import { LogProvider, disabledSemanticLoggerProvider, enableLogForTypes } from "@bitwarden/logging";
|
||||
|
||||
export const RANDOMIZER = new SafeInjectionToken<Randomizer>("Randomizer");
|
||||
const GENERATOR_SERVICE_PROVIDER = new SafeInjectionToken<providers.CredentialGeneratorProviders>(
|
||||
|
||||
@@ -4,11 +4,11 @@ import { PolicyType } from "@bitwarden/common/admin-console/enums";
|
||||
import { Account } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { BoundDependency } from "@bitwarden/common/tools/dependencies";
|
||||
import { ExtensionSite } from "@bitwarden/common/tools/extension";
|
||||
import { SemanticLogger } from "@bitwarden/common/tools/log";
|
||||
import { SystemServiceProvider } from "@bitwarden/common/tools/providers";
|
||||
import { anyComplete, memoizedMap, pin } from "@bitwarden/common/tools/rx";
|
||||
import { UserStateSubject } from "@bitwarden/common/tools/state/user-state-subject";
|
||||
import { UserStateSubjectDependencyProvider } from "@bitwarden/common/tools/state/user-state-subject-dependency-provider";
|
||||
import { SemanticLogger } from "@bitwarden/logging";
|
||||
|
||||
import {
|
||||
GeneratorMetadata,
|
||||
|
||||
Reference in New Issue
Block a user