Disable Error Logging In Laravel 4.2 When Environment is Local - php

I've seen a couple posts around here that tell me how to disable logging. Most of them say I have to comment out a few lines in app/start/global.php, and so I did:
// $logFile = 'laravel.log';
// Log::useDailyFiles(storage_path().'/logs/'.$logFile);
App::error(function(Exception $exception, $code){
// Log::error($exception);
});
My concern is that information still gets written to the log file, say when I navigate to a route that doesn't exist. I've also tried changing when the information is written to the log, for example:
if(App::environment() == "local"){
Log::info("Error Ignored. Environment: Local");
} else {
Log::error($exception);
}
But this doesn't seem to affect anything at all. If I get an error, it still logs the full error, and I know my environment is local by running php artisan env.
Lastly, I don't want to turn 'debug' => false, as I would never be able to see the errors.

After any config changes, it's usually a good idea to run the following commands:
php artisan optimize & php artisan cache:clear

Related

PHP - Laravel error : Symfony\Component\Finder\Exception\DirectoryNotFoundExceptionon my cPanel

I mistakenly ran my laravel application on debug mode in my production environment, and it threw an error for me to change App_debug:true to App_debug:false, which I did, ever since then, my site has been throwing an HTTP ERROR 500
"This page isn’t working admin.robyhub.com is currently unable to handle this request.
HTTP ERROR 500"
I then went on to my cpanel terminal and tried to clear the logs on the config file but it gives me the below error.
[thehcerl#premium261 admin.robyhub.com]$ php artisan config:clear
Symfony\Component\Finder\Exception\DirectoryNotFoundException
The "/home/thehcerl/admin.robyhub.com/resources/lang/ha" directory does not exist.
at vendor/symfony/finder/Finder.php:590
586▕ } elseif ($glob = glob($dir, (\defined('GLOB_BRACE') ? \GLOB_BRACE : 0) | \GLOB_ONLYDIR | \GLOB_NOSORT)) {
587▕ sort($glob);
588▕ $resolvedDirs = array_merge($resolvedDirs, array_map([$this, 'normalizeDir'], $glob));
589▕ } else {
➜ 590▕ throw new DirectoryNotFoundException(sprintf('The "%s" directory does not exist.', $dir));
591▕ }
592▕ }
593▕
594▕ $this->dirs = array_merge($this->dirs, $resolvedDirs);
+2 vendor frames
3 app/Providers/TranslationServiceProvider.php:40
Illuminate\Support\Facades\Facade::__callStatic()
4 app/Providers/TranslationServiceProvider.php:27
App\Providers\TranslationServiceProvider::phpTranslations()
Cpanel Terminal
Ever since I changed debug to false on my .env from my laravel project main directory because the laravel documentation warned me to not use debug mode on a non-local environment. I expected my application would automatically stop receiving the laravel debug config solutions and would run properly.
This is not a very generic error, it's as a result of an error on my part, I created language folders that I did not link to my PHP "translationProvider.php" file, so it invariably gave me that issue.
I was using a purchased template from Envato so I hadn't taken the time to get the full inner working of the backend at the time.
If anyone has a similar error I hope this will guide you not to make the mistakes I made, and meticulously look through your code when making changed or edits.
Thanks, happy coding.

