JEISA-WEBAPP/test-logging.js
2025-09-25 00:15:35 +02:00

49 lines
1.5 KiB
JavaScript

import logger from './src/lib/logger.js';
// Test the logging system
async function testLogging() {
console.log('🧪 Testing logging system...');
try {
// Set a test user
logger.setUser('test-user');
// Test different log levels
await logger.info('Application started', 'JEI Stock App has been started successfully');
await logger.warn('Low stock warning', 'Product ABC has low stock levels', {
product: 'ABC',
currentStock: 5
});
await logger.error('Database connection failed', 'Failed to connect to external API', {
endpoint: 'https://api.example.com',
statusCode: 500
});
await logger.debug('User interaction', 'User clicked on stock item', {
itemId: 'stock-123',
timestamp: new Date().toISOString()
});
// Test convenience methods
await logger.logStockOperation('added', 'Test Product', 100, 'admin');
await logger.logCustomerOperation('created', 'Test Company', 'admin');
await logger.logBookOutOperation('Test Company', [
{ name: 'Test Product', quantity: 10 }
], 'admin');
console.log('✅ Successfully created test logs!');
// Retrieve and display logs
const logs = await logger.getLogs({ limit: 10 });
console.log('📋 Recent logs:');
console.log(logs.items.map(log => `${log.level.toUpperCase()}: ${log.action} - ${log.details || 'No details'}`));
} catch (error) {
console.error('❌ Error testing logging:', error);
}
}
// Run the test
testLogging();