### Production Setup Example Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/usage.mdx A comprehensive example demonstrating a production-ready Logixlysia setup. It includes file logging with rotation, log filtering for errors and warnings, and Pino configuration for sensitive data redaction. ```typescript const app = new Elysia() .use( logixlysia({ config: { logFilePath: './logs/production.log', logRotation: { maxSize: '100m', interval: '1d', maxFiles: '30d', compress: true }, logFilter: { level: ['ERROR', 'WARNING'] }, pino: { level: 'info', redact: ['password', 'token', 'apiKey'] } } }) ) .listen(3000) ``` -------------------------------- ### Elysia Setup with Startup Message Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/examples.mdx Configures Logixlysia to display a startup message using a banner format. This is useful for confirming the server has started and is logging. ```typescript const app = new Elysia() .use( logixlysia({ config: { showStartupMessage: true, startupMessageFormat: 'banner' } }) ) .listen(3000) ``` -------------------------------- ### Install and Run Elysia Playground Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/elysia/README.md Commands to install dependencies, navigate to the Elysia app directory, and run the development server. ```bash bun install cd apps/elysia bun run dev ``` -------------------------------- ### Install Dependencies with Bun Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/contributing.mdx Install project dependencies using Bun. This command should be run after cloning the repository. ```bash bun install ``` -------------------------------- ### Complete Logixlysia Configuration Example Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/configuration.mdx A comprehensive example demonstrating various configuration options for Logixlysia, including startup messages, display settings, formatting, file logging, output control, and Pino integration. ```typescript logixlysia({ config: { // Startup showStartupMessage: true, startupMessageFormat: 'banner', // Display useColors: true, ip: true, autoRedact: false, logQueryParams: false, // Formatting timestamp: { translateTime: 'yyyy-mm-dd HH:MM:ss' }, customLogFormat: '{now} {level} {duration}ms {method} {pathname} {status}', // File Logging logFilePath: './logs/app.log', logRotation: { maxSize: '100m', interval: '1d', maxFiles: '30d', compress: true }, // Output Control disableInternalLogger: false, disableFileLogging: false, useTransportsOnly: false, transports: [], // Pino pino: { level: 'info', prettyPrint: false, redact: ['password', 'token'], base: { service: 'my-api', version: '1.0.0' } } } }) ``` -------------------------------- ### Install OpenTelemetry Peer Dependency Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/otel.mdx Install the optional `@opentelemetry/api` package using Bun. ```bash bun add @opentelemetry/api ``` -------------------------------- ### Dynamic Configuration based on Environment Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/examples.mdx Configure Logixlysia settings dynamically using environment variables for development and production. This example shows conditional setup for startup messages, log file paths, Pino options, and transports. ```typescript const isDev = process.env.NODE_ENV === 'development' const isProd = process.env.NODE_ENV === 'production' app.use( logixlysia({ config: { showStartupMessage: isDev, startupMessageFormat: isDev ? 'banner' : 'simple', logFilePath: isProd ? './logs/production.log' : undefined, logRotation: isProd ? { maxSize: '100m', interval: '1d', maxFiles: '30d', compress: true } : undefined, pino: { level: isDev ? 'debug' : 'info', prettyPrint: isDev, redact: isProd ? ['password', 'token', 'apiKey'] : [], base: { service: 'my-api', version: process.env.APP_VERSION, environment: process.env.NODE_ENV } }, transports: isProd ? [ elasticsearchTransport, slackTransport ] : [] } }) ) ``` -------------------------------- ### Context Tree Example (No Colors) Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/formatting.mdx An example of how context tree branches are displayed without ANSI colors. It shows nested key-value pairs, including an appended error row for error logs. ```plaintext ├─ orderId ord_123 └─ error Card declined ``` -------------------------------- ### Elysia Plugin Setup: evlog vs Logixlysia Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/migration-from-evlog.mdx Compares the setup for evlog and Logixlysia plugins in Elysia. Use evlog with a custom drain, and Logixlysia with a preset. ```typescript import { evlog } from 'evlog/elysia' new Elysia().use(evlog({ drain: myDrain })) ``` ```typescript import logixlysia from 'logixlysia' new Elysia().use(logixlysia({ preset: 'prod' })) ``` -------------------------------- ### Complete REST API with Logixlysia Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/examples.mdx A full Elysia REST API example demonstrating the integration of Logixlysia with basic Pino configuration and usage of `store.pino` for logging within routes. Includes examples for GET, POST, PUT, and DELETE requests. ```typescript import { Elysia } from 'elysia' import logixlysia from 'logixlysia' const app = new Elysia() .use(logixlysia({ config: { pino: { level: 'info', base: { service: 'user-api' } } } })) .get('/users', ({ store }) => { const { pino } = store pino.info({ action: 'list_users' }, 'Fetching users') return { users: [] } }) .get('/users/:id', ({ store, params }) => { const { pino } = store const userLogger = pino.child({ userId: params.id }) userLogger.info('Fetching user') return { user: { id: params.id } } }) .post('/users', ({ store, body }) => { const { pino } = store pino.info({ action: 'create_user' }, 'Creating user') return { user: body } }) .put('/users/:id', ({ store, params, body }) => { const { pino } = store pino.info({ userId: params.id, action: 'update_user' }, 'Updating user') return { user: { id: params.id, ...body } } }) .delete('/users/:id', ({ store, params }) => { const { pino } = store pino.info({ userId: params.id, action: 'delete_user' }, 'Deleting user') return { success: true } }) .listen(3000) ``` -------------------------------- ### Install Logixlysia with Bun Source: https://github.com/pungrumpy/logixlysia/blob/main/README.md Use this command to add the logixlysia package to your project using the Bun package manager. ```bash bun add logixlysia ``` -------------------------------- ### Structured Logging Example Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/pino.mdx Use structured logging by passing objects to Pino for better log analysis. This example logs user profile views. ```typescript app.get('/users/:id', ({ store, params }) => { const { pino } = store pino.info({ userId: params.id, action: 'view_profile', timestamp: Date.now() }, 'User profile viewed') return user }) ``` -------------------------------- ### Install Logixlysia with npm Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/faq.mdx Use this command to add Logixlysia to your project with npm. ```bash npm install logixlysia ``` -------------------------------- ### Best Practice: Log Performance Metrics Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/pino.mdx Example of logging performance metrics for an operation. ```typescript pino.info({ duration: 150, operation: 'db_query' }, 'Query completed') ``` -------------------------------- ### Branded Log Format Example (No Colors) Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/formatting.mdx An example of how a branded log line appears without ANSI colors or on a non-TTY output. It shows the basic structure including the service prefix and the fox icon. ```plaintext 2025-04-13T15:00:19.123Z [my-api]🦊 GET /api/users 200 12ms User viewed profile ``` -------------------------------- ### Production Log Rotation Configuration Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/log-rotation.mdx Example configuration for production environments, balancing file size, daily rotation, 30-day retention, and compression. ```typescript logRotation: { maxSize: '100m', interval: '1d', maxFiles: '30d', compress: true } ``` -------------------------------- ### Best Practice: Environment-based Configuration Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/pino.mdx Configure Pino settings like log level and pretty printing based on the environment. This example sets debug level and pretty printing for development. ```typescript const isDev = process.env.NODE_ENV === 'development' logixlysia({ config: { pino: { level: isDev ? 'debug' : 'info', prettyPrint: isDev } } }) ``` -------------------------------- ### Development Log Rotation Configuration Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/log-rotation.mdx Example configuration for development environments, using smaller file sizes, 7-day retention, and disabling compression. ```typescript logRotation: { maxSize: '10m', maxFiles: '7d', compress: false } ``` -------------------------------- ### Elysia.js Development Setup with Logixlysia Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/usage.mdx Configure Logixlysia for development with a startup message and debug logging. Ensure the Elysia app is listening on port 3000. ```typescript const app = new Elysia() .use( logixlysia({ config: { showStartupMessage: true, startupMessageFormat: 'banner', pino: { level: 'debug', prettyPrint: true } } }) ) .listen(3000) ``` -------------------------------- ### Environment-based Configuration Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/pino.mdx Configure Pino settings like log level and pretty printing based on the environment. This example sets debug level and pretty printing for development. ```typescript const isDev = process.env.NODE_ENV === 'development' logixlysia({ config: { pino: { level: isDev ? 'debug' : 'info', prettyPrint: isDev, redact: isDev ? [] : ['password', 'token', 'apiKey'], base: { service: 'my-api', environment: process.env.NODE_ENV } } } }) ``` -------------------------------- ### Best Practice: Create Child Loggers Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/pino.mdx Example of creating a child logger with a request ID for scoped logging. ```typescript const requestLogger = pino.child({ requestId: generateId() }) ``` -------------------------------- ### High-Volume Log Rotation Configuration Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/log-rotation.mdx Example configuration for high-volume logging scenarios, with large file sizes, hourly rotation, 7-day retention, and compression. ```typescript logRotation: { maxSize: '1g', interval: '1h', maxFiles: '7d', compress: true } ``` -------------------------------- ### Production Log Filter Configuration Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/log-levels.mdx Example configuration for production environments, typically logging only warnings and errors to reduce noise. ```typescript logFilter: { level: ['WARNING', 'ERROR'] } ``` -------------------------------- ### Minimal Log Format Example Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/formatting.mdx A minimal custom log format focusing on essential request details. This format is useful for concise logging where only the method, path, and status are critical. ```plaintext GET /api/users 200 ``` -------------------------------- ### Development Log Filter Configuration Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/log-levels.mdx Example configuration for development environments, enabling all log levels for maximum detail during debugging. ```typescript logFilter: { level: ['DEBUG', 'INFO', 'WARNING', 'ERROR'] } ``` -------------------------------- ### Configure Logixlysia with Production Preset Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/presets.mdx Use the 'preset' option for one-line environment defaults. Explicit 'config' fields will always override the preset. This example sets the preset to 'prod' and specifies custom service and log file path configurations. ```typescript import { Elysia } from 'elysia' import logixlysia from 'logixlysia' const app = new Elysia().use( logixlysia({ preset: 'prod', config: { service: 'api', logFilePath: './logs/app.log' } }) ) ``` -------------------------------- ### Quick cURL Commands for Elysia Routes Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/elysia/README.md Example cURL commands to test various routes of the Elysia application, including the root, checkout, chat, trace, status, and boom endpoints. ```bash curl http://localhost:3001/ ``` ```bash curl http://localhost:3001/checkout ``` ```bash curl -X POST http://localhost:3001/chat ``` ```bash curl http://localhost:3001/trace ``` ```bash curl http://localhost:3001/status/404 ``` ```bash curl http://localhost:3001/boom ``` -------------------------------- ### Monitoring Log Filter Configuration Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/log-levels.mdx Example configuration for monitoring, focusing solely on error logs to trigger alerts for critical issues. ```typescript logFilter: { level: ['ERROR'] } ``` -------------------------------- ### Performance Logging Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/pino.mdx Log performance metrics like operation duration to monitor application performance. This example logs the time taken for data processing. ```typescript app.post('/api/process', async ({ store, body }) => { const { pino } = store const startTime = Date.now() const result = await processData(body) pino.info({ operation: 'process_data', duration: Date.now() - startTime, itemsProcessed: result.count, success: true }, 'Data processing completed') return result }) ``` -------------------------------- ### Override Preset Options Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/presets.mdx This example demonstrates how to override specific options within a chosen preset. Here, 'prod' preset is used, but 'autoRedact' is set to false and 'showStartupMessage' to true, overriding the default 'prod' behavior. ```typescript logixlysia({ preset: 'prod', config: { autoRedact: false, showStartupMessage: true } }) ``` -------------------------------- ### Child Loggers for Context Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/pino.mdx Create child loggers with specific context, such as order IDs or module names, for more granular logging. This example logs order fetching details. ```typescript app.get('/api/orders/:id', ({ store, params }) => { const { pino } = store const orderLogger = pino.child({ orderId: params.id, module: 'order-service' }) orderLogger.info('Fetching order details') orderLogger.debug({ query: 'SELECT * FROM orders WHERE id = ?' }) return order }) ``` -------------------------------- ### Implement MongoDB Transport Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/transports.mdx An example transport that logs messages to a MongoDB collection. It includes basic error handling for the database insertion. ```typescript const mongodbTransport = { log: async (level, message, meta) => { try { await db.collection('logs').insertOne({ level, message, ...meta, timestamp: new Date() }) } catch (err) { console.error('MongoDB transport error', err) } } } ``` -------------------------------- ### Implement Elasticsearch Transport Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/transports.mdx An example transport that sends logs to an Elasticsearch instance. It handles potential network errors during the POST request. ```typescript const elasticsearchTransport = { log: async (level, message, meta) => { try { await fetch('http://elasticsearch:9200/logs/_doc', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ level, message, ...meta, timestamp: new Date().toISOString() }) }) } catch (err) { console.error('Elasticsearch transport error', err) } } } ``` -------------------------------- ### Error Logging Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/pino.mdx Log errors effectively by including error objects and relevant context. This example catches and logs errors from a risky operation. ```typescript app.get('/api/risky', ({ store }) => { const { pino } = store try { performRiskyOperation() } catch (error) { pino.error({ err: error, operation: 'risky_operation' }, 'Operation failed') throw error } }) ``` -------------------------------- ### Set Maximum Log Files or Retention Period Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/configuration.mdx Configure the maximum number of log files to keep or set a retention period in days. For example, '7d' keeps logs for 7 days. ```typescript maxFiles: '7d' // or 10 ``` -------------------------------- ### Simple Startup Message Format Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/startup.mdx Displays a minimal startup message. This format is recommended for production environments. ```text 🦊 Logixlysia is running on http://localhost:3000 ``` -------------------------------- ### Configure Startup Message Format Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/configuration.mdx Set the format for the startup message. Options are 'simple' or 'banner'. Defaults to 'banner'. ```typescript startupMessageFormat: 'simple' // or 'banner' ``` -------------------------------- ### Configure Startup Message Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/startup.mdx Enable and set the format for the startup message by passing configuration options to the Logixlysia constructor. Use 'simple' or 'banner' for the format. ```typescript logixlysia({ config: { showStartupMessage: true, startupMessageFormat: 'simple' // or 'banner' } }) ``` -------------------------------- ### Initialize Logixlysia with Pino for Standalone Use Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/pino.mdx Configure Logixlysia with Pino settings and export the Pino instance for use outside of HTTP request contexts. ```typescript // logger.ts import logixlysia from 'logixlysia' export const logixlysiaIns = logixlysia({ config: { logFilePath: './logs/app.log', pino: { level: 'info', base: { service: 'my-api', version: '1.0.0' } } } }) // Export Pino instance for standalone use export const logger = logixlysiaIns.store.pino ``` -------------------------------- ### Run Project Tests Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/contributing.mdx Execute the project's test suite using Bun. Ensure all tests pass before submitting changes. ```bash bun test ``` -------------------------------- ### Banner Startup Message Format Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/startup.mdx Displays a detailed ASCII art banner for the startup message. This format is the default and is useful for development. ```text ┌─────────────────────────────────────────────────┐ │ │ │ Elysia v1.4.19 │ │ │ │ 🦊 Elysia is running at http://localhost:3001 │ │ │ └─────────────────────────────────────────────────┘ ``` -------------------------------- ### Enable Startup Message Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/configuration.mdx Control whether the startup message is displayed when the server begins. Defaults to true. ```typescript showStartupMessage: true ``` -------------------------------- ### Filter Logs by HTTP Method Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/filtering.mdx Filter logs to include only requests made with a specific HTTP method like GET. ```typescript logFilter: { method: 'GET' // Only log GET requests } ``` -------------------------------- ### Throw Custom HttpError Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/api-reference.mdx Example of throwing a custom `HttpError` with a specific status code and message, useful for handling application-level errors. ```typescript throw new HttpError(404, 'User not found') ``` -------------------------------- ### Basic Logixlysia Configuration Options Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/usage.mdx Configure Logixlysia with basic options. Enable startup messages, set IP logging, control auto-redaction, log query parameters, and specify a log file path. ```typescript logixlysia({ config: { showStartupMessage: true, startupMessageFormat: 'simple', // or 'banner' ip: true, autoRedact: false, // Set to true to auto-redact sensitive PII (emails, IPs, credit cards, JWTs) logQueryParams: true, logFilePath: './logs/app.log' } }) ``` -------------------------------- ### Run Monorepo Benchmark Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/comparison.mdx Execute the benchmark suite within the monorepo to compare performance. Use results for regression tracking. ```bash bun run bench ``` -------------------------------- ### Initialize File Logging Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/file-logging.mdx Configure Logixlysia to save logs to a specified file path. Ensure the directory exists. ```typescript logixlysia({ config: { logFilePath: './logs/app.log' } }) ``` -------------------------------- ### Logixlysia Presets Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/usage.mdx Apply predefined configurations for different environments. Use 'dev' for pretty console logs and a banner, 'prod' for JSON logs with auto-redaction, or 'json' for minimal JSON console output. ```typescript logixlysia({ preset: 'dev' }) // pretty console + banner ``` ```typescript logixlysia({ preset: 'prod' }) // JSON logs + autoRedact ``` ```typescript logixlysia({ preset: 'json' }) // minimal JSON console ``` -------------------------------- ### Logixlysia Store Type Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/api-reference.mdx Defines the type for the store available within Elysia context when using Logixlysia. It includes the logger instance, direct Pino instance, and the request start time. ```typescript type LogixlysiaStore = { logger: Logger pino: Pino beforeTime?: bigint } ``` -------------------------------- ### Initialize Logixlysia Plugin Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/api-reference.mdx Use the main `logixlysia` function to add logging capabilities to your Elysia application. Configuration options can be passed to customize its behavior. ```typescript import logixlysia from 'logixlysia' const app = new Elysia() .use(logixlysia({ config: { showStartupMessage: true } })) ``` -------------------------------- ### Testing Logixlysia in Packages Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/elysia/README.md Commands to navigate to the logixlysia package directory and run tests, including integration tests and Node adapter smoke tests. ```bash cd packages/logixlysia bun test bun test __tests__/integration ``` -------------------------------- ### Configure Custom Pino Pretty Printing Options Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/pino.mdx Customize pretty printing for Pino logs with specific options like colorization and time translation. ```typescript logixlysia({ config: { pino: { prettyPrint: { colorize: true, translateTime: 'HH:MM:ss Z', ignore: 'pid,hostname' } } } }) ``` -------------------------------- ### JSON Format for Error Logs in Elysia Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/examples.mdx Configures Logixlysia to use a custom JSON log format, including specific fields like level, message, method, pathname, and status. This example also shows how errors are logged in this format. ```typescript app.use(logixlysia({ config: { customLogFormat: '{"level": "{level}", "message": "{message}", "method": "{method}", "pathname": "{pathname}", "status": "{status}"}' } })) app.get('/error', () => { throw new Error('Validation failed') }) ``` ```json {"level": "INFO", "message": "", "method": "GET", "pathname": "/hello", "status": "200"} {"level": "ERROR", "message": "Validation failed", "method": "GET", "pathname": "/error", "status": "500"} ``` -------------------------------- ### Basic Log Rotation Configuration Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/log-rotation.mdx Configure basic log rotation settings including file path, maximum size, retention period, and compression. ```typescript logixlysia({ config: { logFilePath: './logs/app.log', logRotation: { maxSize: '10m', // Rotate when file reaches 10MB maxFiles: '7d', // Keep logs for 7 days compress: true // Compress rotated logs } } }) ``` -------------------------------- ### Configure Both Pino and Logixlysia Transports Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/pino.mdx Demonstrates how to configure separate transports for Pino's application logs and Logixlysia's HTTP request logs. ```typescript logixlysia({ config: { // Pino transport - only for store.pino.* logs pino: { transport: { target: 'pino/file', options: { destination: './logs/pino-example.log' } } }, // Logixlysia transports - only for HTTP request logs transports: [customTransport] } }) app.get('/example', ({ store }) => { // This log goes to pino/file transport store.pino.info({ feature: 'pino' }, 'pino log example') // HTTP request logs go to Logixlysia transports (if configured) // or to console/file based on logixlysia config }) ``` -------------------------------- ### Emitting Request Logs: evlog log.emit vs Logixlysia manual logging Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/migration-from-evlog.mdx Shows how to emit logs with evlog using `log.emit`. Logixlysia emits access logs automatically in `onAfterHandle`, but custom logging can be done with `store.logger.info` to skip the default. ```typescript log.emit({ status: 200 }) ``` ```typescript store.logger.info(request, 'handled manually') ``` -------------------------------- ### Development Logixlysia Configuration Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/examples.mdx Configures Logixlysia for development with a startup message and pretty-printed JSON logs for better readability. The Pino configuration enables debug level logging. ```typescript const app = new Elysia() .use( logixlysia({ config: { showStartupMessage: true, startupMessageFormat: 'banner', // Pretty printing for development pino: { level: 'debug', prettyPrint: { colorize: true, translateTime: 'HH:MM:ss Z', ignore: 'pid,hostname' } } } }) ) .listen(3000) ``` -------------------------------- ### Best Practice: Structured Logging Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/pino.mdx Demonstrates the preferred method for logging messages using structured objects instead of string interpolation. ```typescript // ✅ Good pino.info({ userId: 123, action: 'login' }, 'User logged in') // ❌ Avoid pino.info(`User ${userId} logged in`) ``` -------------------------------- ### Basic Logixlysia Configuration Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/configuration.mdx Configure Logixlysia with a preset or custom options. Presets like 'dev' or 'prod' offer default settings. ```typescript logixlysia({ preset: 'prod', // optional: 'dev' | 'prod' | 'json' config: { // ... configuration options (override preset) } }) ``` -------------------------------- ### Enable Pino Pretty Printing Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/pino.mdx Enable pretty printing for Pino logs by setting 'prettyPrint' to true in the Logixlysia configuration. ```typescript logixlysia({ config: { pino: { prettyPrint: true } } }) ``` -------------------------------- ### Context Accumulation: evlog log.set vs Logixlysia store.logger.mergeContext Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/migration-from-evlog.mdx Demonstrates how to set context in evlog using `log.set` and in Logixlysia using `store.logger.mergeContext`. Logixlysia also provides direct access to `store.logger` in handlers. ```typescript log.set({ userId: 'x' }) ``` ```typescript store.logger.mergeContext(request, { userId: 'x' }) ``` ```typescript log.set({ cart: { total: 99 } }) ``` ```typescript store.logger.mergeContext(request, { cart: { total: 99 } }) ``` ```typescript useLogger() ``` ```typescript store.logger ``` -------------------------------- ### Configure Pino Logger Options Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/configuration.mdx Provide a configuration object to customize the underlying Pino logger. This includes setting the log level, enabling pretty printing, defining fields to redact, and adding base fields. ```typescript pino: { level: 'info', prettyPrint: true, redact: ['password', 'token'], base: { service: 'my-api', version: '1.0.0' } } ``` -------------------------------- ### Run Tests in Watch Mode Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/contributing.mdx Run the project's test suite in watch mode using Bun. This will automatically re-run tests when files change. ```bash bun test --watch ``` -------------------------------- ### Creating Child Loggers in Elysia Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/examples.mdx Demonstrates how to create child loggers using Pino's `child` method within an Elysia route. Child loggers inherit context, making it easier to trace logs related to specific entities like orders. ```typescript app.get('/api/orders/:id', ({ store, params }) => { const { pino } = store // Create scoped logger const orderLogger = pino.child({ orderId: params.id, module: 'order-service' }) orderLogger.debug('Fetching order details') orderLogger.info({ status: 'processing' }, 'Order retrieved') return getOrder(params.id) }) ``` -------------------------------- ### Configure Pino File Transport Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/pino.mdx Set up a Pino transport to write logs to a specific file. ```typescript logixlysia({ config: { pino: { transport: { target: 'pino/file', options: { destination: './logs/pino-example.log' } } } } }) ``` -------------------------------- ### Full Production Logixlysia Configuration Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/examples.mdx Sets up Logixlysia for a production environment, disabling startup messages, enabling file logging with rotation, filtering logs, and configuring Pino with redaction and base information. It also includes options for external transports. ```typescript import { Elysia } from 'elysia' import logixlysia from 'logixlysia' const app = new Elysia() .use( logixlysia({ config: { // Disable startup message in production showStartupMessage: false, // File logging with rotation logFilePath: './logs/production.log', logRotation: { maxSize: '100m', interval: '1d', maxFiles: '30d', compress: true }, // Filter to important logs only logFilter: { level: ['ERROR', 'WARNING'] }, // Pino configuration pino: { level: 'info', redact: ['password', 'token', 'apiKey', 'creditCard'], base: { service: 'my-api', version: process.env.APP_VERSION, environment: 'production' } }, // Use transports for external services useTransportsOnly: false, transports: [ elasticsearchTransport, slackTransport ] } }) ) .listen(3000) ``` -------------------------------- ### Configure Pretty Printing Options Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/configuration.mdx Customize the appearance of pretty-printed logs using options like colorization, timestamp translation, and ignoring specific fields. ```typescript pino: { prettyPrint: { colorize: true, translateTime: 'HH:MM:ss Z', ignore: 'pid,hostname' } } ``` -------------------------------- ### Specify Log File Path Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/configuration.mdx Configure the path where log files will be stored. Ensure the directory exists and is writable. ```typescript logFilePath: './logs/app.log' ``` -------------------------------- ### Wrap WebSocket Routes with Lifecycle Logs Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/websocket.mdx Use `wrapWs` on the plugin instance to add lifecycle logs for WebSocket routes. Each event logs with HTTP method `WS`, the route path, duration, and optional `wsId` in context. ```typescript import { Elysia } from 'elysia' import logixlysia from 'logixlysia' const plugin = logixlysia({ config: { service: 'chat' } }) const app = new Elysia() .use(plugin) .ws( '/chat', plugin.wrapWs({ open(ws) { ws.send('connected') }, message(ws, message) { ws.send(message) }, close(ws) { console.log('bye', ws.id) } }) ) ``` -------------------------------- ### Branded Log Format with Icon and Service Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/formatting.mdx Configure a branded log format that includes the Logixlysia fox icon and a service name. The icon styling adapts to terminal colors and log levels. This format also includes speed indicators for slow requests. ```typescript logixlysia({ config: { service: 'my-api', customLogFormat: '{now} {service}{icon} {method} {pathname} {status} {duration} {message}{speed}' } }) ``` -------------------------------- ### Custom Logging in Elysia Route Handlers Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/api-reference.mdx Shows how to use the `logger` from the `store` to log custom messages at different levels (e.g., `debug`, `info`) within an Elysia route handler during user creation. ```typescript app.post('/users', ({ store, body, request }) => { const { logger } = store logger.debug(request, 'Creating user', { email: body.email }) // ... create user logic logger.info(request, 'User created', { userId: newUser.id }) return newUser }) ``` -------------------------------- ### Clone Logixlysia Repository Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/contributing.mdx Clone the Logixlysia repository to your local machine and navigate into the project directory. ```bash git clone https://github.com/PunGrumpy/logixlysia.git cd logixlysia ``` -------------------------------- ### Add Base Fields to All Logs Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/configuration.mdx Include common fields like service name, version, or environment variables in every log entry. ```typescript pino: { base: { service: 'my-api', version: '1.0.0', environment: process.env.NODE_ENV } } ``` -------------------------------- ### Specify Compression Algorithm Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/configuration.mdx Set the compression algorithm to use for rotated logs. Currently, only 'gzip' is supported. ```typescript compression: 'gzip' ``` -------------------------------- ### Add Base Fields to Pino Logs Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/pino.mdx Include common fields like service name, version, and environment to all Pino log entries. ```typescript logixlysia({ config: { pino: { base: { service: 'my-api', version: '1.0.0', environment: process.env.NODE_ENV } } } }) ``` -------------------------------- ### Configure Pino Log Levels Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/log-levels.mdx When integrating with Pino, configure Pino's specific log levels using the 'level' option within the 'pino' configuration. ```typescript logixlysia({ config: { pino: { level: 'debug' // 'fatal', 'error', 'warn', 'info', 'debug', 'trace' } } }) ``` -------------------------------- ### Configure Log Filtering Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/filtering.mdx Set up log filtering by specifying levels, statuses, and methods in the configuration. ```typescript logixlysia({ config: { logFilter: { level: ['ERROR', 'WARNING'], status: [500, 404], method: 'GET' } } }) ``` -------------------------------- ### Integrate Standalone Logger with Elysia App Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/pino.mdx Set up an Elysia application and use the standalone logger instance within its services. ```typescript // index.ts import { Elysia } from 'elysia' import { logixlysiaIns } from './logger' import { OrderService } from './services/order.service' const orderService = new OrderService() new Elysia() .use(logixlysiaIns) .post('/orders/:id/process', async ({ params }) => { await orderService.processOrder(params.id) return { success: true } }) .listen(3000) ``` -------------------------------- ### Configure Pino Options Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/usage.mdx Pass custom options to the Pino logger instance used by Logixlysia. This allows for fine-tuning Pino's behavior, such as setting log levels, enabling pretty printing, defining redaction rules, and setting base properties. ```typescript logixlysia({ config: { pino: { level: 'debug', prettyPrint: true, redact: ['password', 'token'], base: { service: 'my-api' } } } }) ``` -------------------------------- ### Access Pino Instance for Logging Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/usage.mdx Access the underlying Pino instance via `store.pino` to use Pino's logging methods directly within your Elysia routes. This allows for more granular logging control and custom log messages. ```typescript app.get('/users/:id', ({ store, params }) => { const { pino } = store pino.info({ userId: params.id, action: 'view_profile' }, 'User profile accessed') return { user: 'data' } }) ``` -------------------------------- ### Configure Multiple Log Levels Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/log-levels.mdx Specify an array of log levels to include. This allows logging specific levels while excluding others in between. ```typescript logixlysia({ config: { logFilter: { level: ['INFO', 'ERROR'] } } }) ``` -------------------------------- ### File Logging Configuration Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/usage.mdx Configure Logixlysia to save logs to a file and set up log rotation based on size, interval, and file count. Compression can also be enabled for rotated files. ```typescript logixlysia({ config: { logFilePath: './logs/app.log', logRotation: { maxSize: '10m', interval: '1d', maxFiles: '7d', compress: true } } }) ``` -------------------------------- ### Basic Elysia App with Logixlysia Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/introduction.mdx Integrate Logixlysia into a basic Elysia application. Ensure you have imported Elysia and logixlysia. ```typescript import { Elysia } from 'elysia' import logixlysia from 'logixlysia' const app = new Elysia() .use(logixlysia()) .get('/', () => 'Hello World') .listen(3000) ``` -------------------------------- ### Basic Request Context Accumulation Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/request-context.mdx Use `store.logger.mergeContext` to add fields to the request's context. These fields will be included in the access log. Ensure Logixlysia is initialized with `.use(logixlysia())`. ```typescript import { Elysia } from 'elysia' import logixlysia from 'logixlysia' const app = new Elysia() .use(logixlysia()) .get('/checkout', ({ request, store }) => { store.logger.mergeContext(request, { userId: 'usr_123' }) store.logger.mergeContext(request, { cartTotal: 9999 }) return { ok: true } }) ``` -------------------------------- ### Best Practice: Export Pino for Standalone Use Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/pino.mdx Export the Pino logger instance for use in services, jobs, and utilities outside the main application context. ```typescript // logger.ts export const logger = logixlysiaIns.store.pino // services/user.service.ts import { logger } from '../logger' logger.info({ userId }, 'User updated') ``` -------------------------------- ### Logixlysia Options Type Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/api-reference.mdx Defines the structure for configuration options when initializing the Logixlysia plugin. This includes settings for startup messages, colors, IP logging, redaction, timestamps, custom formats, services, slow request thresholds, context tree display, query parameter logging, transports, and Pino logger options. ```typescript type Options = { config?: { showStartupMessage?: boolean startupMessageFormat?: 'simple' | 'banner' useColors?: boolean ip?: boolean autoRedact?: boolean timestamp?: { translateTime?: string } customLogFormat?: string service?: string slowThreshold?: number verySlowThreshold?: number showContextTree?: boolean contextDepth?: number logQueryParams?: boolean transports?: Transport[] useTransportsOnly?: boolean disableInternalLogger?: boolean disableFileLogging?: boolean logFilePath?: string logRotation?: LogRotationConfig pino?: PinoLoggerOptions & { prettyPrint?: boolean | object } } } ``` -------------------------------- ### Configure Log Rotation Settings for Logixlysia Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/faq.mdx Define parameters for automatic log file rotation, including maximum file size, rotation interval, log retention period, and compression. ```typescript logRotation: { maxSize: '10m', interval: '1d', maxFiles: '7d', compress: true } ``` -------------------------------- ### Log Compression Configuration Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/log-rotation.mdx Enable or disable compression (gzip) for rotated log files. ```typescript logRotation: { compress: true // Enable compression (gzip) } ``` -------------------------------- ### Test IP Logging Locally Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/faq.mdx Use this curl command to test IP logging by simulating the `x-real-ip` header when testing locally without a proxy. ```bash curl -H 'x-real-ip: 1.2.3.4' http://localhost:3000/ ``` -------------------------------- ### Logixlysia Configuration for Elysia Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/elysia/README.md Configuration object for Logixlysia, enabling 'dev' preset and setting service name, log file path, IP logging, and auto-redaction. ```typescript logixlysia({ preset: 'dev', config: { service: 'elysia-demo', logFilePath: './logs/example.log', ip: true, autoRedact: true } }) ``` -------------------------------- ### Basic Elysia App with Logixlysia Source: https://github.com/pungrumpy/logixlysia/blob/main/README.md Integrate Logixlysia into an ElysiaJS application by importing and using the plugin. Configure logging options such as service name, startup messages, context tree display, and timestamp format. ```typescript import { Elysia } from 'elysia' import logixlysia from 'logixlysia' // or import { logixlysia } from 'logixlysia' const app = new Elysia({ name: "Elysia with Logixlysia" }) .use( logixlysia({ config: { service: 'api-server', showStartupMessage: true, startupMessageFormat: 'banner', showContextTree: true, contextDepth: 2, slowThreshold: 500, verySlowThreshold: 1000, timestamp: { translateTime: 'yyyy-mm-dd HH:MM:ss.SSS' }, ip: true } })) .get('/', () => { return { message: 'Welcome to Basic Elysia with Logixlysia' } }) app.listen(3000) ``` -------------------------------- ### Context Tree Configuration Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/formatting.mdx Enables the display of context data as a tree structure under the main log line. This configuration also sets the maximum depth for flattening nested objects into dotted keys. ```typescript logixlysia({ config: { showContextTree: true, contextDepth: 2 } }) ``` -------------------------------- ### Structured Logging with Context in Elysia Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/examples.mdx Shows how to use the logger and Pino directly within an Elysia route handler to add custom context to log messages. This is useful for tracking specific requests or user actions. ```typescript app.get('/users/:id', ({ store, params, request }) => { const { logger, pino } = store // Using logger helper logger.info(request, 'User profile accessed', { userId: params.id, timestamp: Date.now() }) // Or using Pino directly pino.info({ userId: params.id, action: 'view_profile', timestamp: Date.now() }, 'User profile accessed') return getUserById(params.id) }) ``` -------------------------------- ### Accessing Logger in Elysia Route Handlers Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/api-reference.mdx Demonstrates how to access the `logger` and `pino` instances from the `store` within an Elysia route handler to log information about the request. ```typescript app.get('/users/:id', ({ store, params, request }) => { const { logger, pino } = store // Use logger helper methods logger.info(request, 'User accessed', { userId: params.id }) // Or use Pino directly pino.info({ userId: params.id }, 'User accessed') return { user: 'data' } }) ``` -------------------------------- ### Configure Logixlysia for Development and Production Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/faq.mdx Dynamically adjust Logixlysia's configuration based on the environment variable `NODE_ENV`. Enables debug logging and pretty printing in development. ```typescript const isDev = process.env.NODE_ENV === 'development' logixlysia({ config: { showStartupMessage: isDev, pino: { level: isDev ? 'debug' : 'info', prettyPrint: isDev } } }) ``` -------------------------------- ### Custom Log Format Configuration Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/usage.mdx Customize the log message format using placeholders. This allows you to define the exact information and order of details in your log output. ```typescript logixlysia({ config: { customLogFormat: '{now} {level} {duration}ms {method} {pathname}{query} {status}' } }) ``` -------------------------------- ### Configure Environment-Based Log Levels Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/log-levels.mdx Dynamically set log levels based on the environment variable NODE_ENV. This is useful for different logging needs in development versus production. ```typescript logixlysia({ config: { logFilter: { level: process.env.NODE_ENV === 'production' ? ['ERROR', 'WARNING'] : ['DEBUG', 'INFO', 'WARNING', 'ERROR'] } } }) ``` -------------------------------- ### Minimal Custom Log Format String Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/features/formatting.mdx Defines a minimal custom log format string for logging only the HTTP method, request path, and response status code. ```typescript customLogFormat: '{method} {pathname} {status}' ``` -------------------------------- ### Log Query Parameters Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/configuration.mdx Include query parameters in the logged URL path. Defaults to false. ```typescript logQueryParams: true ``` -------------------------------- ### Configure Logixlysia for File Logging Only Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/faq.mdx Set up Logixlysia to log exclusively to a file, disabling the console output. Specify the desired log file path. ```typescript logixlysia({ config: { disableInternalLogger: true, logFilePath: './logs/app.log' } }) ``` -------------------------------- ### Enable Colored Console Output Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/configuration.mdx Enable colored output in console logs. Defaults to true. ```typescript useColors: true ``` -------------------------------- ### Enable Pretty Printing for Development Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/(docs)/configuration.mdx Enable pretty printing to make log output more readable in development environments. Can be a boolean or an object with specific formatting options. ```typescript pino: { prettyPrint: true } ``` -------------------------------- ### Merge AI Metrics into Request Logs Source: https://github.com/pungrumpy/logixlysia/blob/main/apps/docs/content/integrations/ai.mdx Import `logixlysia/ai` and use `mergeAIMetrics` after your AI SDK call to log model details, input/output tokens, and processing time. The logged context mirrors evlog's `ai` field. ```typescript import logixlysia from 'logixlysia' import { mergeAIMetrics } from 'logixlysia/ai' const plugin = logixlysia() const app = new Elysia() .use(plugin) .post('/chat', async ({ request, store }) => { // After your AI SDK call: mergeAIMetrics(store.logger, request, { model: 'claude-sonnet', provider: 'anthropic', inputTokens: 1200, outputTokens: 400, totalTokens: 1600, msToFinish: 2300 }) return { ok: true } }) ```