UNPKG

thrilled-be-core

Version:

Core Express backend package with middleware, logging, security, and base application setup

66 lines (65 loc) 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Logger_1 = require("../logging/Logger"); // Example 1: Using the default logger console.log('=== Example 1: Default Logger ==='); Logger_1.defaultLogger.info('Application starting up'); Logger_1.defaultLogger.warn('This is a warning message'); Logger_1.defaultLogger.error('This is an error message'); // Example 2: Creating a custom logger for a service console.log('\n=== Example 2: Custom Service Logger ==='); const apiLogger = (0, Logger_1.createLogger)({ level: 'debug', dir: './logs/api', format: 'json', maxFiles: 7, }); apiLogger.info('API server starting', { port: 3000, env: 'development' }); apiLogger.debug('Database connection established', { host: 'localhost', db: 'myapp', }); // Example 3: Error logging with Error objects console.log('\n=== Example 3: Error Handling ==='); const authLogger = (0, Logger_1.createLogger)({ level: 'info', dir: './logs/auth', format: 'simple', }); try { // Simulate an error throw new Error('Invalid credentials'); } catch (error) { authLogger.error(error, { userId: 123, action: 'login_attempt', ip: '192.168.1.1', }); } // Example 4: Different log levels console.log('\n=== Example 4: Log Levels ==='); const appLogger = Logger_1.Logger.create({ level: 'debug', dir: './logs/app', correlationId: true, }); appLogger.error('Critical error occurred'); appLogger.warn('Memory usage is high', { memoryUsage: '85%' }); appLogger.info('User registered successfully', { userId: 456, email: 'user@example.com', }); appLogger.debug('Processing request', { requestId: 'req-789', step: 'validation', }); // Example 5: Disabling correlation IDs console.log('\n=== Example 5: Without Correlation IDs ==='); const simpleLogger = (0, Logger_1.createLogger)({ level: 'info', dir: './logs/simple', correlationId: false, }); simpleLogger.info('Simple log message without correlation ID'); console.log('\nLogger examples completed. Check the ./logs directories for generated log files.');