/

Bun

ByteHide Logger works seamlessly with Bun's fast JavaScript runtime, providing excellent performance for logging operations.

Installation

bun add @bytehide/logger

Basic Setup

import { Log } from '@bytehide/logger';

// Configure logger
Log.configure({
    projectToken: 'your-project-token',
    logLevel: 'info',
    consoleOutput: true
});

// Start logging
Log.info('Bun application started');

TypeScript Support

import { Log } from '@bytehide/logger';

Log.configure({
    projectToken: process.env.BYTEHIDE_PROJECT_TOKEN!,
    logLevel: 'info'
});

Log.info('TypeScript with Bun works great');

Environment Variables

// Using Bun's built-in environment support
Log.configure({
    projectToken: process.env.BYTEHIDE_PROJECT_TOKEN,
    logLevel: process.env.LOG_LEVEL || 'info'
});

File Logging

Log.configure({
    projectToken: 'your-project-token',
    fileOutput: {
        enabled: true,
        path: './logs'
    }
});

Bun Server Integration

import { Log } from '@bytehide/logger';

const server = Bun.serve({
    port: 3000,
    fetch(req) {
        Log.info('Request received', {
            context: { 
                method: req.method, 
                url: req.url 
            }
        });

        return new Response('Hello from Bun!');
    },
});

Log.info(`Server running on port ${server.port}`);

Performance

Bun's fast runtime provides excellent logging performance:

// High-frequency logging performs well with Bun
for (let i = 0; i < 1000; i++) {
    Log.debug('Processing item', {
        context: { itemId: i }
    });
}

Best Practices

Bun Best Practices

  • Leverage Bun's fast startup time for logging initialization
  • Use TypeScript for better development experience
  • Take advantage of Bun's built-in environment variable support
  • Utilize Bun's performance for high-frequency logging scenarios
Previous
Deno