Skip to content

Commit

Permalink
make log handler more robust against failure
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 6, 2016
1 parent 59a440e commit 6550153
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
12 changes: 6 additions & 6 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ class Application extends Container implements ApplicationContract, HttpKernelIn
*/
public function __construct($basePath = null)
{
if ($basePath) {
$this->setBasePath($basePath);
}

$this->registerBaseBindings();

$this->registerBaseServiceProviders();

$this->registerCoreContainerAliases();

if ($basePath) {
$this->setBasePath($basePath);
}
}

/**
Expand Down Expand Up @@ -185,9 +185,9 @@ protected function registerBaseServiceProviders()
{
$this->register(new EventServiceProvider($this));

$this->register(new RoutingServiceProvider($this));

$this->register(new LogServiceProvider($this));

$this->register(new RoutingServiceProvider($this));
}

/**
Expand Down
55 changes: 41 additions & 14 deletions src/Illuminate/Log/LogServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function register()
public function createLogger($app)
{
$log = new Writer(
new Monolog($app->environment()), $app['events']
new Monolog($app->bound('env') ? $app->environment() : 'production'), $app['events']
);

if ($app->hasMonologConfigurator()) {
Expand All @@ -52,7 +52,13 @@ public function createLogger($app)
*/
protected function configureHandlers(Application $app, Writer $log)
{
$method = 'configure'.ucfirst($app['config']['app.log']).'Handler';
if ($this->app->bound('config')) {
$handler = $this->app->make('config')->get('app.log');
} else {
$handler = 'single';
}

$method = 'configure'.ucfirst($handler).'Handler';

$this->{$method}($app, $log);
}
Expand All @@ -68,7 +74,7 @@ protected function configureSingleHandler(Application $app, Writer $log)
{
$log->useFiles(
$app->storagePath().'/logs/laravel.log',
$app->make('config')->get('app.log_level', 'debug')
$this->logLevel()
);
}

Expand All @@ -81,13 +87,9 @@ protected function configureSingleHandler(Application $app, Writer $log)
*/
protected function configureDailyHandler(Application $app, Writer $log)
{
$config = $app->make('config');

$maxFiles = $config->get('app.log_max_files');

$log->useDailyFiles(
$app->storagePath().'/logs/laravel.log', is_null($maxFiles) ? 5 : $maxFiles,
$config->get('app.log_level', 'debug')
$app->storagePath().'/logs/laravel.log', $this->maxFiles(),
$this->logLevel()
);
}

Expand All @@ -100,10 +102,7 @@ protected function configureDailyHandler(Application $app, Writer $log)
*/
protected function configureSyslogHandler(Application $app, Writer $log)
{
$log->useSyslog(
'laravel',
$app->make('config')->get('app.log_level', 'debug')
);
$log->useSyslog('laravel', $this->logLevel());
}

/**
Expand All @@ -115,6 +114,34 @@ protected function configureSyslogHandler(Application $app, Writer $log)
*/
protected function configureErrorlogHandler(Application $app, Writer $log)
{
$log->useErrorLog($app->make('config')->get('app.log_level', 'debug'));
$log->useErrorLog($this->logLevel());
}

/**
* Get the log level for the application.
*
* @return string
*/
protected function logLevel()
{
if ($this->app->bound('config')) {
return $this->app->make('config')->get('app.log_level');
}

return 'debug';
}

/**
* Get the maximum number of log files for the application.
*
* @return int
*/
protected function maxFiles()
{
if ($this->app->bound('config')) {
return $this->app->make('config')->get('app.log_max_files', 5);
}

return 0;

This comment has been minimized.

Copy link
@MartelliEnrico

MartelliEnrico Oct 18, 2016

Shouldn't this be 5 like the default number used 3 lines above?

}
}

0 comments on commit 6550153

Please sign in to comment.