diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 804e69b83131..f4e8ca17722a 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -59,13 +59,17 @@ class Handler extends ExceptionHandler if (Utils::isNinja() && strpos(request()->url(), '/logo/') !== false) { return false; } + // Log 404s to a separate file + $errorStr = date('Y-m-d h:i:s') . ' ' . request()->url() . "\n" . json_encode(Utils::prepareErrorData('PHP')) . "\n\n"; + @file_put_contents(storage_path('logs/not_found.log'), $errorStr, FILE_APPEND); + return false; } elseif ($e instanceof HttpResponseException) { return false; } if (! Utils::isTravis()) { Utils::logError(Utils::getErrorString($e)); - $stacktrace = date('Y-m-d h:i:s') . ' ' . $e->getTraceAsString(); + $stacktrace = date('Y-m-d h:i:s') . ' ' . $e->getTraceAsString() . "\n\n"; @file_put_contents(storage_path('logs/stacktrace.log'), $stacktrace, FILE_APPEND); return false; } else { diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index c8f612d3ef92..6a3ca2010510 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -382,7 +382,18 @@ class Utils return 'logged'; } - $data = [ + $data = static::prepareErrorData($context); + + if ($info) { + Log::info($error."\n", $data); + } else { + Log::error($error."\n", $data); + } + } + + public static function prepareErrorData($context) + { + return [ 'context' => $context, 'user_id' => Auth::check() ? Auth::user()->id : 0, 'account_id' => Auth::check() ? Auth::user()->account_id : 0, @@ -397,19 +408,6 @@ class Utils 'is_api' => session('token_id') ? 'yes' : 'no', 'db_server' => config('database.default'), ]; - - if ($info) { - Log::info($error."\n", $data); - } else { - Log::error($error."\n", $data); - } - - /* - Mail::queue('emails.error', ['message'=>$error.' '.json_encode($data)], function($message) - { - $message->to($email)->subject($subject); - }); - */ } public static function parseFloat($value)