Unable to understand the exception in Prod, while the same functionality works in Dev mode

Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "" at /var/www/<projectId>/src/oro/platform/src/Oro/Bundle/FeatureToggleBundle/EventListener/RequestListener.php line 33
And the trace as follows
{/var/www/<projectId>/src/oro/platform/src/Oro/Bundle/FeatureToggleBundle/EventListener/RequestListener.php:33 {▼
Oro\Bundle\FeatureToggleBundle\EventListener\RequestListener->onRequest(GetResponseEvent $event) …
› if ($event->isMasterRequest()) {
› throw new NotFoundHttpException();
› }
}
/var/www/<projectId>/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php:126 {}
And the request for offer functionality, works perfectly fine in Dev but not in Prod.
I have ensured that the files are updated and also made sure there is nothing that is amiss.
Checked DB migrations and ensured that all changes are intact
The fact that the functionality works fine on Dev is strange and When I do <App_URL>/index_dev.php/customer/request/create on the 500 Internal error does not show any error but infact loads the RFQ page perfectly fine and intact.
Any suggestions to debug this error or an understanding of What may be going wrong ?
According to the error message and the stack trace, you have the feature enabled in dev but disabled in a prod environment. Usually, it happens because of the cache.
So the first suggestion is to remove the file cache manually, using rm -rf var/cache/*, and if you are using Redis, flush the redis database as well. The cache:clear command is not always reliable.
You say that the exception is thrown only in prod, but the error stack-trace has wrappers, that must be used only with the debug=true option in the AppKernel. Please, make sure, you haven't customized the index.php file to enable debug, as it is unsecure, and make sure your web-server virtual host is configured to use index.php, not index_dev.php.
The exception comes from the feature toggle bundle. As the last resort, you can check the documentation, on how the feature is implemented, and debug the listener from the trace (src/oro/platform/src/Oro/Bundle/FeatureToggleBundle/EventListener/RequestListener), to see, where the value comes from.

laravel 5 show blank page on server error (and no laravel log), running with hhvm and nginx

I followed Fideloper post about running laravel with hhvm, step by step. There are two projects hosted on my server, one is my blog which is based on wardrobe (laravel 4.1), and another project with laravel 5.
My blog has no issue with server errors and laravel log file; But the other project cannot create log files, and it won't show error page because of that.
I double checked storage folder permission. It is 777.
When I run php artisan serve (native php, not hhvm) and browse to it, the error page showed up, and log file was created. So something is wrong with hhvm I think.
How can I fix blank page, when running laravel 5 with hhvm, and an error occurred? How can I bring back the error page (or whoops page)
P.S. I have read related question like this and still have the problem.
P.S.S. If any information needed ask me and I will update the question.
I suffered the same problem when I installed Laravel Homestead with HHVM. If you enter some random junk like sdfkjl into your routes file you'll get a blank page (however, if add a semi-colon sdfkjl; you get error output). The errors are being logged at /var/log/hhvm/error.log but they don't go to the browser, instead you just get a blank page. It appears this is intentional behavior for HHVM. It also appears Laravel tries to handle these but doesn't catch some of the fatals sent by HHVM. Thanks to clues from this github issue I decided to make some slight changes to Laravel's Foundation\Bootstrap\HandleExceptions.php to see if I could get it to catch all of these fatals:
First, update your /etc/hhvm/php.ini and add these settings:
hhvm.server.implicit_flush = true
hhvm.error_handling.call_user_handler_on_fatals = true
Before modifying a package source, let's remove the vendor\compiled.php with this artisan command:
$ php artisan clear-compiled
And let's set the environment sessons to array:
in your .env
SESSION_DRIVER=array
(You may also need to clear all the random-looking session files in storage/framework/sessions)
Now any changes we make to the Laravel package source will immediately reflect. Let's update a few things in the HandleExceptions class:
in vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php
// **** Add this to hold fatal error
protected static $fatalError = null;
...
public function handleError($level, $message, $file = '', $line = 0, $context = array())
{
// **** Add this, loads fatal error
if ($level & (1 << 24)) {
self::$fatalError = array(
'message' => $message,
'type' => $level,
'file' => $file,
'line' => $line
);
}
if (error_reporting() & $level)
{
throw new ErrorException($message, 0, $level, $file, $line);
}
}
...
// *** Update this function so it can handle the fatal
public function handleShutdown()
{
$error = error_get_last();
if(self::$fatalError){
$error = self::$fatalError;
}
if ( ! is_null($error) && $this->isFatal($error['type']))
{
$this->handleException($this->fatalExceptionFromError($error, 0));
}
}
...
protected function isFatal($type)
{
// *** Add type 16777217 that HVVM returns for fatal
return in_array($type, [16777217, E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE]);
}
...
Now type the random junk (no semi-colon) in your routes folder and you'll see the fatal display. I have now reported this issue to Taylor on the Laravel github. If you are in Lumen, I've got a solution here that will work until Lumen gets fixed as well.
I also got the same issue. Give 755 permission to entire laravel project it's work for me
anyway you can check hhvm error log, run
$tail -n 50 -f /var/log/hhvm/error.log

How to debug Laravel 5 projects?

I ran command
php artisan optimize
and changed debug settings in app.php file to be
'debug' => 'true',
and added 'everyone' to have full access over 'storage' folder. I don't know what else I can do to let debugger work in my Laravel 5 project.
I'm stuck with 'Whoops, looks like something went wrong' message.
Any Ideas??
The debug => true will just show you the full error stack when you hit an error with your app. It doesn't give metrics and statistics. If you are looking for that kind of information check out the article here:
https://laravel-news.com/2015/02/laravel-debugbar/
The error you are receiving is a general error, likely server-side configuration. Without any information on your setup it will be pretty hard to determine what your issue is. Based upon your question and comments to others responses I have a couple of things for you.
You stated "I don't know what else I can do to let debugger work in my Laravel 5 project". Laravel 5 doesn't have a native debugger any more which I imagine is why your page just shows "Whoops, looks like something went wrong". Your statement would indicate that you have a debugger, so which are you trying to use, or was that statement incorrect?
You stated that you changed the debug settings the app.php file. Is there a reason why you changed this in app.php? The debug setting by default is 'debug' => env('APP_DEBUG') which is sufficient in most cases. You should have a .env file in the root of your project (created automatically if you did a composer create-project, if not you need to copy .env.example to .env on your own). The .env file will enable debug for you as there is a line that states APP_DEBUG=true.
Jesse Schutt gave great information in his response above (which I recommend upvoting), including a link to a debug bar that is compatible with L5. Yet again you are stating that you are satisfied with your error stack which implies that you actually have one. If you were satisfied with it, you would have no need to have posted here as you would already have more information on your error. If you are assuming that the filp/whoops is in l5 still and that's what you want you'll have to re-enable it. Follow the instructions at http://mattstauffer.co/blog/bringing-whoops-back-to-laravel-5

Laravel 4.2 says my application is in production. How do I turn this off?

I have a fresh install of Laravel. When running php artisan migrate:refresh I get a message saying Application In Production! Do you really wish to run this command?'
I know this is an update in 4.2, however I can't figure out how to turn it off.
I found in the source that it comes from Illuminate\Console\ConfirmableTrait and runs if this if test passes : if ($this->getLaravel()->environment() == 'production')
I'm not sure why it thinks I'm in production. I never setup any environments. This is the default environment detection, which I'm still currently using.
$env = $app->detectEnvironment(array(
'local' => array('homestead')
));
Also, if I set a production environment to a hostname that isn't my machine, I still have the same problem.
Just specify a machine name for the host that matches a given environment, then laravel will automatically detect the environment (default is production), for example:
$env = $app->detectEnvironment(array(
//'local' => array('homestead'),
'local' => array('*.dev', gethostname()),
'production' => array('*.com', '*.net', 'www.somedomain.com')
));
Read the documentation and this answer as well.
Setting your environment to something other than production is The Right Way. See the accepted answer.
But, if you're looking for A Quick Fix you can use (in UNIXoid environments):
yes | php artisan migrate:refresh
All this does is send a stream of "y" to the program, which acts like you pressed "y" when prompted.
I find this to be a little better than --force, as not all the artisan commands support force.
In case if anyone stumbled upon this question while searching for similar problem in a lumen installation I'd suggest to check the .env file and add APP_ENV=local if its not already there. It solved my problem.
Hopefully this will help someone else. I suddenly had an issue where my dev site I was building stopped connecting to the DB saying:
PDOException SQLSTATE[HY000] [1049] Unknown database 'forge' failed
I was also receiving errors such as the OP when trying to run artisan migrate:refresh etc, the error was stating that i was in production etc etc.
After much head scratching (!) I found that my hostname value set inside the /bootstrap/start.php was wrong, because my hostname had changed on my macbook pro!? I have no idea how but it changed from something like RobMacbookPro2.local to RobMacbookPro.local. This meant it fell back to production thus loading the incorrect database.php file with the standard DB=forge (which was wrong)
Check this guide:
http://laravel.com/docs/4.2/configuration
Pay particular attention to the code:
<?php
$env = $app->detectEnvironment(array(
'local' => array('your-machine-name'),
));
On a mac and probably linux? you can determine your hostname by typing # hostname in terminal.
Hope that saves someone some time!

Categories