|
| 1 | +/** |
| 2 | + * Unified logging functions for example scripts |
| 3 | + * Provides consistent formatting and visual hierarchy across all tests |
| 4 | + */ |
| 5 | + |
| 6 | +/** |
| 7 | + * Print a section header with double-line border |
| 8 | + * @param {string} text - Header text |
| 9 | + */ |
| 10 | +export function logHeader(text) { |
| 11 | + console.log('\n' + '═'.repeat(80)); |
| 12 | + console.log(` ${text}`); |
| 13 | + console.log('═'.repeat(80)); |
| 14 | +} |
| 15 | + |
| 16 | +/** |
| 17 | + * Print a sub-section header with single-line border |
| 18 | + * @param {string} text - Section text |
| 19 | + */ |
| 20 | +export function logSection(text) { |
| 21 | + console.log('\n' + '─'.repeat(80)); |
| 22 | + console.log(` ${text}`); |
| 23 | + console.log('─'.repeat(80)); |
| 24 | +} |
| 25 | + |
| 26 | +/** |
| 27 | + * Log configuration parameters in a formatted table |
| 28 | + * @param {Object} config - Configuration object with key-value pairs |
| 29 | + */ |
| 30 | +export function logConfig(config) { |
| 31 | + console.log('\n📋 Configuration:'); |
| 32 | + for (const [key, value] of Object.entries(config)) { |
| 33 | + console.log(` ${key.padEnd(20)}: ${value}`); |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +/** |
| 38 | + * Log connection information (convenience function) |
| 39 | + * @param {string} wsUrl - WebSocket URL |
| 40 | + * @param {string} seed - Account seed or address |
| 41 | + * @param {string} ipfsApi - IPFS API URL |
| 42 | + */ |
| 43 | +export function logConnection(wsUrl, seed, ipfsApi) { |
| 44 | + logConfig({ |
| 45 | + 'RPC Endpoint': wsUrl, |
| 46 | + 'Account/Seed': seed, |
| 47 | + 'IPFS API': ipfsApi |
| 48 | + }); |
| 49 | +} |
| 50 | + |
| 51 | +/** |
| 52 | + * Log a step in the process |
| 53 | + * @param {string} step - Step indicator (e.g., "1️⃣", "2️⃣") |
| 54 | + * @param {string} message - Step description |
| 55 | + */ |
| 56 | +export function logStep(step, message) { |
| 57 | + console.log(`\n${step} ${message}`); |
| 58 | +} |
| 59 | + |
| 60 | +/** |
| 61 | + * Log success message |
| 62 | + * @param {string} message - Success message |
| 63 | + */ |
| 64 | +export function logSuccess(message) { |
| 65 | + console.log(`✅ ${message}`); |
| 66 | +} |
| 67 | + |
| 68 | +/** |
| 69 | + * Log error message |
| 70 | + * @param {string} message - Error message |
| 71 | + */ |
| 72 | +export function logError(message) { |
| 73 | + console.error(`❌ ${message}`); |
| 74 | +} |
| 75 | + |
| 76 | +/** |
| 77 | + * Log info message |
| 78 | + * @param {string} message - Info message |
| 79 | + */ |
| 80 | +export function logInfo(message) { |
| 81 | + console.log(`ℹ️ ${message}`); |
| 82 | +} |
| 83 | + |
| 84 | +/** |
| 85 | + * Log warning message |
| 86 | + * @param {string} message - Warning message |
| 87 | + */ |
| 88 | +export function logWarning(message) { |
| 89 | + console.log(`⚠️ ${message}`); |
| 90 | +} |
| 91 | + |
| 92 | +/** |
| 93 | + * Log final test result with banner |
| 94 | + * @param {boolean} passed - Whether the test passed |
| 95 | + * @param {string} testName - Name of the test (default: "Test") |
| 96 | + */ |
| 97 | +export function logTestResult(passed, testName = 'Test') { |
| 98 | + console.log('\n' + '═'.repeat(80)); |
| 99 | + if (passed) { |
| 100 | + console.log(` ✅✅✅ ${testName} PASSED! ✅✅✅`); |
| 101 | + } else { |
| 102 | + console.log(` ❌❌❌ ${testName} FAILED! ❌❌❌`); |
| 103 | + } |
| 104 | + console.log('═'.repeat(80) + '\n'); |
| 105 | +} |
0 commit comments