Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor/
composer.lock
*.cache
/.phpstan-cache
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ function withContext(array $context) : self
Returns a new instance with the given context
replacing the existing context.

##### Parameters:

- ***array*** `$context` - The context to add to all log messages.

---

#### Method: LoggerWithContextInterface->withAddedContext
Expand All @@ -127,6 +131,10 @@ function withAddedContext(array $context) : self
Returns a new instance with the given context
added to the existing context.

##### Parameters:

- ***array*** `$context` - The context to add to all log messages.

### Class: Corpus\Loggers\Interfaces\MultiLoggerInterface

#### Method: MultiLoggerInterface->withAdditionalLoggers
Expand Down Expand Up @@ -160,6 +168,10 @@ function withContext(array $context) : self
Returns a new instance with the given context
replacing the existing context.

##### Parameters:

- ***array*** `$context` - The context to add to all log messages.

---

#### Method: WithContextInterface->withAddedContext
Expand All @@ -171,6 +183,10 @@ function withAddedContext(array $context) : self
Returns a new instance with the given context
added to the existing context.

##### Parameters:

- ***array*** `$context` - The context to add to all log messages.

### Class: Corpus\Loggers\LoggerVerbosityFilter

LoggerVerbosityFilter mutes log messages based on a given integer verbosity level.
Expand Down Expand Up @@ -240,6 +256,7 @@ The given context will be added to all log messages.

- ***\Psr\Log\LoggerInterface*** `$logger` - The logger to delegate to.
- ***array*** `$context` - The context to add to all log messages.
- ***array*** `$context`

---

Expand All @@ -252,6 +269,10 @@ function withContext(array $context) : self
Returns a new instance with the given context
replacing the existing context.

##### Parameters:

- ***array*** `$context` - The context to add to all log messages.

---

#### Method: LoggerWithContext->withAddedContext
Expand All @@ -263,6 +284,10 @@ function withAddedContext(array $context) : self
Returns a new instance with the given context
added to the existing context.

##### Parameters:

- ***array*** `$context` - The context to add to all log messages.

### Class: Corpus\Loggers\LogLevelFilter

LogLevelFilter is a PSR Logger that filters logs based on the log level.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"corpus/coding-standard": "^0.8.0",
"friendsofphp/php-cs-fixer": "^3.65",
"rawr/phpunit-data-provider": "^3.3",
"corpus/recursive-require": "^1.2"
"corpus/recursive-require": "^1.2",
"phpstan/phpstan": "^2.1"
},
"autoload": {
"psr-4": {
Expand Down
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
level: 8
tmpDir: .phpstan-cache
paths:
- src
phpVersion: 70400
treatPhpDocTypesAsCertain: false
4 changes: 4 additions & 0 deletions src/Interfaces/WithContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ interface WithContextInterface {
/**
* Returns a new instance with the given context
* replacing the existing context.
*
* @param mixed[] $context The context to add to all log messages.
*/
public function withContext( array $context ) : self;

/**
* Returns a new instance with the given context
* added to the existing context.
*
* @param mixed[] $context The context to add to all log messages.
*/
public function withAddedContext( array $context ) : self;

Expand Down
2 changes: 2 additions & 0 deletions src/LoggerWithContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class LoggerWithContext implements LoggerWithContextInterface {

use LoggerTrait;

/** @var mixed[] */
private array $context;
private LoggerInterface $logger;

Expand All @@ -27,6 +28,7 @@ class LoggerWithContext implements LoggerWithContextInterface {
*
* @param LoggerInterface $logger The logger to delegate to.
* @param array $context The context to add to all log messages.
* @param mixed[] $context
*/
public function __construct( LoggerInterface $logger, array $context = [] ) {
$this->logger = $logger;
Expand Down
3 changes: 3 additions & 0 deletions src/MemoryLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class MemoryLogger implements LoggerInterface {
public const KEY_MESSAGE = 'message';
public const KEY_CONTEXT = 'context';

/** @var array<array{level:mixed,message:string,context:mixed[]}> */
private array $logs = [];

/**
Expand All @@ -37,6 +38,7 @@ public function log( $level, $message, array $context = [] ) : void {
* - MemoryLogger::KEY_MESSAGE : The log message
* - MemoryLogger::KEY_CONTEXT : The log context
*
* @phpstan-return array<array{level:mixed,message:string,context:mixed[]}>
* @return array[]
*/
public function getLogs() : array {
Expand All @@ -58,6 +60,7 @@ public function clearLogs() : void {
* @param mixed $level The log level
* @param string $message The log message
* @param mixed[] $context The log context
* @return array{level:mixed,message:string,context:mixed[]}
* @mddoc-ignore
*/
public static function makeLogRecord( $level, $message, array $context = [] ) : array {
Expand Down
2 changes: 1 addition & 1 deletion src/StreamResourceLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function log( $level, $message, array $context = [] ) : void {
$this->stream,
"%s %9s: %s\n",
date('c'),
$level,
(string)$level,
is_string($message) ? $message : var_export($message, true)
);

Expand Down
Loading