UNPKG

playwright-ai-codegen-lib

Version:

A utility to auto-generate Playwright PageObjects and test scripts using OpenAI and DOM extraction.

39 lines (38 loc) 1.92 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Logger = void 0; const util_1 = __importDefault(require("util")); class Logger { static log(message, ...args) { const { timestamp, className, functionName } = Logger.extractLogDetails(); const formattedMessage = util_1.default.format(message, ...args); console.log(`[INFO] ---- [${timestamp}] --> [${className}.${functionName}] ${formattedMessage}`); } static warning(message, ...args) { const { timestamp, className, functionName } = Logger.extractLogDetails(); const formattedMessage = util_1.default.format(message, ...args); // Using ANSI escape codes to set the text color to amber (yellow) console.warn(`\x1b[33m[WARNING] ---- [${timestamp}] --> [${className}.${functionName}] ${formattedMessage}\x1b[0m`); } static error(error, ...args) { const { timestamp, className, functionName } = Logger.extractLogDetails(); // Using ANSI escape codes to set the text color to red console.error(`\x1b[31mERROR ----- [${timestamp}] --> [${className}.${functionName}] Error: ${error.message}\x1b[0m`); console.error(error.stack); } static extractLogDetails() { const rawTimestamp = new Date(); const timestamp = rawTimestamp.toLocaleString('en-NZ', { timeZone: 'Pacific/Auckland' }); const stack = new Error().stack; const stackLines = stack.split('\n'); const callerLine = stackLines[3] || ''; const match = callerLine.match(/at (\w+).(\w+)/) || []; const className = match[1] || 'Global'; const functionName = match[2] || 'anonymous'; return { timestamp, className, functionName }; } } exports.Logger = Logger;