/

Log Levels Configuration

Log levels determine which messages are recorded based on their importance. ByteHide for JavaScript supports standard logging levels with flexible configuration.

Available Log Levels

LevelPriorityDescriptionUse Case
trace0Detailed execution flowDevelopment debugging
debug1Diagnostic informationDevelopment troubleshooting
info2General informationApplication flow
warn3Warning conditionsPotential issues
error4Error conditionsRuntime errors
critical5Critical failuresSystem crashes

Setting Minimum Log Level

Configure the minimum log level using the minimumLevel option:

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

Log.configure({
    minimumLevel: 'info' // Only info, warn, error, and critical messages will be logged
});

Environment-Based Configuration

Development Environment

Log.configure({
    minimumLevel: 'debug',
    consoleEnabled: true
});

Log.trace('Detailed execution step');
Log.debug('Variable value', { metadata: { userId: 123 } });
Log.info('User logged in', { tags: ['auth'] });

Production Environment

Log.configure({
    minimumLevel: 'warn',
    consoleEnabled: false,
    persist: true
});

Log.warn('API rate limit approaching');
Log.error('Database connection failed');
Log.critical('Application crashed');

Using Environment Variables

const logLevel = process.env.LOG_LEVEL || 'info';

Log.configure({
    minimumLevel: logLevel,
    consoleEnabled: process.env.NODE_ENV === 'development'
});

Level-Specific Logging

Trace Level

For detailed debugging information:

Log.trace('Function entry', { 
    metadata: { 
        function: 'processPayment',
        args: { amount: 100, currency: 'USD' } 
    } 
});

Debug Level

For development diagnostics:

Log.debug('API response received', {
    metadata: {
        statusCode: 200,
        responseTime: 150,
        endpoint: '/api/users'
    }
});

Info Level

For general application flow:

Log.info('User action completed', {
    metadata: {
        action: 'purchase',
        userId: 'user123'
    }
});

Warning Level

For potential issues:

Log.warn('Deprecated API used', {
    metadata: {
        api: '/api/v1/users',
        suggestedAlternative: '/api/v2/users'
    }
});

Error Level

For runtime errors:

try {
    await processPayment(paymentData);
} catch (error) {
    Log.error('Payment processing failed', {
        metadata: {
            paymentId: paymentData.id
        }
    }, error);
}

Critical Level

For critical system failures:

process.on('uncaughtException', (error) => {
    Log.critical('Uncaught exception', {}, error);
    process.exit(1);
});

Best Practices

Level Selection Guidelines

  • Development: Use debug or trace for detailed information
  • Staging: Use info to monitor application flow
  • Production: Use warn or error to minimize noise
  • Critical Systems: Use error or critical only
Previous
Project Token