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:
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);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
| Method | Description | Default |
|---|---|---|
setProjectToken(String) | Set project token manually | null |
setProject() | Load token from environment variable | - |
setConsoleEnabled(boolean) | Enable/disable console output | false |
setMinimumLevel(LogLevel) | Minimum log level to process | WARN |
setPersist(boolean) | Enable/disable file persistence | false |
setFilePath(String) | Log file path | "logs.txt" |
setRollingInterval(RollingInterval) | File rotation interval | DAY |
addSensitiveKey(String) | Add sensitive data key to mask | - |
setDuplicateSuppressionWindow(Long) | Duplicate suppression window (ms) | 1000 |
setUser(AuthUser) | Set authenticated user | null |
setAnonymousId(String) | Set anonymous user ID | null |
addMetaContext(String, Object) | Add global context metadata | - |
File Persistence Settings
Control how logs are saved to files:
import com.bytehide.logs.models.RollingInterval;
// Enable file logging
Log.setPersist(true);
Log.setFilePath("logs/application.log");
// File rotation settings
Log.setRollingInterval(RollingInterval.DAY);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 minuteRollingInterval.HOUR: Every hourRollingInterval.DAY: Daily (recommended)RollingInterval.WEEK: WeeklyRollingInterval.MONTH: MonthlyRollingInterval.YEAR: Yearly
Console Output Settings
Configure console logging:
Log.setConsoleEnabled(true); // Default: falseLog.setConsoleEnabled(true); // Default: falseLog Level Configuration
Set the minimum log level to process:
import com.bytehide.logs.models.LogLevel;
Log.setMinimumLevel(LogLevel.INFO); // Default: LogLevel.WARNimport com.bytehide.logs.models.LogLevel;
Log.setMinimumLevel(LogLevel.INFO); // Default: LogLevel.WARNAvailable Log Levels (in order of severity):
LogLevel.TRACE: Most detailed diagnostic informationLogLevel.DEBUG: Detailed diagnostic informationLogLevel.INFO: General information messagesLogLevel.WARN: Warning messages for potential issuesLogLevel.ERROR: Error messages for failuresLogLevel.CRITICAL: Critical errors that may cause application termination
Security Settings
Configure data masking for sensitive information:
// Add sensitive keys to mask in logs
Log.addSensitiveKey("password");
Log.addSensitiveKey("token");
Log.addSensitiveKey("apiKey");
Log.addSensitiveKey("creditCard");// Add sensitive keys to mask in logs
Log.addSensitiveKey("password");
Log.addSensitiveKey("token");
Log.addSensitiveKey("apiKey");
Log.addSensitiveKey("creditCard");Performance Settings
Configure duplicate suppression:
// Suppress duplicate messages within time window (milliseconds)
Log.setDuplicateSuppressionWindow(5000L); // 5 seconds// Suppress duplicate messages within time window (milliseconds)
Log.setDuplicateSuppressionWindow(5000L); // 5 secondsConfiguration Examples
Development Environment
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");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
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 secondsLog.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 secondsComplete Configuration Example
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");
}
}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
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"));
}
}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: