Reduce error information in Logfile How can i reduce the amount of information written in laravel.log file?
Eg:
[2021-09-16 11:09:29] production.ERROR: Undefined variable $name {"exception":"[object] (ErrorException(code: 0): Undefined variable $name at /var/www/vhosts/mydomain.com/app/Http/Controllers/myController.php:199)
[stacktrace]
#0 /var/www/vhosts/mydomain.com/app/Http/Controllers/myController.php(199): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()
#1 /var/www/vhosts/mydomain.com/app/Http/Controllers/myController.php(192): App\Http\Controllers\myController->handleRequestType()
#2 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\Http\Controllers\myController->ValidateInboundRequest()
#3 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction()
#4 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Routing/Route.php(261): Illuminate\Routing\ControllerDispatcher->dispatch()
#5 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Routing/Route.php(204): Illuminate\Routing\Route->runController()
#6 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php(695): Illuminate\Routing\Route->run()
#7 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#8 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#9 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Routing\Middleware\SubstituteBindings->handle()
#10 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(78): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#11 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle()
#12 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#13 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\View\Middleware\ShareErrorsFromSession->handle()
#14 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#15 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession->handleStatefulRequest()
#16 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Session\Middleware\StartSession->handle()
#17 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#18 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle()
#19 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#20 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Cookie\Middleware\EncryptCookies->handle()
#21 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#22 /var/www/vhosts/mydomain.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php(697): Illuminate\Pipeline\Pipeline->then()
and so on...
In general I dont need any further information after the first entry It should just become:
[2021-09-16 11:09:29] production.ERROR: Undefined variable $name {"exception":"[object] (ErrorException(code: 0): Undefined variable $name at /var/www/vhosts/mydomain.com/app/Http/Controllers/myController.php:199)
@surreal It’s a lot file. It logs things. What you have is the exception and its stack trace.
Don‘t try and remove context because I can guarantee one day you’ll have an error where it doesn’t occur in the first frame but in fact occurs somewhere else in your application, and you won’t have the stack trace to debug it.
@martinbean Is there an option to create a separate log file where my desired first entry is only being logged?
@surreal Truncating information is not the answer. As @tykus says: what’s the actual issue you’re having?
What problem are you actually trying to solve here @surreal ? If your log file is getting too large because you are not rotating; use logrotate ? Or, is the problem readability; consider a Log Reader ?
Ultimately, one of our jobs as developers is the ability find, diagnose, understand and fix issues in our applications - reading a full stacktrace is foundational.
Please sign in or create an account to participate in this conversation.