B
B
BonBon Slick2017-09-24 17:18:48
Laravel
BonBon Slick, 2017-09-24 17:18:48

Laravel log to a custom file, sculpts all the errors in a row?

$app = ['aaa' => 123];
        Log::useFiles(base_path() . '/storage/logs/steam_apps_sync.log', 'info');
        Log::info(json_encode($app) . '\r\n');

Everything is fine, however, if another error pops up somewhere on the site, it is automatically sculpted into the laravel.log file and into this custom one.
And I, for example, catch an exception for a specific case, and I want to write only data about it in a separate log file without unnecessary errors.
Please tell me why it also sculpts other errors in this file and how to do it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Talalaev, 2017-09-25
@BonBonSlick

Monolog is built into Laravel (I advise you to study it if you are interested in the topic of logs), it has the ability to track event types , here 's an example :

$app->configureMonologUsing(function ($monolog) use ($app) {
    $monolog->pushHandler(new Monolog\Handler\StreamHandler($app->storagePath() . '/logs/info.log', Monolog\Logger::DEBUG, false));
    $monolog->pushHandler(new Monolog\Handler\StreamHandler($app->storagePath() . '/logs/laravel.log', Monolog\Logger::NOTICE, false));

    return $monolog;
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question