Question

I am using this code for logging the error in L4

    $logFile = 'log-' . php_sapi_name() . '.txt';

    Log::useDailyFiles(storage_path() . '/logs/' . $logFile);
    App::error(function(Exception $exception, $code) {

        Log::error($exception);

    });

but this logs are very heavy error message with trace stack. I don't want any extra data into it, I want only an error name, an error code, an error message and exact location of file. I mean the file containing that statement.

Was it helpful?

Solution

Well, you can try to make your own logger. Something like this:

Create a new model named 'Logger' (or some other name, but not 'Log', because its reserved for laravel).

/**
 * Create new log record in database
 *
 */
protected static function createLog($user_id, $ip, $class, $method, $description, $url, $uri, $prio)
{
    $log = new Logger();
    $log->user_id = $user_id;
    $log->ip = $ip;
    $log->class = $class;
    $log->method = $method;
    $log->description = $description;
    $log->url = $url;
    $log->uri = $uri;
    $log->prio = $prio;
    $log->save();
    return true;
}

And then just call the method like so:

Logger::createLog(Auth::user()->id, Request::getClientIp(),'UserController','postCreate','User successfully created', Request::url(), Request::path(), 2);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top