Skip to content

Commit

Permalink
Add log service provider, defers loading of logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
garygreen committed Sep 21, 2016
1 parent abc5bb6 commit 02f41e1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
3 changes: 3 additions & 0 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Http\Request;
use Illuminate\Container\Container;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Log\LogServiceProvider;
use Illuminate\Support\ServiceProvider;
use Illuminate\Events\EventServiceProvider;
use Illuminate\Routing\RoutingServiceProvider;
Expand Down Expand Up @@ -185,6 +186,8 @@ protected function registerBaseServiceProviders()
$this->register(new EventServiceProvider($this));

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

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

/**
Expand Down
1 change: 0 additions & 1 deletion src/Illuminate/Foundation/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class Kernel implements KernelContract
protected $bootstrappers = [
'Illuminate\Foundation\Bootstrap\DetectEnvironment',
'Illuminate\Foundation\Bootstrap\LoadConfiguration',
'Illuminate\Foundation\Bootstrap\ConfigureLogging',
'Illuminate\Foundation\Bootstrap\HandleExceptions',
'Illuminate\Foundation\Bootstrap\RegisterFacades',
'Illuminate\Foundation\Bootstrap\SetRequestForConsole',
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Console/Optimize/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
$basePath.'/vendor/symfony/http-kernel/TerminableInterface.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Foundation/Application.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Foundation/EnvironmentDetector.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/ConfigureLogging.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/RegisterFacades.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/RegisterProviders.php',
Expand Down Expand Up @@ -73,6 +72,7 @@
$basePath.'/vendor/symfony/http-foundation/AcceptHeaderItem.php',
$basePath.'/vendor/symfony/http-foundation/AcceptHeader.php',
$basePath.'/vendor/symfony/debug/ExceptionHandler.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Log/LogServiceProvider.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/ServiceProvider.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/AggregateServiceProvider.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php',
Expand Down
1 change: 0 additions & 1 deletion src/Illuminate/Foundation/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Kernel implements KernelContract
protected $bootstrappers = [
'Illuminate\Foundation\Bootstrap\DetectEnvironment',
'Illuminate\Foundation\Bootstrap\LoadConfiguration',
'Illuminate\Foundation\Bootstrap\ConfigureLogging',
'Illuminate\Foundation\Bootstrap\HandleExceptions',
'Illuminate\Foundation\Bootstrap\RegisterFacades',
'Illuminate\Foundation\Bootstrap\RegisterProviders',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,45 @@
<?php

namespace Illuminate\Foundation\Bootstrap;
namespace Illuminate\Log;

use Illuminate\Log\Writer;
use Monolog\Logger as Monolog;
use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Foundation\Application;

class ConfigureLogging
class LogServiceProvider extends ServiceProvider
{
/**
* Bootstrap the given application.
* Register the service provider.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @return void
*/
public function bootstrap(Application $app)
public function register()
{
$log = $this->registerLogger($app);

// If a custom Monolog configurator has been registered for the application
// we will call that, passing Monolog along. Otherwise, we will grab the
// the configurations for the log system and use it for configuration.
if ($app->hasMonologConfigurator()) {
call_user_func(
$app->getMonologConfigurator(), $log->getMonolog()
);
} else {
$this->configureHandlers($app, $log);
}
$this->app->singleton('log', function ($app) {
return $this->createLogger($app);
});
}

/**
* Register the logger instance in the container.
* Create the logger.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @param \Illuminate\Contracts\Foundation\Application $app
* @return \Illuminate\Log\Writer
*/
protected function registerLogger(Application $app)
public function createLogger($app)
{
$app->instance('log', $log = new Writer(
new Monolog($app->environment()), $app['events'])
$log = new Writer(
new Monolog($app->environment()), $app['events']
);

if ($app->hasMonologConfigurator()) {
call_user_func(
$app->getMonologConfigurator(), $log->getMonolog()
);
} else {
$this->configureHandlers($app, $log);
}

return $log;
}

Expand Down

0 comments on commit 02f41e1

Please sign in to comment.