Facing issue to integrate laravel error log features in my project - laravel

I am facing issue to integrate laravel error log features in my project, I am fresher, if anybody has some idea please share with me.
I had also used arcendev package but, I have no proper documentation about that so, it was difficult for me to understand functionality of arcendev package.

you can use the following code snippet as reference.
First you should import
use Illuminate\Support\Facades\Log;
As you have mentioned that you want to use log to show errors
If you are using try catch blocks to handle errors you can put log error in your catch for exceptions.
catch(Exception $e){
$error['error'] = $e->getMessage();
$error['inputs'] = $request->all();
Log::info('My Error Message',$error);
}
By default, the message will be written to the default log channel as configured by your config/logging.php configuration file.
You can also use Log::error($message); to keep track of log messages.
Check here for more logging messages.

Related

How can i Put My Project Between Try and catch in laravel

Hello Guys Please I Have A Big Project And I Want To Put All Project Classes Between Try And Catch To Handle Errors Because If I Put All Classes Between Try & catch manually It Takes A Lot of time
you have to put try catches on the functions in order to know and handle the error, if you put a try catch IN THEORY on your whole project, then your project will fail anyway since there is no clear way of catching and handling your error

Error getting valid response from API. Check log file for error details

I cant seem to find the error log of authorize.net api.
I have Laravel application which uses "authorizenet/authorizenet" package and the code where I try to create a customer profile, I get following error:
"Error getting valid response from API. Check log file for error details"
Can anyone tell me whereto find these logs? and what it's name?
I tried in /var/logs folder but i cant seem to find it.
if someone else has this issue, here is the solution.
The authorize.net has changed their endpoints from https://api.authorize.net to https://api2.authorize.net which is one of the possible reasons that you might get this error.
So if you are hardcoding these endpoints in your code then update it to the new one or if you are using library constant for it, same as me:
\net\authorize\api\constants\ANetEnvironment::SANDBOX
\net\authorize\api\constants\ANetEnvironment::PRODUCTION
Then simply update your library by running:
composer update authorizenet/authorizenet
This is how I resolved it and it seems to be the best way so far because it will update their library to take everything up to date if they have changes something else and you started experiencing this issue.
I hope it helps

Rollbar overrides Laravel's exception handler

I'm using Rollbar in a Laravel 5.7 app, and the following situation has been confusing and frustrating me.
It seems that my \app\Exceptions\Handler.php file isn't getting used normally.
I finally noticed that https://docs.rollbar.com/docs/laravel#section-exception-logging says:
"For Laravel 5.6, all errors which are normally handled by \App\Exceptions\Handler are going to be reported to Rollbar by default."
How can I disable this default functionality?
My \app\Exceptions\Handler.php will use Log to send data to Rollbar too, but it's important for me to run my whole exception handler since there is other functionality in there that needs to happen first.
Thanks.

How to catch parse errors in PHP?

I`m writing a light PHP framework for learning purposes and I came up to a problem. In famous frameworks like Laravel for example, all errors are caught and displayed in a custom mode. I know that I can setup custom errorHandler and exceptionHandler for my application like this:
set_error_handler([$handler, 'errorHandler']);
set_exception_handler([$handler, 'exceptionHandler']);
I can even setup shut_down function in order to catch the fatal errors and in combination with error_get_last() I can throw them as exceptions.
register_shutdown_function([$handler, 'shutDownFunction']);
Then problem is that I cannot catch parse errors. It seems none of my handlers are catching a parse error.
Is there a way to do that? Please help.
In php 7 parser errors handled with set_error_handler callback.

Laravel 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' how to find the URL that is causing the issue?

I have a CMS which uses quite a large number of ajax calls. There are no visible issues, but often when I look in Laravel's log file, I see a similar rambling mess of an error message about a 'NotFoundHttpException', presumably due to one of my api calls not finding the correct route.
I love Laravel, but my god, this has got to be one of the most unhelpful errors I have ever seen. There are references there to files deep within Laravel's core which I have no reason to ever touch nor care about. If this is a routing problem (which it ostensibly is) then all I really want to know is what the URL is that is causing the problem.
Is there any way of finding out which is the problem route, or any way of re-configuring the error reporting to tell you?
Thanks.
I don't know of any way to configure Laravel's error logging in such a way, but you can do it by yourself.
The error logging happens in app/start/global.php. There you have the "Application Error Handler". You can easily add an if statement and log your own message, including the actual URL that has been called.
App::error(function(Exception $exception, $code)
{
$message = $exception;
if($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException){
$message = 'URL '.Request::url().' not found - '.$exception;
}
Log::error($message);
});

Resources