eterps
eterps

Reputation: 14208

How do I write separate log files for each Log level in Laravel 4?

My current logging setup creates a file for application messages and cli message. How would I get it to create a separate file for each of the different log levels (DEBUG, ERROR, etc...)?

My app/start/global.php config is like this:

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

Log::useDailyFiles(storage_path().'/logs/'.$logFile);

App::error(function(Exception $exception, $code)
{
    Log::error($exception);
});

Upvotes: 2

Views: 2990

Answers (1)

SudoGetBeer
SudoGetBeer

Reputation: 128

Use something like that:

$handler = new Monolog\Handler\RotatingFileHandler(storage_path().'/logs/info.log',0,Logger::INFO);
Log::getMonolog()->pushHandler($handler);

If you want it for errors use Logger::ERROR etc.

For Documentation of the __construct: https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/RotatingFileHandler.php

Upvotes: 3

Related Questions