PHP code example of corpus / loggers

1. Go to this page and download the library: Download corpus/loggers library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

corpus / loggers example snippets




use Corpus\Loggers\LoggerWithContext;
use Corpus\Loggers\LogLevelFilter;
use Corpus\Loggers\MemoryLogger;
use Corpus\Loggers\MultiLogger;
use Corpus\Loggers\StreamResourceLogger;
use Psr\Log\LogLevel;

xt([ 'Logger' => 'Number 1' ]),
		[ Psr\Log\LogLevel::INFO ]
	),
	new LogLevelFilter(
		(new LoggerWithContext($cliLogger))->withContext([ 'Logger' => 'Number 2' ]),
		[ Psr\Log\LogLevel::INFO, LogLevel::DEBUG ]
	),
	new LogLevelFilter(
		(new LoggerWithContext($cliLogger))->withContext([ 'Logger' => 'Number 3' ]),
		[ Psr\Log\LogLevel::INFO, LogLevel::DEBUG ],
		true // reverse filter - only log levels NOT in the array
	)
);

$logger->info('Hello World', [ 'hello' => 'world' ]);
$logger->debug('How are you?', [ 'foo' => 'bar' ]);
$logger->error('I am fine', [ 'bar' => 'baz', 'baz' => 'qux' ]);

echo "\n--- dumping memory logger ---\n\n";

var_export($memoryLogger->getLogs());


function withContext(array $context) : self

function withAddedContext(array $context) : self

function withAdditionalLoggers(\Psr\Log\LoggerInterface ...$loggers) : self

function withAdditionalLoggers(\Psr\Log\LoggerInterface ...$loggers) : self

function withContext(array $context) : self

function withAddedContext(array $context) : self

function __construct(\Psr\Log\LoggerInterface $logger [, int $verbosity = 0 [, ?callable $verbosityFromLevelCallback = null]])

function withVerbosity(int $verbosity) : self

function withVerbosityFromLevelCallback(callable $verbosityFromLevelCallback) : self

function __construct(\Psr\Log\LoggerInterface $logger [, array $context = []])

function withContext(array $context) : self

function withAddedContext(array $context) : self

function __construct(\Psr\Log\LoggerInterface $logger, array $levels [, bool $exclude = false])

function __construct([ ?\Psr\Log\LoggerInterface $defaultLogger = null [, ?\Psr\Log\LoggerInterface $emergencyLogger = null [, ?\Psr\Log\LoggerInterface $alertLogger = null [, ?\Psr\Log\LoggerInterface $criticalLogger = null [, ?\Psr\Log\LoggerInterface $errorLogger = null [, ?\Psr\Log\LoggerInterface $warningLogger = null [, ?\Psr\Log\LoggerInterface $noticeLogger = null [, ?\Psr\Log\LoggerInterface $infoLogger = null [, ?\Psr\Log\LoggerInterface $debugLogger = null]]]]]]]]])

function withEmergencyLogger(\Psr\Log\LoggerInterface $logger) : self

function withAlertLogger(\Psr\Log\LoggerInterface $logger) : self

function withCriticalLogger(\Psr\Log\LoggerInterface $logger) : self

function withErrorLogger(\Psr\Log\LoggerInterface $logger) : self

function withWarningLogger(\Psr\Log\LoggerInterface $logger) : self

function withNoticeLogger(\Psr\Log\LoggerInterface $logger) : self

function withInfoLogger(\Psr\Log\LoggerInterface $logger) : self

function withDebugLogger(\Psr\Log\LoggerInterface $logger) : self


namespace Corpus\Loggers;

class MemoryLogger {
	public const KEY_LEVEL = 'level';
	public const KEY_MESSAGE = 'message';
	public const KEY_CONTEXT = 'context';
}

function getLogs() : array

function clearLogs() : void

function __construct(\Psr\Log\LoggerInterface ...$loggers)

function withAdditionalLoggers(\Psr\Log\LoggerInterface ...$loggers) : self

function __construct($resource)