aaix/laravel-smart-log

Context-aware logging wrapper for Laravel applications

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/aaix/laravel-smart-log

1.0.2 2025-12-27 06:09 UTC

This package is auto-updated.

Last update: 2025-12-27 06:09:56 UTC


README

Laravel SmartLog Logo

Laravel SmartLog

Context-aware logging wrapper for Laravel applications.

Latest Version on Packagist Total Downloads License

SmartLog solves a common problem in Laravel CLI development: You want visual feedback in your terminal (colors, progress), but you don't want to clutter your production log files (laravel.log, Sentry, Slack) with developer noise.

SmartLog intelligently routes your messages based on context (CLI vs. Web) and configuration.

Installation

composer require aaix/laravel-smart-log

Usage

Use SmartLog anywhere in your code. It automatically detects if it's running inside an Artisan command or a web request.

use Aaix\SmartLog\SmartLog;

// 1. Standard Output (CLI: White | File: Ignored)
// Perfect for progress bars, raw data dumps, or steps.
SmartLog::log('Importing users step 1 of 5...');

// 2. Developer Output (CLI: Gray | File: Ignored)
// Subtle output for debugging.
SmartLog::debug('Memory usage: 12MB');

// 3. Operational Info (CLI: Cyan | File: Ignored by default)
// Good for status updates that don't need permanent storage.
SmartLog::info('User 123 imported successfully.');
SmartLog::success('All operations finished.'); // Alias for info with green color

// 4. Issues (CLI: Yellow/Red | File: LOGGED)
// These are automatically sent to your default log channel (File, Sentry, etc.)
SmartLog::warning('API rate limit approaching.');
SmartLog::error('Connection failed, retrying...');

// 5. Block Styles (CLI: Large Blocks | File: LOGGED)
// Visually dominant blocks for critical start/stop events.
SmartLog::successBlock('DEPLOYMENT COMPLETE');
SmartLog::errorBlock('CRITICAL SYSTEM FAILURE');

How it works

Method CLI Output (Visual) Log File (Persistence)
log() White text ❌ (Ignored)
debug() Gray text (subtle) ❌ (Ignored)
info() Cyan text ❌ (Ignored*)
success() Green text ❌ (Ignored*)
warning() Yellow text Logged (warning)
error() Red text Logged (error)

*Default configuration. You can enable persistence for info/debug levels in the config file.

Configuration

By default, only warning and error levels are written to the log file. Everything else remains visual-only in the console.

To change this, publish the configuration file:

php artisan vendor:publish --tag=smart-log-config

config/smart-log.php

return [
    'persist_levels' => [
        'error',
        'warning', 
        // Add 'info' here to save info() and success() calls to the log file
    ],
];

Web Context Behavior

If you use SmartLog within a Controller or Job (non-CLI):

  • Visual Output: Skipped (no echo or print).
  • Persistence: Respects the config. SmartLog::error() will log to the file. SmartLog::log() will do nothing.

Testing

Run the test command:

./vendor/bin/testbench smartlog:test

License

The MIT License (MIT). Please see License File for more information.