/

Disable Logging Configuration

There are several ways to disable or reduce logging in ByteHide Logger, from complete shutdown to selective filtering. Choose the method that best fits your needs.

Complete Logging Disable

Use the built-in disable method to stop all logging:

Java
// Initialize logger normally
Log.setProjectToken("your-token");
Log.setConsoleEnabled(true);

// Disable logging completely
Log.disable();

// All logging calls will be ignored
Log.info("This will not be logged");
Log.error("This will also be ignored");

// Re-enable logging when needed
Log.enable();
Log.info("This will be logged again");

Method 2: Set Minimum Level to Highest

Java
Log.setMinimumLevel(LogLevel.CRITICAL);  // Only critical messages

// These will be ignored
Log.info("Ignored");
Log.warn("Ignored");
Log.error("Ignored");

// Only this will be logged
Log.critical("This will be logged");

Conditional Disabling

Environment-Based Disabling

Java
String environment = System.getenv("APP_ENVIRONMENT");
boolean isHighTraffic = "true".equals(System.getenv("HIGH_TRAFFIC_MODE"));

if (isHighTraffic) {
    Log.disable();
} else {
    Log.setMinimumLevel(LogLevel.WARN);
}

Feature Flag Disabling

Java
public class LoggerConfig {
    public static void initializeWithFeatureFlag(boolean loggingEnabled) {
        Log.setProjectToken(System.getenv("BYTEHIDE_LOGS_TOKEN"));
        Log.setMinimumLevel(LogLevel.INFO);
        
        if (!loggingEnabled) {
            Log.disable();
        }
    }
}

Selective Disabling

Disable Console Only

Java
Log.setConsoleEnabled(false);    // Disable console output
Log.setPersist(true);            // Keep file logging
Log.setFilePath("logs/app.log");

Disable File Logging Only

Java
Log.setPersist(false);           // Disable file logging
Log.setConsoleEnabled(true);     // Keep console output

Disable Cloud Logging Only

Java
// Configure local logging
Log.setPersist(true);
Log.setConsoleEnabled(true);

// Don't set project token - logs stay local only
// Log.setProjectToken("token"); // Not called

Performance-Based Disabling

High-Traffic Configuration

Java
Log.setMinimumLevel(LogLevel.ERROR);
Log.setConsoleEnabled(false);
Log.setDuplicateSuppressionWindow(300000L);  // 5 minutes

Minimal Logging Configuration

Java
Log.setMinimumLevel(LogLevel.CRITICAL);
Log.setConsoleEnabled(false);
Log.setPersist(true);
Log.setFilePath("logs/critical-only.log");

Runtime Disabling

Using Built-in Enable/Disable Methods

Java
public class RuntimeLogControl {
    public static void disableAllLogging() {
        Log.disable();
    }
    
    public static void enableLogging() {
        Log.enable();
    }
    
    public static void toggleLogging(boolean enabled) {
        if (enabled) {
            Log.enable();
        } else {
            Log.disable();
        }
    }
}

Graceful Shutdown

Always flush and shut down the logger when your application exits:

Java
// Flush pending logs
Log.flush();

// Shutdown the logger
Log.shutdown();

Shutdown Hook

Java
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
    Log.info("Application shutting down");
    Log.flush();
    Log.shutdown();
}));

Environment Variable Control

Complete Disable via Environment

Bash
BYTEHIDE_LOGGING_DISABLED=true
Java
public static void initializeWithEnvironmentControl() {
    String loggingDisabled = System.getenv("BYTEHIDE_LOGGING_DISABLED");
    
    if ("true".equalsIgnoreCase(loggingDisabled)) {
        Log.disable();
        return;
    }
    
    Log.setMinimumLevel(LogLevel.INFO);
    Log.setProjectToken(System.getenv("BYTEHIDE_LOGS_TOKEN"));
}

Best Practices

Disabling Logging Best Practices

  • Use environment variables for flexible logging control
  • Always call flush() and shutdown() before application exit
  • Keep critical error logging even in high-performance scenarios
  • Test logging disable/enable in your deployment pipeline
  • Document logging configuration for your operations team
Previous
Environment Variables