---
title: FAQ
description: Frequently asked questions about Elogs
---

## General

### What is Elogs?

Elogs is a high-performance logging plugin for [Elysia.js](https://elysiajs.com/) that provides structured logging powered by [Pino](https://github.com/pinojs/pino). It offers flexible configuration, file logging, and seamless integration with Elysia applications.

### Why use Elogs instead of plain Pino?

Elogs provides:
- Automatic request/response logging
- Elysia plugin integration
- Built-in file logging with rotation
- Custom transport support
- Simple configuration API
- TypeScript support

### Is Elogs production-ready?

Yes, Elogs is built for production environments. It's powered by Pino, which is battle-tested in production, and includes features like log rotation, filtering, and transport support.

## Installation

### How do I install Elogs?

```bash
bun add @eastgold15/elogs
```

Or with npm:

```bash
npm install @eastgold15/elogs
```

### What are the requirements?

- Node.js 18+ or Bun
- Elysia 2.0.0 or newer
- TypeScript 5.7+

## Configuration

### How do I disable console logging?

```ts
createElogs({
  config: {
    disableInternalLogger: true
  }
})
```

### How do I use only file logging?

```ts
createElogs({
  config: {
    disableInternalLogger: true,
    logFilePath: './logs/app.log'
  }
})
```

### How do I use only transports?

```ts
createElogs({
  config: {
    useTransportsOnly: true,
    transports: [myTransport]
  }
})
```

### How do I configure different settings for development and production?

```ts
const isDev = process.env.NODE_ENV === 'development'

createElogs({
  config: {
    showStartupMessage: isDev,
    pino: {
      level: isDev ? 'debug' : 'info',
      prettyPrint: isDev
    }
  }
})
```

## Usage

### How do I access the logger in route handlers?

```ts
app.get('/users/:id', ({ store, request }) => {
  const { logger, pino } = store

  // Use logger helper
  logger.info(request, 'User accessed')

  // Or use Pino directly
  pino.info('User accessed')

  return { user: 'data' }
})
```

### How do I log custom messages?

```ts
app.post('/users', ({ store, body, request }) => {
  const { logger } = store

  logger.info(request, 'Creating user', {
    email: body.email
  })

  return createUser(body)
})
```

### How do I create child loggers?

```ts
app.get('/orders/:id', ({ store, params }) => {
  const { pino } = store

  const orderLogger = pino.child({
    orderId: params.id,
    module: 'order-service'
  })

  orderLogger.info('Processing order')

  return getOrder(params.id)
})
```

### How do I use the logger outside of Elysia routes (in services, background jobs, etc.)?

**Use `store.pino` directly** for logging outside of HTTP request context:

```ts
// logger.ts
import { createElogs } from '@eastgold15/elogs'

export const elogsIns = createElogs({
  config: {
    logFilePath: './logs/app.log',
    pino: {
      level: 'info',
      base: { service: 'my-api' }
    }
  }
})

// Export Pino for standalone use
export const logger = elogsIns.store.pino

// services/user.service.ts
import { logger } from '../logger'

export class UserService {
  async createUser(data: any) {
    logger.info({ userId: data.id }, 'Creating user')
    // ... business logic
    logger.info({ userId: data.id }, 'User created successfully')
  }
}
```

**Why can't I use `store.logger` outside routes?**

`store.logger` methods (`.info()`, `.debug()`, `.warn()`, `.error()`) require a `Request` object because they're designed specifically for HTTP request logging with context like method, pathname, IP, and duration. For general-purpose logging, use `store.pino` instead.

## File Logging

### How do I enable file logging?

```ts
createElogs({
  config: {
    logFilePath: './logs/app.log'
  }
})
```

### How does log rotation work?

Log rotation automatically manages log file sizes and retention:

```ts
logRotation: {
  maxSize: '10m',    // Rotate when file reaches 10MB
  interval: '1d',    // Also rotate daily
  maxFiles: '7d',   // Keep logs for 7 days
  compress: true     // Compress rotated logs
}
```

### Can I use multiple log files?

Currently, Elogs supports a single log file path. For multiple files, use custom transports.

## Transports

### How do I create a custom transport?

```ts
const myTransport = {
  log: async (level, message, meta) => {
    // Your logging logic here
    await sendToService(level, message, meta)
  }
}

createElogs({
  config: {
    transports: [myTransport]
  }
})
```

### Can I use multiple transports?

Yes, you can use multiple transports:

```ts
createElogs({
  config: {
    transports: [
      elasticsearchTransport,
      slackTransport,
      mongodbTransport
    ]
  }
})
```

## Performance

### What is the performance impact?

Elogs is built on Pino, one of the fastest Node.js loggers. The performance impact is minimal, especially when using async transports.

### Should I use file logging in production?

File logging is recommended for production environments. Use log rotation to manage disk space and consider compression for space savings.

### How do I reduce logging overhead?

- Use log filtering to log only important events
- Use appropriate log levels
- Consider using transports for high-volume scenarios
- Disable pretty printing in production

## Troubleshooting

### IP logging shows empty or IP is not appearing

The `{ip}` placeholder reads from `x-forwarded-for` (first IP in the list) or `x-real-ip` headers. These are set by reverse proxies and load balancers. When testing on localhost or over a LAN without a proxy, these headers are not set, so the IP field will be empty.

**To test IP logging locally:**
```bash
curl -H 'x-real-ip: 1.2.3.4' http://localhost:3000/
```

In production behind nginx, Caddy, Cloudflare, or similar, the proxy typically sets these headers and IP logging works as expected.

### Logs are not appearing

Check:
1. Log level configuration
2. Log filter settings
3. Output control settings (`disableInternalLogger`, `disableFileLogging`)
4. File permissions for file logging

### File rotation is not working

Ensure:
1. `logFilePath` is set
2. File has write permissions
3. `maxSize` or `interval` is configured
4. Check console for rotation errors

### Pino pretty printing not working

Make sure:
1. `pino.prettyPrint` is set to `true`
2. You're in development mode (pretty printing is typically disabled in production)
3. You have `pino-pretty` installed if using transport-based pretty printing

### Transports are not receiving logs

Check:
1. Transport is properly configured
2. Transport `log` method is not throwing errors
3. `useTransportsOnly` is not conflicting with other settings
4. Check console for transport errors

### customLogFormat is not working for error logs

Ensure you're using Elogs v6.0.2 or later. Earlier versions had a bug where error logs ignored the `customLogFormat` configuration and used a hardcoded format instead. This has been fixed in version 6.0.2+.

**Before (v6.0.1 and earlier):**
```
ERROR POST /api/users Validation failed
```

**After (v6.0.2+ with customLogFormat):**
```json
{"level": "ERROR", "message": "Validation failed", "method": "POST", "pathname": "/api/users", "status": "400"}
```

## Migration

### How do I migrate from another logging library?

1. Install Elogs
2. Replace your logging setup with `createElogs()`
3. Update log calls to use `store.logger` or `store.pino`
4. Configure transports if needed

### Is Elogs backward compatible?

Elogs maintains backward compatibility within major versions. Check the changelog for breaking changes between versions.

## Support

### Where can I get help?

- [Documentation](/)
- [GitHub Issues](https://github.com/eastgold15/elogs/issues)

### How do I report a bug?

Open an issue on [GitHub](https://github.com/eastgold15/elogs/issues) with:
- Description of the issue
- Steps to reproduce
- Expected behavior
- Actual behavior
- Environment details
