File Logging Configuration
File logging allows you to persist logs to disk with automatic rotation. Configure file paths and rotation intervals to suit your needs.
Enable File Logging
Enable file persistence:
Java
Log.setPersist(true); // Enable file logging (default: false)
Log.setFilePath("logs/application.log"); // File path (default: "logs.txt")Log.setPersist(true); // Enable file logging (default: false)
Log.setFilePath("logs/application.log"); // File path (default: "logs.txt")File Path Configuration
Basic File Path
Java
Log.setPersist(true);
Log.setFilePath("logs/app.log");Log.setPersist(true);
Log.setFilePath("logs/app.log");Environment-Based Paths
Java
String environment = System.getenv("APP_ENVIRONMENT");
if (environment == null) environment = "production";
Log.setPersist(true);
Log.setFilePath("logs/" + environment.toLowerCase() + "/app.log");String environment = System.getenv("APP_ENVIRONMENT");
if (environment == null) environment = "production";
Log.setPersist(true);
Log.setFilePath("logs/" + environment.toLowerCase() + "/app.log");File Rotation Configuration
Rolling Intervals
Configure when files are rotated:
Java
import com.bytehide.logs.models.RollingInterval;
Log.setPersist(true);
Log.setFilePath("logs/app.log");
Log.setRollingInterval(RollingInterval.DAY); // Default: DAYimport com.bytehide.logs.models.RollingInterval;
Log.setPersist(true);
Log.setFilePath("logs/app.log");
Log.setRollingInterval(RollingInterval.DAY); // Default: DAYAvailable Intervals:
| Interval | Description |
|---|---|
RollingInterval.MINUTE | Every minute |
RollingInterval.HOUR | Every hour |
RollingInterval.DAY | Daily (recommended) |
RollingInterval.WEEK | Weekly |
RollingInterval.MONTH | Monthly |
RollingInterval.YEAR | Yearly |
Configuration Examples
Development Environment
Java
Log.setPersist(true);
Log.setFilePath("logs/debug.log");
Log.setRollingInterval(RollingInterval.HOUR);Log.setPersist(true);
Log.setFilePath("logs/debug.log");
Log.setRollingInterval(RollingInterval.HOUR);Production Environment
Java
Log.setPersist(true);
Log.setFilePath("logs/production.log");
Log.setRollingInterval(RollingInterval.DAY);Log.setPersist(true);
Log.setFilePath("logs/production.log");
Log.setRollingInterval(RollingInterval.DAY);High-Volume Applications
Java
Log.setPersist(true);
Log.setFilePath("logs/high-volume.log");
Log.setRollingInterval(RollingInterval.HOUR);Log.setPersist(true);
Log.setFilePath("logs/high-volume.log");
Log.setRollingInterval(RollingInterval.HOUR);File Management
Automatic Directory Creation
ByteHide Logger automatically creates directories if they don't exist:
Java
// This will create the full directory structure
Log.setFilePath("logs/application/2024/app.log");// This will create the full directory structure
Log.setFilePath("logs/application/2024/app.log");File Permissions
Ensure your application has write permissions to the log directory:
Bash
# Linux/Mac
chmod 755 logs/# Linux/Mac
chmod 755 logs/Best Practices
File Logging Best Practices
- Use daily rotation for most applications (
RollingInterval.DAY) - Use environment-specific paths to separate dev/staging/prod logs
- Monitor disk space in production environments
- Consider log retention policies for long-running applications
Troubleshooting
| Issue | Solution |
|---|---|
| Permission denied | Check write permissions on log directory |
| Directory not found | Enable automatic directory creation or create manually |
| Disk space full | Implement log retention or increase rotation frequency |