/

Log Levels Configuration

Log levels control which messages are processed and logged. Set the minimum level to filter out less important messages and optimize performance.

Available Log Levels

ByteHide Logger supports six log levels in order of severity:

LevelSeverityUse Case
LogLevel.TRACELowMost detailed diagnostic information
LogLevel.DEBUGLowDetailed diagnostic information
LogLevel.INFOMediumGeneral information messages
LogLevel.WARNHighWarning messages for potential issues
LogLevel.ERRORCriticalError messages for failures
LogLevel.CRITICALCriticalCritical errors that may cause termination

Setting Minimum Log Level

Configure the minimum level:

Java
import com.bytehide.logs.models.LogLevel;

Log.setMinimumLevel(LogLevel.INFO);  // Default: LogLevel.WARN

Level Filtering Behavior

When you set a minimum level, only messages at that level or higher are processed:

Java
// Set minimum level to Info
Log.setMinimumLevel(LogLevel.INFO);

Log.trace("This will be ignored");    // ❌ Below minimum
Log.debug("This will be ignored");    // ❌ Below minimum
Log.info("This will be logged");      // ✅ At minimum level
Log.warn("This will be logged");      // ✅ Above minimum
Log.error("This will be logged");     // ✅ Above minimum
Log.critical("This will be logged");  // ✅ Above minimum

Environment-Specific Configuration

Development Environment

Java
Log.setMinimumLevel(LogLevel.DEBUG);  // Verbose logging for debugging

Production Environment

Java
Log.setMinimumLevel(LogLevel.WARN);   // Only warnings and errors

Dynamic Configuration

Java
String environment = System.getenv("APP_ENVIRONMENT");
boolean isDevelopment = "development".equalsIgnoreCase(environment);

Log.setMinimumLevel(isDevelopment ? LogLevel.DEBUG : LogLevel.ERROR);

Usage Examples

Trace Level

Java
Log.trace("Entering method processOrder with orderId: " + orderId);

Debug Level

Java
Log.debug("Database query executed in " + elapsed + "ms");

Info Level

Java
Log.info("User " + userId + " logged in successfully");

Warn Level

Java
Log.warn("API rate limit approaching: " + current + "/" + max);

Error Level

Java
Log.error("Failed to process payment for order " + orderId);

Critical Level

Java
Log.critical("Database connection lost. Application shutting down.");

Performance Impact

LevelPerformanceUse Case
Trace/DebugHighest overheadDevelopment only
InfoModerate overheadDevelopment/staging
WarnLow overheadProduction (recommended)
Error/CriticalMinimal overheadHigh-performance production

Best Practices

Level Selection Guidelines

  • Development: Use DEBUG or INFO for detailed diagnostics
  • Staging: Use INFO or WARN for testing scenarios
  • Production: Use WARN or ERROR for optimal performance
  • High-traffic: Use ERROR or CRITICAL for minimal overhead
Previous
Project Token