/

Logger SDK Configuration

Configuration overview

ByteHide Logger for Java is configured through static methods on the Log class, providing a simple and flexible way to set up logging behavior, file management, security, and performance optimization.

Configuration Overview

The Java SDK uses static configuration methods on the Log class. Here's how to set up basic configuration:

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

// Set your project token
Log.setProjectToken("your-project-token");

// Configure logging behavior
Log.setConsoleEnabled(true);
Log.setMinimumLevel(LogLevel.INFO);

Project Token Configuration

By simply adding your project token, all logs will be automatically sent to the ByteHide cloud platform without any additional configuration. If you don't set a project token, logs will only be stored in local files. For more information about obtaining and configuring your project token, see Project Token setup.

Configuration Methods

MethodDescriptionDefault
setProjectToken(String)Set project token manuallynull
setProject()Load token from environment variable-
setConsoleEnabled(boolean)Enable/disable console outputfalse
setMinimumLevel(LogLevel)Minimum log level to processWARN
setPersist(boolean)Enable/disable file persistencefalse
setFilePath(String)Log file path"logs.txt"
setRollingInterval(RollingInterval)File rotation intervalDAY
addSensitiveKey(String)Add sensitive data key to mask-
setDuplicateSuppressionWindow(Long)Duplicate suppression window (ms)1000
setUser(AuthUser)Set authenticated usernull
setAnonymousId(String)Set anonymous user IDnull
addMetaContext(String, Object)Add global context metadata-

File Persistence Settings

Control how logs are saved to files:

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

// Enable file logging
Log.setPersist(true);
Log.setFilePath("logs/application.log");

// File rotation settings
Log.setRollingInterval(RollingInterval.DAY);

Available Rolling Intervals:

  • RollingInterval.MINUTE: Every minute
  • RollingInterval.HOUR: Every hour
  • RollingInterval.DAY: Daily (recommended)
  • RollingInterval.WEEK: Weekly
  • RollingInterval.MONTH: Monthly
  • RollingInterval.YEAR: Yearly

Console Output Settings

Configure console logging:

Java
Log.setConsoleEnabled(true);  // Default: false

Log Level Configuration

Set the minimum log level to process:

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

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

Available Log Levels (in order of severity):

  • LogLevel.TRACE: Most detailed diagnostic information
  • LogLevel.DEBUG: Detailed diagnostic information
  • LogLevel.INFO: General information messages
  • LogLevel.WARN: Warning messages for potential issues
  • LogLevel.ERROR: Error messages for failures
  • LogLevel.CRITICAL: Critical errors that may cause application termination

Security Settings

Configure data masking for sensitive information:

Java
// Add sensitive keys to mask in logs
Log.addSensitiveKey("password");
Log.addSensitiveKey("token");
Log.addSensitiveKey("apiKey");
Log.addSensitiveKey("creditCard");

Performance Settings

Configure duplicate suppression:

Java
// Suppress duplicate messages within time window (milliseconds)
Log.setDuplicateSuppressionWindow(5000L);  // 5 seconds

Configuration Examples

Development Environment

Java
Log.setProjectToken("your-dev-token");
Log.setConsoleEnabled(true);
Log.setMinimumLevel(LogLevel.DEBUG);

// File logging
Log.setPersist(true);
Log.setFilePath("logs/debug.log");
Log.setRollingInterval(RollingInterval.HOUR);

// Basic security
Log.addSensitiveKey("password");
Log.addSensitiveKey("token");

Production Environment

Java
Log.setProjectToken(System.getenv("BYTEHIDE_LOGS_TOKEN"));
Log.setConsoleEnabled(false);
Log.setMinimumLevel(LogLevel.WARN);

// Robust file logging
Log.setPersist(true);
Log.setFilePath("logs/production.log");
Log.setRollingInterval(RollingInterval.DAY);

// Enhanced security
Log.addSensitiveKey("password");
Log.addSensitiveKey("token");
Log.addSensitiveKey("secret");
Log.addSensitiveKey("apiKey");
Log.addSensitiveKey("creditCard");

// Performance optimization
Log.setDuplicateSuppressionWindow(10000L);  // 10 seconds

Complete Configuration Example

Java
import com.bytehide.logs.core.Log;
import com.bytehide.logs.models.LogLevel;
import com.bytehide.logs.models.RollingInterval;

public class LoggerConfig {
    public static void initialize() {
        // Project token
        Log.setProjectToken(System.getenv("BYTEHIDE_LOGS_TOKEN"));
        
        // Basic settings
        Log.setMinimumLevel(LogLevel.INFO);
        Log.setConsoleEnabled(false);
        
        // File persistence
        Log.setPersist(true);
        Log.setFilePath("logs/application.log");
        Log.setRollingInterval(RollingInterval.DAY);
        
        // Security
        Log.addSensitiveKey("password");
        Log.addSensitiveKey("token");
        Log.addSensitiveKey("secret");
        Log.addSensitiveKey("apiKey");
        
        // Performance
        Log.setDuplicateSuppressionWindow(5000L);
        
        // Global context
        Log.addMetaContext("environment", "production");
        Log.addMetaContext("version", "1.0.0");
    }
}

Environment-Based Configuration

Java
public class LoggerConfig {
    public static void initialize() {
        String environment = System.getenv("APP_ENVIRONMENT");
        boolean isDevelopment = "development".equalsIgnoreCase(environment);
        
        Log.setMinimumLevel(isDevelopment ? LogLevel.DEBUG : LogLevel.WARN);
        Log.setConsoleEnabled(isDevelopment);
        
        Log.setPersist(true);
        Log.setFilePath(isDevelopment ? "logs/debug.log" : "logs/production.log");
        Log.setRollingInterval(RollingInterval.DAY);
        
        Log.addSensitiveKey("password");
        Log.addSensitiveKey("token");
        Log.addSensitiveKey("secret");
        
        if (!isDevelopment) {
            Log.setDuplicateSuppressionWindow(10000L);
        }
        
        Log.setProjectToken(System.getenv("BYTEHIDE_LOGS_TOKEN"));
    }
}

Next Steps

After configuring the basic settings, explore these advanced topics:

Configuration:

Features:

Previous
Installation