Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat logging #50

Merged
merged 5 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ jobs:
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-${{ matrix.php }}-
- name: Install dependencies
run: composer update $DEFAULT_COMPOSER_FLAGS
- name: Install logging proxy
if: ${{ matrix.php != '7.4' }}
run: composer require "yiisoft/yii2-psr-log-source"
- name: Run unit tests with coverage
run: vendor/bin/phpunit --coverage-text
- name: Static analysis (Psalm)
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Yii Framework 2 Symfony mailer extension Change Log
================================================

3.0.1 under development
3.1.0 under development
-----------------------

- Enh #45: Added option to create transport from Dsn object (Swanty)
- Enh #50: Forward transport logs to the Yii Logger (sammousa)


3.0.0 December 05, 2022
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
"captainhook/captainhook": "^5.10",
"captainhook/plugin-composer": "^5.3"
},
"suggest": {
"yiisoft/yii2-psr-log-source": "Allows routing transport logs to your Yii2 logger"
},
"repositories": [
{
"type": "composer",
Expand Down
10 changes: 9 additions & 1 deletion src/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace yii\symfonymailer;

use Psr\Log\LoggerInterface;
use Symfony\Component\Mailer\Mailer as SymfonyMailer;
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mailer\Transport\Dsn;
Expand All @@ -16,6 +17,8 @@
use yii\base\InvalidArgumentException;
use yii\base\InvalidConfigException;
use yii\mail\BaseMailer;
use yii\psr\DynamicLogger;
use yii\psr\Logger;

/**
* @psalm-suppress PropertyNotSetInConstructor
Expand Down Expand Up @@ -93,7 +96,12 @@ private function getTransportFactory(): Transport
if (isset($this->transportFactory)) {
return $this->transportFactory;
}
$defaultFactories = Transport::getDefaultFactories();
/** @var LoggerInterface|null $logger */
$logger = class_exists(DynamicLogger::class) ? new DynamicLogger() : null;
/**
* @psalm-suppress TooManyArguments On PHP 7.4 symfony/mailer 5.4 is uses which uses func_get_args instead of real args
*/
$defaultFactories = Transport::getDefaultFactories(null, null, $logger);
/** @psalm-suppress InvalidArgument Symfony's type annotation is wrong */
return new Transport($defaultFactories);
}
Expand Down