PHPackages                             vocweb/laravel-log-compress - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. vocweb/laravel-log-compress

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

vocweb/laravel-log-compress
===========================

Auto-compress daily rotated Laravel log files with optional password protection

v0.2.2(yesterday)05—0%MITPHPPHP ^8.1

Since Mar 19Pushed yesterdayCompare

[ Source](https://github.com/vocweb/laravel-log-compress)[ Packagist](https://packagist.org/packages/vocweb/laravel-log-compress)[ RSS](/packages/vocweb-laravel-log-compress/feed)WikiDiscussions develop Synced today

READMEChangelogDependencies (5)Versions (6)Used By (0)

Laravel Log Compress
====================

[](#laravel-log-compress)

Automatically compress daily-rotated Laravel log files to tar.gz archives with optional AES-256 password encryption. Reduce storage costs and simplify log management.

Features
--------

[](#features)

- ✅ **Auto-discover daily channels** from logging configuration
- ✅ **Smart file detection** finds logs matching `{base}-YYYY-MM-DD.log` pattern
- ✅ **Optional encryption** AES-256-CBC via OpenSSL with PBKDF2 hashing
- ✅ **Configurable retention** skip logs newer than N days (default: 1)
- ✅ **Safe deletion** remove originals only after successful compression
- ✅ **Auto-scheduled** runs daily automatically, zero config needed
- ✅ **Manual &amp; scheduled** Artisan command + custom scheduler support
- ✅ **Error resilience** continue processing on individual file errors, report all issues
- ✅ **Secure passwords** passed via environment variables, never exposed in process list

Requirements
------------

[](#requirements)

ComponentVersionPHP8.1+Laravel10.x, 11.x, 12.x, 13.xSystem Tools`tar`, `openssl` (for encryption)Typical Linux/macOS installations have both tools. Windows requires GNU tar/openssl.

Installation
------------

[](#installation)

### Via Composer

[](#via-composer)

```
composer require vocweb/laravel-log-compress
```

The package auto-registers via Laravel's package discovery.

### Publish Configuration (Optional)

[](#publish-configuration-optional)

```
php artisan vendor:publish --tag=log-compress-config
```

This creates `config/log-compress.php` in your Laravel project.

Configuration
-------------

[](#configuration)

### Environment Variables

[](#environment-variables)

Add to your `.env` file:

```
# Optional: Set encryption password
LOG_COMPRESS_PASSWORD=your_secure_password_here

# Optional: Disable auto-schedule (default: true)
LOG_COMPRESS_AUTO_SCHEDULE=true

# Optional: Change schedule time (default: 00:00)
LOG_COMPRESS_SCHEDULE_TIME=00:00
```

### Configuration File

[](#configuration-file)

Edit `config/log-compress.php`:

```
return [
    // Encryption password (overrides env if set)
    'password' => env('LOG_COMPRESS_PASSWORD', null),

    // Delete original log files after successful compression
    'delete_after_compress' => true,

    // Only compress logs older than N days (prevents active log compression)
    'older_than_days' => 1,

    // Automatically schedule daily compression (default: true)
    'auto_schedule' => env('LOG_COMPRESS_AUTO_SCHEDULE', true),

    // Time of day for auto-scheduled compression (24h format)
    'schedule_time' => env('LOG_COMPRESS_SCHEDULE_TIME', '00:00'),
];
```

Usage
-----

[](#usage)

### Manual Compression

[](#manual-compression)

Compress all eligible daily log files:

```
php artisan log:compress
```

### With Password Override

[](#with-password-override)

Encrypt archives with a specific password (overrides config):

```
php artisan log:compress --password=my_secure_password
```

### Auto-Scheduled Execution

[](#auto-scheduled-execution)

By default, the package **automatically registers** a daily scheduled task to compress logs. No manual setup required — just ensure your Laravel scheduler is running:

```
# Add to crontab (if not already configured)
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
```

#### Configure Auto-Schedule

[](#configure-auto-schedule)

Via `.env`:

```
# Disable auto-schedule (default: true)
LOG_COMPRESS_AUTO_SCHEDULE=false

# Change schedule time (default: 00:00)
LOG_COMPRESS_SCHEDULE_TIME=02:00
```

#### Manual Schedule (if auto-schedule is disabled)

[](#manual-schedule-if-auto-schedule-is-disabled)

If you set `LOG_COMPRESS_AUTO_SCHEDULE=false`, register the schedule manually:

**Laravel 10** — `app/Console/Kernel.php`:

```
protected function schedule(Schedule $schedule)
{
    $schedule->command('log:compress')->dailyAt('02:00');
}
```

**Laravel 11** — `routes/console.php`:

```
use Illuminate\Support\Facades\Schedule;

Schedule::command('log:compress')->dailyAt('02:00');
```

**Laravel 12 / 13** — `bootstrap/app.php`:

```
use Illuminate\Console\Scheduling\Schedule;

->withSchedule(function (Schedule $schedule) {
    $schedule->command('log:compress')->dailyAt('02:00');
})
```

How It Works
------------

[](#how-it-works)

### Discovery

[](#discovery)

1. Scans all channels in `config/logging.php`
2. Identifies channels with `driver: daily`

### Selection

[](#selection)

3. For each daily channel, finds log files:
    - Pattern: `{base_path}-YYYY-MM-DD.log`
    - Age: older than `older_than_days` setting
    - Status: not already compressed

### Compression

[](#compression)

4. Creates tar.gz archive using system `tar` command
5. If password configured: encrypts with OpenSSL AES-256-CBC
6. Cleans up partial files on failure

### Cleanup

[](#cleanup)

7. Deletes original log file (if `delete_after_compress: true`)
8. Reports count of compressed files and any errors

Decrypting Encrypted Archives
-----------------------------

[](#decrypting-encrypted-archives)

If you encrypted logs with a password, decrypt them:

```
# Decrypt to stdout
openssl enc -d -aes-256-cbc -pbkdf2 -pass pass:your_password -in laravel-2024-01-15.log.tar.gz | tar xz

# Or extract directly to a directory
openssl enc -d -aes-256-cbc -pbkdf2 -pass pass:your_password -in laravel-2024-01-15.log.tar.gz | tar xz -C /path/to/extract

# Save decrypted archive (unencrypted tar.gz)
openssl enc -d -aes-256-cbc -pbkdf2 -pass pass:your_password -in laravel-2024-01-15.log.tar.gz -out laravel-2024-01-15.log.tar.gz.decrypted
tar xzf laravel-2024-01-15.log.tar.gz.decrypted
```

Example Workflow
----------------

[](#example-workflow)

### Setup

[](#setup)

```
# 1. Install package
composer require vocweb/laravel-log-compress

# 2. Set encryption password in .env
echo "LOG_COMPRESS_PASSWORD=MySecurePass123" >> .env

# 3. Publish config (optional)
php artisan vendor:publish --tag=log-compress-config

# 4. Auto-schedule is enabled by default (runs daily at 00:00)
# To customize: set LOG_COMPRESS_SCHEDULE_TIME=02:00 in .env
```

### Daily Operation

[](#daily-operation)

```
2024-01-14 23:59:59 - Laravel writes to storage/logs/laravel-2024-01-14.log
2024-01-15 00:00:00 - New day, Laravel creates laravel-2024-01-15.log
2024-01-15 02:00:00 - Scheduled: php artisan log:compress
  ✓ Finds laravel-2024-01-14.log (older than 1 day)
  ✓ Creates laravel-2024-01-14.log.tar.gz (encrypted)
  ✓ Deletes laravel-2024-01-14.log
  → storage/logs/laravel-2024-01-14.log.tar.gz (encrypted, ~1% of original size)

```

### Retrieve Old Logs

[](#retrieve-old-logs)

```
# List encrypted archive contents
openssl enc -d -aes-256-cbc -pbkdf2 -pass pass:MySecurePass123 -in laravel-2024-01-14.log.tar.gz | tar tzf -

# Extract specific log
openssl enc -d -aes-256-cbc -pbkdf2 -pass pass:MySecurePass123 -in laravel-2024-01-14.log.tar.gz | tar xzOf - laravel-2024-01-14.log | grep "error"
```

Logging Configuration
---------------------

[](#logging-configuration)

Ensure you have a `daily` channel in `config/logging.php`:

```
'channels' => [
    'daily' => [
        'driver' => 'daily',
        'path' => storage_path('logs/laravel.log'),
        'level' => env('LOG_LEVEL', 'debug'),
        'days' => 14,
    ],
    // other channels...
],
```

Multiple daily channels are supported and will all be compressed.

Output &amp; Status Codes
-------------------------

[](#output--status-codes)

### Successful Compression

[](#successful-compression)

```
Scanning for daily log files to compress...
Compressed 5 log file(s).

```

Exit code: 0

### No Files Found

[](#no-files-found)

```
Scanning for daily log files to compress...
No log files found to compress.

```

Exit code: 0

### With Errors

[](#with-errors)

```
Scanning for daily log files to compress...
Compressed 3 log file(s).
[error] Failed to compress /path/to/laravel-2024-01-10.log: Permission denied
[error] Failed to delete original /path/to/laravel-2024-01-09.log: ...

```

Exit code: 1

Security Notes
--------------

[](#security-notes)

- **Passwords**: Never stored in config; use `.env` file only
- **Process safety**: Passwords passed via environment variables, hidden from `ps aux`
- **Encryption**: AES-256-CBC with PBKDF2 (10,000 iterations), industry-standard
- **Path safety**: Real path resolution prevents directory traversal attacks
- **File handling**: Atomic operations; partial files cleaned up on failure

Troubleshooting
---------------

[](#troubleshooting)

### "tar: command not found"

[](#tar-command-not-found)

- Install tar: `apt-get install tar` (Debian/Ubuntu) or `brew install gnu-tar` (macOS)

### "openssl: command not found" (with encryption enabled)

[](#openssl-command-not-found-with-encryption-enabled)

- Install openssl: `apt-get install openssl` or `brew install openssl`

### Permission denied errors

[](#permission-denied-errors)

- Ensure Laravel process has read access to log files
- Ensure write access to log directory (for deletion)

### Encrypted archives not decrypting

[](#encrypted-archives-not-decrypting)

- Verify password: check `.env` matches password used at compression time
- Use `-pass pass:your_password` in openssl command (or `-pass stdin` to prompt)

License
-------

[](#license)

MIT License - see LICENSE file for details.

Credits
-------

[](#credits)

Created by vocweb. Inspired by the need to manage large production log archives efficiently.

###  Health Score

38

—

LowBetter than 86% of packages

Maintenance100

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

1d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/30e3379e8d19b8dfc60d98859c909d9f83845b445558b103cb52286c293070e6?d=identicon)[tien](/maintainers/tien)

---

Top Contributors

[![vocweb](https://avatars.githubusercontent.com/u/285232?v=4)](https://github.com/vocweb "vocweb (1 commits)")

---

Tags

loglaravelarchivetarcompress

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vocweb-laravel-log-compress/health.svg)

```
[![Health](https://phpackages.com/badges/vocweb-laravel-log-compress/health.svg)](https://phpackages.com/packages/vocweb-laravel-log-compress)
```

###  Alternatives

[spatie/laravel-tail

Easily tail application logs

7592.5M4](/packages/spatie-laravel-tail)[yadahan/laravel-authentication-log

Laravel Authentication Log provides authentication logger and notification for Laravel.

417620.3k5](/packages/yadahan-laravel-authentication-log)[jackiedo/log-reader

An easy log reader and management tool for Laravel

151365.1k4](/packages/jackiedo-log-reader)[ytake/laravel-fluent-logger

fluent logger for laravel and lumen

62538.4k1](/packages/ytake-laravel-fluent-logger)[hedii/artisan-log-cleaner

An artisan command to clear laravel log files

4160.8k](/packages/hedii-artisan-log-cleaner)[kitloong/laravel-app-logger

Laravel log for your application

101.2M6](/packages/kitloong-laravel-app-logger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
