### Install Elenora Source: https://github.com/developerkubilay/elenora/blob/main/README.md The installation command for the Elenora package using npm. ```bash npm install elenora ``` -------------------------------- ### Quick Start: Console Integration Source: https://github.com/developerkubilay/elenora/blob/main/README.md Demonstrates how to wrap the global console object to automatically route logs to a rotating file system. ```javascript const elenora = require('elenora'); // Wrap console and write to logs/app.log elenora.connect(console, { filename: 'logs/app.log', maxSize: 5 * 1024 * 1024, // 5 MB backupCount: 3, continueFromLast: true, // keep history across restarts interval: 500 // flush interval in ms }); console.log('Server started'); console.info('Listening on port 3000'); console.warn('Spicy warning'); console.error('Something exploded'); ``` -------------------------------- ### Custom Log Formatting Source: https://github.com/developerkubilay/elenora/blob/main/README.md Examples of implementing custom formatters to output logs as JSON lines or binary Buffers. ```javascript function jsonFormatter(entry, date) { return JSON.stringify({ ts: date, level: entry.level, message: entry.message }) + '\n'; } elenora.connect(console, { filename: 'logs/json.log', maxSize: 1024 * 1024, backupCount: 3, Formatter: jsonFormatter }); function bufferFormatter(entry, date) { const line = `[${entry.level}] ${date} :: ${entry.message}\n`; return Buffer.from(line, 'utf8'); } ``` -------------------------------- ### Create Standalone Logger Instance Source: https://github.com/developerkubilay/elenora/blob/main/README.md Shows how to instantiate a dedicated logger object instead of patching the global console. ```javascript const elenora = require('elenora'); const logger = elenora.newLog({ filename: 'logs/api.log', maxSize: 2 * 1024 * 1024, backupCount: 2 }); logger.log('api online'); logger.info('GET /health ok'); logger.warn('rate limit close'); logger.error('db timeout'); ``` -------------------------------- ### Define Logger Configuration and Types Source: https://github.com/developerkubilay/elenora/blob/main/README.md TypeScript interfaces and function signatures for configuring the logger and defining log entry structures. ```typescript connect(output: any, options?: { filename?: string; maxSize?: number; // bytes, default 5 * 1024 * 1024 backupCount?: number; // default 0 interval?: number; // ms, default 1000 timeZone?: string; // passed to toLocaleString continueFromLast?: boolean;// default false Formatter?: (entry: LogEntry, dateString: string) => string | Buffer; }) interface LogEntry { level: 'LOG' | 'INFO' | 'WARN' | 'ERROR'; message: string; } ``` -------------------------------- ### Custom Log Formatting with Elenora Source: https://context7.com/developerkubilay/elenora/llms.txt Demonstrates how to use the `Formatter` option in Elenora to control log output. Supports string or Buffer return types for flexible formatting, such as JSON Lines or custom binary formats. Requires the 'elenora' package. ```javascript const elenora = require('elenora'); // JSON Lines formatter for log aggregation systems (Elasticsearch, Splunk, etc.) function jsonFormatter(entry, dateString) { return JSON.stringify({ timestamp: dateString, level: entry.level.toLowerCase(), message: entry.message, service: 'my-api', version: '1.0.0' }) + '\n'; } elenora.connect(console, { filename: 'logs/json.log', maxSize: 1024 * 1024, backupCount: 3, Formatter: jsonFormatter }); console.log('User authenticated'); // Output: {"timestamp":"16.11.2025 12:47:39","level":"log","message":"User authenticated","service":"my-api","version":"1.0.0"} console.error('Payment failed', { orderId: 'ORD-123' }); // Output: {"timestamp":"16.11.2025 12:47:40","level":"error","message":"Payment failed {\"orderId\":\"ORD-123\"}","service":"my-api","version":"1.0.0"} // Buffer formatter for precise byte control function bufferFormatter(entry, date) { const line = `[${entry.level}] ${date} :: ${entry.message}\n`; return Buffer.from(line, 'utf8'); } const binaryLogger = elenora.newLog({ filename: 'logs/binary.log', maxSize: 512 * 1024, Formatter: bufferFormatter }); binaryLogger.info('Binary formatted log entry'); // Output: [INFO] 16.11.2025 12:47:41 :: Binary formatted log entry ``` -------------------------------- ### Log Rotation and Backup Management with Elenora Source: https://context7.com/developerkubilay/elenora/llms.txt Explains Elenora's byte-based log rotation and backup system. Files are rotated when `maxSize` is reached, with backups managed by `backupCount`. Ensures files are rewritten cleanly on rotation. Requires the 'elenora' package. ```javascript const elenora = require('elenora'); // Configure for high-throughput logging with aggressive rotation elenora.connect(console, { filename: 'logs/high-volume.log', maxSize: 1024 * 4, // 4 KB per file (small for demonstration) backupCount: 3, // Keep 3 backups (total 4 files max) interval: 200, // Flush every 200ms for near real-time writes continueFromLast: false // Start fresh on each process start }); // Generate logs that trigger rotation for (let i = 0; i < 100; i++) { console.log(`Event ${i.toString().padStart(3, '0')}: ${'x'.repeat(50)}`); } // After rotation, disk contains: // logs/high-volume.log - newest entries (up to 4 KB) // logs/Backup_0_high-volume.log - slightly older (up to 4 KB) // logs/Backup_1_high-volume.log - older (up to 4 KB) // logs/Backup_2_high-volume.log - oldest kept (up to 4 KB) // Total disk usage: maxSize * (1 + backupCount) = 4 KB * 4 = 16 KB max ``` -------------------------------- ### Creating Standalone Loggers with elenora.newLog Source: https://context7.com/developerkubilay/elenora/llms.txt The newLog function initializes a dedicated logger instance that operates independently of the global console. This allows for multiple loggers with unique configurations and file destinations. ```javascript const elenora = require('elenora'); const apiLogger = elenora.newLog({ filename: 'logs/api.log', maxSize: 2 * 1024 * 1024, backupCount: 2, interval: 500 }); const errorLogger = elenora.newLog({ filename: 'logs/errors.log', maxSize: 10 * 1024 * 1024, backupCount: 5, continueFromLast: true }); apiLogger.log('GET /api/users - 200 OK'); apiLogger.info('Request processed in 45ms'); errorLogger.error('Unhandled exception in payment processor'); errorLogger.warn('Retry attempt 3 of 5'); ``` -------------------------------- ### Patching Console with elenora.connect Source: https://context7.com/developerkubilay/elenora/llms.txt The connect function wraps the global console object to intercept log, info, warn, and error calls. It buffers logs in memory and flushes them to a rotating file based on the specified maxSize and backupCount. ```javascript const elenora = require('elenora'); elenora.connect(console, { filename: 'logs/app.log', maxSize: 5 * 1024 * 1024, backupCount: 3, interval: 1000, timeZone: 'America/New_York', continueFromLast: true }); console.log('Application started'); console.info('Server listening on port 3000'); console.warn('Memory usage high'); console.error('Database connection failed'); console.log({ userId: 123, action: 'login' }); console.log([1, 2, 3], 'items processed'); ``` -------------------------------- ### Crash-Safe Flushing with Elenora Source: https://context7.com/developerkubilay/elenora/llms.txt Details Elenora's automatic crash-safe flushing mechanism. Logs are guaranteed to be written to disk before process termination by handling exit signals like SIGINT and SIGTERM. Uses synchronous I/O for final writes. Requires the 'elenora' package. ```javascript const elenora = require('elenora'); // Logs are automatically flushed on process exit elenora.connect(console, { filename: 'logs/critical.log', maxSize: 5 * 1024 * 1024, backupCount: 2, interval: 5000 // 5 second flush interval }); console.log('Process starting...'); console.info('Initializing services...'); // Even if process is killed before the 5-second interval, // these logs will be written via the exit handler process.on('SIGTERM', () => { console.log('Received SIGTERM, shutting down gracefully'); // elenora's internal handler flushes logs synchronously // before process.exit(0) completes }); // Simulate work setTimeout(() => { console.log('Work completed'); }, 2000); // If Ctrl+C is pressed, SIGINT handler ensures logs are flushed // All buffered entries are written synchronously to disk ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.