Score:0

Laravel: Logging messages generated by "error_log(...)" to terminal, while running app in Apache server

ne flag

The issue is this one:

When I run a Laravel app from PHP server, that's it, with php artisan serve, I could see every message generated by "error_log(...)" printed in the terminal, like this:

leandro@leandro-Lenovo-B50-10:~/laravel-leaflet-example$ php artisan serve
Illuminate\Foundation\Application
/home/leandro/laravel-leaflet-example/bootstrap
Log desde 'register' de AppServiceProvider
Log desde 'register' de TelescopeServiceProvider. Este método se ejecuta ni bien corremos el server

Log desde 'boot' de AppServiceProvider
Illuminate\Foundation\Application
Log desde 'boot' de AuthServiceProvider. Este método se ejecuta ni bien corremos el server

Tipo de $this->policies():
array


App\Policies\OutletPolicy
App\Policies\ModelPolicy


App\Outlet
App\Policies\OutletPolicy
App\Model
App\Policies\ModelPolicy
Fin de Log desde 'boot' de AuthServiceProvider

   INFO  Server running on [http://127.0.0.1:8000].  

  Press Ctrl+C to stop the server

   WARN  Illuminate\Foundation\Application.  

   WARN  bootstrap.  

   WARN  Log desde 'register' de AppServiceProvider.  

   WARN  Log desde 'register' de TelescopeServiceProvider. Este método se ejecuta ni bien corremos el server.  

   WARN  Log desde 'boot' de AppServiceProvider.  

   WARN  Illuminate\Foundation\Application.  

However, while trying to achieve something similar but in Apache server (instead of PHP server) , I've found some troubles.

By running the phpinfo();function within a test file, I'm getting the line:

Loaded Configuration File | /etc/php/8.2/apache2/php.ini

Then, by adding the line error_log = /home/leandro/log/php_errors.log to that file, and then restarting Apache, I could achieve a similar result by doing in the console:
tail -n 0 -f /home/leandro/log/php_errors.log

Despite this works, this solution implies a lot of disk I/O operations and so on, an ugly performance and potential harm to the disk at long term.

I've tried to replace the mentioned line in my "php.ini" to error_log = /dev/stderr and then the commands:
tail -f /dev/stderr and cat /dev/stderr in the terminal, but none of them is working, even with the sudo prefix.

Anyone has an idea of how to achieve the result I want to?

If there's more information needed, or something that it isn't well understood, please let me know.

Thanks a lot!
Leandro

EDIT:

My "config/logging.php":

<?php

use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;

return [

    /*
    |---------------------------------------------
    | Default Log Channel
    |---------------------------------------------
    |
    | This option defines the default log channel that gets used when writing
    | messages to the logs. The name specified in this option should match
    | one of the channels defined in the "channels" configuration array.
    |
    */

    'default' => env('LOG_CHANNEL', 'stack'),

    /*
    |---------------------------------------------
    | Deprecations Log Channel
    |---------------------------------------------
    |
    | This option controls the log channel that should be used to log warnings
    | regarding deprecated PHP and library features. This allows you to get
    | your application ready for upcoming major versions of dependencies.
    |
    */

    'deprecations' => [
        'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
        'trace' => false,
    ],

    /*
    |---------------------------------------------
    | Log Channels
    |---------------------------------------------
    |
    | Here you may configure the log channels for your application. Out of
    | the box, Laravel uses the Monolog PHP logging library. This gives
    | you a variety of powerful log handlers / formatters to utilize.
    |
    | Available Drivers: "single", "daily", "slack", "syslog",
    |                    "errorlog", "monolog",
    |                    "custom", "stack"
    |
    */

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

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

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

        'slack' => [
            'driver' => 'slack',
            'url' => env('LOG_SLACK_WEBHOOK_URL'),
            'username' => 'Laravel Log',
            'emoji' => ':boom:',
            'level' => env('LOG_LEVEL', 'critical'),
        ],

        'papertrail' => [
            'driver' => 'monolog',
            'level' => env('LOG_LEVEL', 'debug'),
            'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class),
            'handler_with' => [
                'host' => env('PAPERTRAIL_URL'),
                'port' => env('PAPERTRAIL_PORT'),
                'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
            ],
        ],

        'stderr' => [
            'driver' => 'monolog',
            'level' => env('LOG_LEVEL', 'debug'),
            'handler' => StreamHandler::class,
            'formatter' => env('LOG_STDERR_FORMATTER'),
            'with' => [
                'stream' => 'php://stderr',
            ],
        ],

        'syslog' => [
            'driver' => 'syslog',
            'level' => env('LOG_LEVEL', 'debug'),
        ],

        'errorlog' => [
            'driver' => 'errorlog',
            'level' => env('LOG_LEVEL', 'debug'),
        ],

        'null' => [
            'driver' => 'monolog',
            'handler' => NullHandler::class,
        ],

        'emergency' => [
            'path' => storage_path('logs/laravel.log'),
        ],
    ],

];

My ".env":

APP_NAME=InfoAlq
APP_ENV=local
APP_KEY=base64:N+QlCYsU2lDVNWiJ+KEP+QraqWsDbar7eLWwtJa+M3s=
APP_DEBUG=true
APP_URL=http://www.infoalq.local

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=jetstream3
DB_USERNAME=root
DB_PASSWORD=root

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=public
QUEUE_CONNECTION=sync
SESSION_DRIVER=database
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=sandbox.smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=0a3a3bb4fcb540
MAIL_PASSWORD=7a9e2495cc9668
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="Leandro Caplan"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1

VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
UnderDog avatar
cn flag
go to your `config/logging.php` file and see all the options there. One of then is `stdout` or something similar. You can make that setting by altering the .env file
Leandro Caplan avatar
ne flag
@UnderDog Should I post here the content of both my "config/logging.php" and my ".env" files? I'm really messed up =(
UnderDog avatar
cn flag
Well... update your original question with that extra information, it might help you
Leandro Caplan avatar
ne flag
@UnderDog I've just done right that
UnderDog avatar
cn flag
Replace `LOG_CHANNEL=stack` in your .env file with `LOG_CHANNEL=stderr` and let's see what happens
Leandro Caplan avatar
ne flag
@UnderDog I've done that, still doesn't work =(
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.