All files / runtime/_services logger.service.ts

98% Statements 98/100
76.92% Branches 10/13
80% Functions 8/10
98% Lines 98/100

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1011x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 1x 1x 1x 7x 7x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import { DyE2E_TestUser_Interface } from '../_models/test-user.interface';
 
/**
 * MP-07 SP-C lift — strukturált E2E-logger.
 *
 * Eredete: `fdp-e2e-helpers/_services/e2e-logger.service.ts` (BL-20260518-006).
 * FDP-szintű függőségek (`@futdevpro/fsm-dynamo` `DyFM_Log` +
 * `@futdevpro/nts-dynamo` `DyNTS_SingletonService`) eltávolítva — generic
 * `DyE2E_LoggerOutput` interfész + `console`-alapú default impl.
 *
 * Consumer-projekt felülírhatja a `setOutput()` hívással bármilyen sajat
 * sink-et (Discord-webhook, file-logger, structured-log-aggregator).
 */
export interface DyE2E_LoggerOutput {
  info(msg: string, metadata?: Record<string, unknown>): void;
  success(msg: string, metadata?: Record<string, unknown>): void;
  error(msg: string, metadata?: Record<string, unknown>): void;
}
 
/** Default console-alapú logger output. */
export const DYE2E_CONSOLE_LOGGER: DyE2E_LoggerOutput = {
  info(msg: string, metadata?: Record<string, unknown>): void {
    console.log(msg, metadata ? JSON.stringify(metadata) : '');
  },
  success(msg: string, metadata?: Record<string, unknown>): void {
    console.log(msg, metadata ? JSON.stringify(metadata) : '');
  },
  error(msg: string, metadata?: Record<string, unknown>): void {
    console.error(msg, metadata ? JSON.stringify(metadata) : '');
  },
};
 
/**
 * Stateless logger — `[E2E]` prefix + structured metadata payload.
 *
 * 4 method: logTestStart / logTestSuccess / logTestFailure / logUserAction.
 */
export class DyE2E_LoggerService {
 
  private static output: DyE2E_LoggerOutput = DYE2E_CONSOLE_LOGGER;
 
  /** Output sink override (Discord-webhook, file, structured-log). */
  static setOutput(output: DyE2E_LoggerOutput): void {
    DyE2E_LoggerService.output = output;
  }
 
  /** Vissza-default a console-output-ra. */
  static resetOutput(): void {
    DyE2E_LoggerService.output = DYE2E_CONSOLE_LOGGER;
  }
 
  static logTestStart(
    testName: string,
    module: string,
    environment: string,
    user?: DyE2E_TestUser_Interface,
  ): void {
    DyE2E_LoggerService.output.info(`[E2E] Test started: ${testName}`, {
      testName: testName,
      module: module,
      environment: environment,
      userEmail: user?.email,
      isPersistent: user?.isPersistent,
    });
  }
 
  static logTestSuccess(testName: string, module: string, durationMs: number): void {
    DyE2E_LoggerService.output.success(`[E2E] Test passed: ${testName} (${durationMs}ms)`, {
      testName: testName,
      module: module,
      duration: durationMs,
    });
  }
 
  static logTestFailure(
    testName: string,
    module: string,
    error: Error,
    user?: DyE2E_TestUser_Interface,
  ): void {
    DyE2E_LoggerService.output.error(`[E2E] Test failed: ${testName}`, {
      testName: testName,
      module: module,
      errorMessage: error.message,
      errorStack: error.stack,
      userEmail: user?.email,
      isPersistent: user?.isPersistent,
    });
  }
 
  static logUserAction(action: string, user: DyE2E_TestUser_Interface): void {
    DyE2E_LoggerService.output.info(`[E2E] User action: ${action}`, {
      action: action,
      userEmail: user.email,
      username: user.username,
      isPersistent: user.isPersistent,
      testContext: user.testContext,
    });
  }
}