UNPKG

@agility/cli

Version:

Agility CLI for working with your content. (Public Beta)

246 lines 9.58 kB
"use strict"; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileLogger = void 0; var fileOperations_1 = require("../../../core/fileOperations"); var state_1 = require("../../../core/state"); var FileLogger = /** @class */ (function () { function FileLogger(config) { this.logEntries = []; this.config = config; this.fileOps = new fileOperations_1.fileOperations(config.guid, config.locale); } /** * Create FileLogger from current state */ FileLogger.fromState = function (operationType, guid) { var state = (0, state_1.getState)(); var targetGuid = guid || state.sourceGuid; return new FileLogger({ rootPath: state.rootPath, guid: targetGuid[0], locale: state.locale[0], preview: state.preview, operationType: operationType }); }; /** * Log a message with specific level */ FileLogger.prototype.log = function (level, message, context) { var entry = { timestamp: new Date().toISOString(), level: level, message: message, context: context }; this.logEntries.push(entry); // Use existing fileOperations.appendLogFile (handles ANSI stripping) var formattedMessage = this.formatLogEntry(entry); this.fileOps.appendLogFile(formattedMessage); }; /** * Format log entry for file output */ FileLogger.prototype.formatLogEntry = function (entry) { var contextPart = entry.context ? " [".concat(entry.context, "]") : ''; return "[".concat(entry.timestamp, "] [").concat(entry.level, "]").concat(contextPart, " ").concat(entry.message, "\n"); }; /** * Log info message */ FileLogger.prototype.logInfo = function (message, context) { this.log('INFO', message, context); }; /** * Log error message */ FileLogger.prototype.logError = function (message, context) { this.log('ERROR', message, context); }; /** * Log warning message */ FileLogger.prototype.logWarning = function (message, context) { this.log('WARNING', message, context); }; /** * Log success message */ FileLogger.prototype.logSuccess = function (message, context) { this.log('SUCCESS', message, context); }; /** * Log step start */ FileLogger.prototype.logStepStart = function (stepName, details) { var message = details ? "Starting ".concat(stepName, " - ").concat(details) : "Starting ".concat(stepName); this.logInfo(message, 'STEP'); }; /** * Log step completion */ FileLogger.prototype.logStepComplete = function (stepName, details) { var message = details ? "Completed ".concat(stepName, " - ").concat(details) : "Completed ".concat(stepName); this.logSuccess(message, 'STEP'); }; /** * Log step error */ FileLogger.prototype.logStepError = function (stepName, error) { this.logError("Failed ".concat(stepName, ": ").concat(error), 'STEP'); }; /** * Log progress update */ FileLogger.prototype.logProgress = function (stepName, progress) { var percentage = Math.round((progress.current / progress.total) * 100); var details = progress.details ? " - ".concat(progress.details) : ''; var message = "".concat(stepName, ": ").concat(progress.current, "/").concat(progress.total, " (").concat(percentage, "%)").concat(details); this.logInfo(message, 'PROGRESS'); }; /** * Log download statistics */ FileLogger.prototype.logDownloadStats = function (stepName, stats) { var total = stats.total, successful = stats.successful, failed = stats.failed, skipped = stats.skipped, duration = stats.duration; var durationText = duration ? " in ".concat((duration / 1000).toFixed(1), "s") : ''; var message = "".concat(stepName, " completed: ").concat(successful, "/").concat(total, " successful, ").concat(failed, " failed, ").concat(skipped, " skipped").concat(durationText); this.logInfo(message, 'STATS'); }; /** * Log upload statistics */ FileLogger.prototype.logUploadStats = function (stepName, stats) { var total = stats.total, successful = stats.successful, failed = stats.failed, skipped = stats.skipped, duration = stats.duration; var durationText = duration ? " in ".concat((duration / 1000).toFixed(1), "s") : ''; var message = "".concat(stepName, " uploaded: ").concat(successful, "/").concat(total, " successful, ").concat(failed, " failed, ").concat(skipped, " skipped").concat(durationText); this.logInfo(message, 'STATS'); }; /** * Log summary information */ FileLogger.prototype.logSummary = function (operation, summary) { var duration = (summary.endTime.getTime() - summary.startTime.getTime()) / 1000; var message = "".concat(operation, " Summary: ").concat(summary.successfulSteps, "/").concat(summary.totalSteps, " steps completed in ").concat(duration.toFixed(1), "s"); this.logInfo(message, 'SUMMARY'); if (summary.entityCounts) { var entitySummary = Object.entries(summary.entityCounts) .map(function (_a) { var type = _a[0], count = _a[1]; return "".concat(type, ": ").concat(count); }) .join(', '); this.logInfo("Entity counts: ".concat(entitySummary), 'SUMMARY'); } }; /** * Log API operation */ FileLogger.prototype.logApiOperation = function (operation, details) { var method = details.method, endpoint = details.endpoint, success = details.success, duration = details.duration, error = details.error; var endpointText = endpoint ? " ".concat(endpoint) : ''; var durationText = duration ? " (".concat(duration, "ms)") : ''; var level = success ? 'SUCCESS' : 'ERROR'; var statusText = success ? 'succeeded' : 'failed'; var errorText = error ? ": ".concat(error) : ''; var message = "".concat(operation, " ").concat(method).concat(endpointText, " ").concat(statusText).concat(durationText).concat(errorText); this.log(level, message, 'API'); }; /** * Log configuration details */ FileLogger.prototype.logConfig = function (config) { var configEntries = Object.entries(config) .map(function (_a) { var key = _a[0], value = _a[1]; return "".concat(key, ": ").concat(value); }) .join(', '); this.logInfo("Configuration: ".concat(configEntries), 'CONFIG'); }; /** * Log system information */ FileLogger.prototype.logSystemInfo = function () { var _this = this; var info = { nodeVersion: process.version, platform: process.platform, arch: process.arch, timestamp: new Date().toISOString(), guid: this.config.guid, locale: this.config.locale, operationType: this.config.operationType }; this.logInfo('System Information:', 'SYSTEM'); Object.entries(info).forEach(function (_a) { var key = _a[0], value = _a[1]; _this.logInfo(" ".concat(key, ": ").concat(value), 'SYSTEM'); }); }; /** * Get all log entries */ FileLogger.prototype.getLogEntries = function () { return __spreadArray([], this.logEntries, true); }; /** * Get log entries by level */ FileLogger.prototype.getLogEntriesByLevel = function (level) { return this.logEntries.filter(function (entry) { return entry.level === level; }); }; /** * Get log entries by context */ FileLogger.prototype.getLogEntriesByContext = function (context) { return this.logEntries.filter(function (entry) { return entry.context === context; }); }; /** * Get log statistics */ FileLogger.prototype.getLogStats = function () { var stats = { INFO: 0, ERROR: 0, WARNING: 0, SUCCESS: 0 }; this.logEntries.forEach(function (entry) { stats[entry.level]++; }); return stats; }; /** * Clear log entries (keeps file contents) */ FileLogger.prototype.clearLogEntries = function () { this.logEntries = []; }; /** * Finalize log file and return path */ FileLogger.prototype.finalize = function () { var finalStats = this.getLogStats(); this.logInfo("Log finalized with ".concat(this.logEntries.length, " entries: ").concat(JSON.stringify(finalStats)), 'FINALIZE'); return this.fileOps.finalizeLogFile(this.config.operationType); }; /** * Get underlying fileOperations instance */ FileLogger.prototype.getFileOps = function () { return this.fileOps; }; return FileLogger; }()); exports.FileLogger = FileLogger; //# sourceMappingURL=file-logger.js.map