/

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:

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

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

Environment-Based Configuration

Development Environment

JavaScript
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

JavaScript
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

JavaScript
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:

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

Debug Level

For development diagnostics:

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

Info Level

For general application flow:

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

Warning Level

For potential issues:

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

Error Level

For runtime errors:

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

Critical Level

For critical system failures:

JavaScript
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