Skip to content

Commit

Permalink
Merge pull request #7341 from Vitaliy-1/i7340_log_service
Browse files Browse the repository at this point in the history
#7340 Register Log Service and configure mail logger
  • Loading branch information
Vitaliy-1 committed Oct 12, 2021
2 parents 34efa3e + 9818908 commit 1a94bff
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion classes/core/PKPContainer.inc.php
Expand Up @@ -17,8 +17,10 @@

use APP\core\AppServiceProvider;

use Exception;
use Illuminate\Config\Repository;
use Illuminate\Container\Container;
use Illuminate\Log\LogServiceProvider;
use Illuminate\Support\Facades\Facade;
use PKP\config\Config;
use Throwable;
Expand Down Expand Up @@ -87,6 +89,7 @@ public function registerConfiguredProviders()
$this->loadConfiguration();

$this->register(new PKPEventServiceProvider($this));
$this->register(new LogServiceProvider($this));
$this->register(new \Illuminate\Database\DatabaseServiceProvider($this));
$this->register(new \Illuminate\Bus\BusServiceProvider($this));
$this->register(new \Illuminate\Queue\QueueServiceProvider($this));
Expand Down Expand Up @@ -121,6 +124,7 @@ public function registerCoreContainerAliases()
'queue' => [\Illuminate\Queue\QueueManager::class, \Illuminate\Contracts\Queue\Factory::class, \Illuminate\Contracts\Queue\Monitor::class],
'queue.connection' => [\Illuminate\Contracts\Queue\Queue::class],
'queue.failer' => [\Illuminate\Queue\Failed\FailedJobProviderInterface::class],
'log' => [\Illuminate\Log\LogManager::class, \Psr\Log\LoggerInterface::class],
] as $key => $aliases) {
foreach ($aliases as $alias) {
$this->alias($key, $alias);
Expand Down Expand Up @@ -167,8 +171,13 @@ protected function loadConfiguration()
'retry_after' => 90,
];

// Logging
$items['logging']['channels']['errorlog'] = [
'driver' => 'errorlog',
'level' => 'debug',
];

// Mail Service
$items['mail']['default'] = Config::getVar('email', 'smtp') ? 'smtp' : 'sendmail';
$items['mail']['mailers']['sendmail'] = [
'transport' => 'sendmail',
'path' => Config::getVar('email', 'sendmail_path'),
Expand All @@ -183,6 +192,12 @@ protected function loadConfiguration()
'timeout' => null,
'auth_mode' => null,
];
$items['mail']['mailers']['log'] = [
'transport' => 'log',
'channel' => 'errorlog',
];

$items['mail']['default'] = static::getDefaultMailer();

$this->instance('config', new Repository($items)); // create instance and bind to use globally
}
Expand All @@ -204,6 +219,21 @@ public function path($path = '')
{
return $this->basePath($path);
}

/**
* Retrieves default mailer driver depending on the configuration
* @throws Exception
*/
protected static function getDefaultMailer(): string
{
$default = Config::getVar('email', 'default');

if (!$default) {
throw new Exception('Mailer driver isn\'t specified in the application\'s config');
}

return $default;
}
}

if (!PKP_STRICT_MODE) {
Expand Down

0 comments on commit 1a94bff

Please sign in to comment.