UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

83 lines 3.67 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.accessLogger = exports.appLogger = void 0; // utils/logger.ts const winston_1 = __importDefault(require("winston")); const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file")); const path_1 = __importDefault(require("path")); const MiscUtils_1 = require("../utils/MiscUtils"); // Private constants and utility functions const APP_LOG_MAX_SIZE = '1m'; const ACCESS_LOG_MAX_SIZE = '5m'; const MAX_FILES = 2; /** * Formats an error object into a detailed string representation */ function formatError(error) { return `${error.constructor.name}: ${error.message}\n${error.stack || ''}`; } // Configure common logging settings const basePath = MiscUtils_1.MiscUtils.baseWorkingDirectory(); const timestampFormat = 'YYYY-MM-DD HH:mm:ss'; // Custom format that handles errors properly const errorAwareFormat = winston_1.default.format((info) => { if (info instanceof Error) { return { ...info, message: formatError(info), stack: info.stack, name: info.constructor.name, }; } else if (info.error instanceof Error) { return { ...info, message: `${info.message}\n${formatError(info.error)}`, stack: info.error.stack, name: info.error.constructor.name, }; } return info; }); // Create and export the application logger directly exports.appLogger = winston_1.default.createLogger({ level: 'info', format: winston_1.default.format.combine(errorAwareFormat(), winston_1.default.format.timestamp({ format: timestampFormat }), winston_1.default.format.json()), transports: [ // Console transport (stderr) new winston_1.default.transports.Console({ stderrLevels: ['info', 'warn', 'error'], format: winston_1.default.format.combine(winston_1.default.format.timestamp({ format: 'HH:mm:ss.SSS' }), winston_1.default.format.printf(({ timestamp, level, message, thread = 'main', stack }) => `${timestamp} [${thread}] ${level.toUpperCase().padEnd(5)} ${message}${stack ? '\n' + stack : ''}`)), }), // File transport with rotation new winston_daily_rotate_file_1.default({ filename: path_1.default.join(basePath, 'app.log'), maxSize: APP_LOG_MAX_SIZE, maxFiles: MAX_FILES, zippedArchive: false, }), ], }); // Create and export the access logger directly exports.accessLogger = winston_1.default.createLogger({ level: 'info', format: winston_1.default.format.combine(winston_1.default.format.timestamp({ format: timestampFormat }), winston_1.default.format.printf(({ timestamp, message }) => `${timestamp} access - ${message}`)), transports: [ // Console transport (stderr) new winston_1.default.transports.Console({ stderrLevels: ['info', 'warn', 'error'], format: winston_1.default.format.combine(winston_1.default.format.timestamp({ format: 'HH:mm:ss.SSS' }), winston_1.default.format.printf(({ timestamp, message }) => `${timestamp} access - ${message}`)), }), // File transport with rotation new winston_daily_rotate_file_1.default({ filename: path_1.default.join(basePath, 'access.log'), maxSize: ACCESS_LOG_MAX_SIZE, maxFiles: MAX_FILES, zippedArchive: false, }), ], }); //# sourceMappingURL=Logger.js.map