/

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")

File Path Configuration

Basic File Path

Java
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");

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: DAY

Available Intervals:

IntervalDescription
RollingInterval.MINUTEEvery minute
RollingInterval.HOUREvery hour
RollingInterval.DAYDaily (recommended)
RollingInterval.WEEKWeekly
RollingInterval.MONTHMonthly
RollingInterval.YEARYearly

Configuration Examples

Development Environment

Java
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);

High-Volume Applications

Java
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");

File Permissions

Ensure your application has write permissions to the log directory:

Bash
# 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

IssueSolution
Permission deniedCheck write permissions on log directory
Directory not foundEnable automatic directory creation or create manually
Disk space fullImplement log retention or increase rotation frequency
Previous
Console Output