Logs Logo

Introduction

How to configure an example of a custom log file ( let´s call it ' test.log ' )

Add the new configuration inside the array of channels in the file ' app -> config -> logging ' like this:

    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['single'],
            'ignore_exceptions' => false,
        ],

        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/laravel.log'),
            'level' => env('LOG_LEVEL', 'debug'),
        ],
        
            .
            .
            .
            .
  
 ---->  'test' => [
            'driver' => 'single',
            'path' => storage_path('logs/test.log'),
            'level' => env('LOG_LEVEL', 'debug'),
        ],
    ],
    
            .
            .
            .
            .
    
    ],
];

Example on how to call this new log:

Log usage test

And that will add the massage in the new log file:

Log usage result

Extra note:

If is needed to save the content of an email, add the following configuration:

<?php

return [

    'default' => env('MAIL_MAILER', 'log'),       <----- This is in your .env file config. By default you can set it with 'log' value.
    
    .
    .
    .

    'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.gmail.com'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'auth_mode' => null,
        ],

        .
        .
        .
        .

        'log' => [
            'transport' => 'log',
            'channel' => env('MAIL_LOG_CHANNEL'),      <----- This is in your .env file config. It is the name of the channel.
        ],

        .
        .
        .
        .
        
        'array' => [
            'transport' => 'array',
        ],
    ];

Demonstration

( Click on the image to watch the video )

Demonstration video