Skip to content

Commit

Permalink
add PsrLogger::new() static method for a new instance creation
Browse files Browse the repository at this point in the history
  • Loading branch information
klimov-paul committed Jul 20, 2023
1 parent 02f5ef6 commit e96b26e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Yii1 PSR Log extension
-----------------------

- Enh: Added ability for global log context setup at `PsrLogger` (klimov-paul)
- Enh: Added `PsrLogger::new()` static method for a new instance creation (klimov-paul)


1.0.0, July 19, 2023
Expand Down
14 changes: 14 additions & 0 deletions src/AbstractPsrLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,18 @@ protected function logGlobalContextResolutionError(Throwable $exception): void

$this->getYiiLogger()->log($errorMessage, CLogger::LEVEL_ERROR, 'system.log');
}

/**
* Creates new self instance.
* This method can be useful when writing chain methods calls.
*
* @since 1.0.1
*
* @param mixed ...$args constructor arguments.
* @return static new self instance.
*/
public static function new(...$args): self
{
return new static(...$args);
}
}
5 changes: 3 additions & 2 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,11 @@ protected function formatLogContext(array $logContext, int $nestedLevel = 0): ar
* Creates new self instance.
* This method can be useful when writing chain methods calls.
*
* @param mixed ...$args constructor arguments.
* @return static new self instance.
*/
public static function new(): self
public static function new(...$args): self
{
return new static();
return new static(...$args);
}
}

0 comments on commit e96b26e

Please sign in to comment.