logixlysia icon indicating copy to clipboard operation
logixlysia copied to clipboard

Feature Request: Integrate Pino Logger for logixlysia

Open NewtTheWolf opened this issue 5 months ago • 0 comments

Title

Implement Pino as Primary Logger

Priority

Medium 🚧

Description

I propose enhancing the logixlysia plugin by replacing the current logging implementation with Pino - a high-performance, industry-standard logging library. This would provide better performance, more extensive logging capabilities.

Background

Pino is one of the fastest logging libraries available for Node.js with extremely low overhead. It's designed to be JSON-first, which makes it ideal for structured logging and analysis in production environments. Many developers are already familiar with Pino from other frameworks like Fastify.

Implementation Details

Core Changes

  1. Replace the current logging implementation with Pino as the primary logger
  2. Expose the Pino logger instance through the context object in route handlers
  3. Provide configuration options for customizing the Pino instance

Usage Examples

import { Elysia } from 'elysia'
import { logixlysia } from 'logixlysia'

// Basic usage with Pino defaults
const app = new Elysia()
  .use(logixlysia())
  .get('/users', ({ logger }) => {
    logger.info('Fetching users list')
    const users = fetchUsers()
    logger.debug({ count: users.length }, 'Users fetched successfully')
    return users
  })

// With custom Pino configuration
const app = new Elysia()
  .use(logixlysia({
    level: 'debug',
    transport: {
      target: 'pino-pretty',
      options: { colorize: true }
    },
    // Optional: pass a pre-configured Pino instance
    instance: myCustomPinoInstance
  }))

Benefits

  1. Performance: Pino is recognized as one of the fastest logging libraries in the Node.js ecosystem
  2. Ecosystem: Access to Pino's rich ecosystem of tools and transports
  3. Structured Logging: Native JSON logging for better integration with monitoring tools
  4. Flexibility: Direct access to the logger in route handlers for custom logging scenarios
  5. Developer Experience: Familiar API for developers coming from other Pino-powered frameworks

Alternative Implementation

As an alternative to replacing the current logger entirely, I propose adding Pino as an optional transport that developers can choose. This would allow those who prefer the current implementation to keep using it while still providing the option to use Pino when desired:

import { Elysia } from 'elysia'
import { logixlysia } from 'logixlysia'

// Use the default logger
const app = new Elysia().use(logixlysia())

// Or use Pino as the transport
const app = new Elysia().use(logixlysia({
  transport: 'pino',
  pinoOptions: {
    level: 'debug',
    transport: {
      target: 'pino-pretty'
    }
  }
}))

This approach would:

  • Maintain backward compatibility for existing users
  • Provide flexibility for different logging preferences
  • Allow gradual adoption of Pino in existing projects

Additional Resources

NewtTheWolf avatar May 05 '25 00:05 NewtTheWolf