Backend Development Laravel Subjective
Sep 30, 2025

Explain Logging configuration in Laravel with code examples.

Detailed Explanation
Laravel logging configuration and usage: **Configuration (config/logging.php):**
return [
    "default" => env("LOG_CHANNEL", "stack"),
    "channels" => [
        "stack" => [
            "driver" => "stack",
            "channels" => ["single", "slack"],
        ],
        "single" => [
            "driver" => "single",
            "path" => storage_path("logs/laravel.log"),
            "level" => "debug",
        ],
        "daily" => [
            "driver" => "daily",
            "path" => storage_path("logs/laravel.log"),
            "level" => "debug",
            "days" => 14,
        ],
        "slack" => [
            "driver" => "slack",
            "url" => env("LOG_SLACK_WEBHOOK_URL"),
            "username" => "Laravel Log",
            "level" => "error",
        ],
    ],
];
**Basic Logging:**
use IlluminateSupportFacadesLog;

// Different log levels
Log::emergency("System is down");
Log::alert("Action must be taken immediately");
Log::critical("Critical conditions");
Log::error("Error conditions");
Log::warning("Warning conditions");
Log::notice("Normal but significant condition");
Log::info("Informational messages");
Log::debug("Debug-level messages");
**Contextual Logging:**
Log::info("User login", [
    "user_id" => $user->id,
    "ip_address" => request()->ip(),
    "user_agent" => request()->userAgent(),
]);

// Custom channel
Log::channel("slack')->error("Payment failed", [
    "order_id" => $order->id,
    "amount" => $order->total,
]);
Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback