Skip to content

Commit

Permalink
refactor: make log_level parameter definition optional
Browse files Browse the repository at this point in the history
  • Loading branch information
hschoenenberger committed Oct 23, 2024
1 parent 3bc5e5e commit 8a0199e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/accounts-qc-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
- name: Scoped dependencies
run: make php-scoper

- name: Platform build
- name: Start container & install module
run: |
make platform-${{ matrix.presta-versions }}
Expand Down
4 changes: 2 additions & 2 deletions config/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ services:
class: PrestaShop\Module\PsAccounts\Vendor\Monolog\Logger
public: true
factory: [ 'PrestaShop\Module\PsAccounts\Log\Logger', 'create' ]
arguments:
- '%ps_accounts.log_level%'
# arguments:
# - '%ps_accounts.log_level%'

PrestaShop\Module\PsAccounts\Provider\OAuth2\ShopProvider:
class: PrestaShop\Module\PsAccounts\Provider\OAuth2\ShopProvider
Expand Down
21 changes: 20 additions & 1 deletion src/Log/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

use PrestaShop\Module\PsAccounts\Vendor\Monolog\Handler\RotatingFileHandler;
use PrestaShop\Module\PsAccounts\Vendor\Monolog\Logger as MonoLogger;
use PrestaShop\Module\PsAccounts\Vendor\Psr\Log\InvalidArgumentException;
use Ps_accounts;

class Logger
Expand All @@ -43,9 +44,10 @@ class Logger
*/
public static function create($logLevel = null)
{
$logLevel = self::getLevel($logLevel);
$monologLevel = MonoLogger::toMonologLevel($logLevel);
if (!is_int($monologLevel)) {
$monologLevel = Logger::DEBUG;
$monologLevel = MonoLogger::DEBUG;
}

$path = _PS_ROOT_DIR_ . '/var/logs/ps_accounts';
Expand Down Expand Up @@ -73,4 +75,21 @@ public static function getInstance()

return $psAccounts->getLogger();
}

/**
* @param $logLevel
* @return mixed
*/
public static function getLevel($logLevel)
{
if ($logLevel === null) {
try {
/** @var Ps_accounts $psAccounts */
$psAccounts = \Module::getInstanceByName('ps_accounts');
$logLevel = $psAccounts->getParameter('ps_accounts.log_level');
} catch (InvalidArgumentException $e) {
}
}
return $logLevel;
}
}

0 comments on commit 8a0199e

Please sign in to comment.