PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, March 18, 2022

[FIXED] Laravel keeps logging even though APP_DEBUG=false

 March 18, 2022     environment-variables, laravel-5, logging, php     No comments   

Issue

For some reason laravel keeps writing log statements to the laravel log after I have set APP_DEBUG=false in my .env file.

I have the following log statement:

Log::debug("testmessage : BEGIN");

I have confirmed that the environment variable is being read by Laravel. I did this using this command that writes to the error log:

error_log("APP_DEBUG : " . env('APP_DEBUG', false));

It displays nothing if APP_DEBUG is false and '1' if it is true

I have cleared the cache :

gavin@gavin-VirtualBox:/var/www/hipengage$ **php artisan config:cache**
Configuration cache cleared!
Configuration cached successfully!
gavin@gavin-VirtualBox:/var/www/hipengage$ **php artisan cache:clear**
Application cache cleared!

I have restarted apache

My .env file looks like this:

APP_ENV=local
APP_DEBUG=false
APP_KEY=*********************************

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

Anything I am missing here? Any help much appreciated.


Solution

APP_DEBUG is used to limit the amount of error details your application displays through the browser.

It should not be confused that it controls the logging in log file.

To log only when APP_DEBUG is true then you can check it's value and do that as:

if (config('app.debug'))
{
    Log::debug("some debug text");
}

Or you can create a helper function like:

function some_cool_name($log)
{
    if (config('app.debug')) {
        Log::debug($log);
    }
}

And then you can use it anywhere:

some_cool_name('some debug text');


Answered By - Amit Gupta
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing