Laravel Logging

Laravel Logging

Laravel provides robust logging services that allow you to log messages to files, the system error log, and even to Slack to notify your entire team.

Configuration

  • Config/logging.php.

Writing Log Messages

Log::emergency($message);
Log::alert($message);
Log::critical($message);
Log::error($message);
Log::warning($message);
Log::notice($message);
Log::info($message);
Log::debug($message);
<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Support\Facades\Log;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    /**
     * Show the profile for the given user.
     *
     * @param  int  $id
     * @return Response
     */
    public function showProfile($id)
    {
        Log::info('Showing user profile for user: '.$id);

        return view('user.profile', ['user' => User::findOrFail($id)]);
    }
}

By default, the message will be written to the default log channel as configured by your config/logging.php configuration file.

Advanced Monolog Channel Customization

Stack channel

Laravel will use the stack channel when logging messages.

Laravel Logging — Structure map

Clickable & Draggable!

Laravel Logging — Related pages: