This commit is contained in:
Paolo A
2024-08-13 13:44:16 +00:00
parent 1bbb23088d
commit e796d76612
4001 changed files with 30101 additions and 40075 deletions

View File

@@ -7,6 +7,7 @@ use Illuminate\Support\Str;
use InvalidArgumentException;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\ErrorLogHandler;
use Monolog\Handler\FingersCrossedHandler;
use Monolog\Handler\FormattableHandlerInterface;
use Monolog\Handler\HandlerInterface;
use Monolog\Handler\RotatingFileHandler;
@@ -61,6 +62,19 @@ class LogManager implements LoggerInterface
$this->app = $app;
}
/**
* Build an on-demand log channel.
*
* @param array $config
* @return \Psr\Log\LoggerInterface
*/
public function build(array $config)
{
unset($this->channels['ondemand']);
return $this->get('ondemand', $config);
}
/**
* Create a new, on-demand aggregate logger instance.
*
@@ -95,27 +109,20 @@ class LogManager implements LoggerInterface
*/
public function driver($driver = null)
{
return $this->get($driver ?? $this->getDefaultDriver());
}
/**
* @return array
*/
public function getChannels()
{
return $this->channels;
return $this->get($this->parseDriver($driver));
}
/**
* Attempt to get the log from the local cache.
*
* @param string $name
* @param array|null $config
* @return \Psr\Log\LoggerInterface
*/
protected function get($name)
protected function get($name, ?array $config = null)
{
try {
return $this->channels[$name] ?? with($this->resolve($name), function ($logger) use ($name) {
return $this->channels[$name] ?? with($this->resolve($name, $config), function ($logger) use ($name) {
return $this->channels[$name] = $this->tap($name, new Logger($logger, $this->app['events']));
});
} catch (Throwable $e) {
@@ -180,13 +187,14 @@ class LogManager implements LoggerInterface
* Resolve the given log instance by name.
*
* @param string $name
* @param array|null $config
* @return \Psr\Log\LoggerInterface
*
* @throws \InvalidArgumentException
*/
protected function resolve($name)
protected function resolve($name, ?array $config = null)
{
$config = $this->configurationFor($name);
$config = $config ?? $this->configurationFor($name);
if (is_null($config)) {
throw new InvalidArgumentException("Log [{$name}] is not defined.");
@@ -237,15 +245,27 @@ class LogManager implements LoggerInterface
*/
protected function createStackDriver(array $config)
{
if (is_string($config['channels'])) {
$config['channels'] = explode(',', $config['channels']);
}
$handlers = collect($config['channels'])->flatMap(function ($channel) {
return $this->channel($channel)->getHandlers();
return $channel instanceof LoggerInterface
? $channel->getHandlers()
: $this->channel($channel)->getHandlers();
})->all();
$processors = collect($config['channels'])->flatMap(function ($channel) {
return $channel instanceof LoggerInterface
? $channel->getProcessors()
: $this->channel($channel)->getProcessors();
})->all();
if ($config['ignore_exceptions'] ?? false) {
$handlers = [new WhatFailureGroupHandler($handlers)];
}
return new Monolog($this->parseChannel($config), $handlers);
return new Monolog($this->parseChannel($config), $handlers, $processors);
}
/**
@@ -389,17 +409,17 @@ class LogManager implements LoggerInterface
*/
protected function prepareHandler(HandlerInterface $handler, array $config = [])
{
$isHandlerFormattable = false;
if (Monolog::API === 1) {
$isHandlerFormattable = true;
} elseif (Monolog::API === 2 && $handler instanceof FormattableHandlerInterface) {
$isHandlerFormattable = true;
if (isset($config['action_level'])) {
$handler = new FingersCrossedHandler($handler, $this->actionLevel($config));
}
if ($isHandlerFormattable && ! isset($config['formatter'])) {
if (Monolog::API !== 1 && (Monolog::API !== 2 || ! $handler instanceof FormattableHandlerInterface)) {
return $handler;
}
if (! isset($config['formatter'])) {
$handler->setFormatter($this->formatter());
} elseif ($isHandlerFormattable && $config['formatter'] !== 'default') {
} elseif ($config['formatter'] !== 'default') {
$handler->setFormatter($this->app->make($config['formatter'], $config['formatter_with'] ?? []));
}
@@ -442,7 +462,7 @@ class LogManager implements LoggerInterface
/**
* Get the default log driver name.
*
* @return string
* @return string|null
*/
public function getDefaultDriver()
{
@@ -482,13 +502,40 @@ class LogManager implements LoggerInterface
*/
public function forgetChannel($driver = null)
{
$driver = $driver ?? $this->getDefaultDriver();
$driver = $this->parseDriver($driver);
if (isset($this->channels[$driver])) {
unset($this->channels[$driver]);
}
}
/**
* Parse the driver name.
*
* @param string|null $driver
* @return string|null
*/
protected function parseDriver($driver)
{
$driver = $driver ?? $this->getDefaultDriver();
if ($this->app->runningUnitTests()) {
$driver = $driver ?? 'null';
}
return $driver;
}
/**
* Get all of the resolved log channels.
*
* @return array
*/
public function getChannels()
{
return $this->channels;
}
/**
* System is unusable.
*

37
vendor/laravel/framework/src/Illuminate/Log/Logger.php vendored Normal file → Executable file
View File

@@ -26,6 +26,13 @@ class Logger implements LoggerInterface
*/
protected $dispatcher;
/**
* Any context to be added to logs.
*
* @var array
*/
protected $context = [];
/**
* Create a new log writer instance.
*
@@ -171,11 +178,39 @@ class Logger implements LoggerInterface
*/
protected function writeLog($level, $message, $context)
{
$this->logger->{$level}($message = $this->formatMessage($message), $context);
$this->logger->{$level}(
$message = $this->formatMessage($message),
$context = array_merge($this->context, $context)
);
$this->fireLogEvent($level, $message, $context);
}
/**
* Add context to all future logs.
*
* @param array $context
* @return $this
*/
public function withContext(array $context = [])
{
$this->context = array_merge($this->context, $context);
return $this;
}
/**
* Flush the existing context array.
*
* @return $this
*/
public function withoutContext()
{
$this->context = [];
return $this;
}
/**
* Register a new callback handler for when a log event is triggered.
*

View File

@@ -49,6 +49,23 @@ trait ParsesLogConfiguration
throw new InvalidArgumentException('Invalid log level.');
}
/**
* Parse the action level from the given configuration.
*
* @param array $config
* @return int
*/
protected function actionLevel(array $config)
{
$level = $config['action_level'] ?? 'debug';
if (isset($this->levels[$level])) {
return $this->levels[$level];
}
throw new InvalidArgumentException('Invalid log action level.');
}
/**
* Extract the log channel from the given configuration.
*

8
vendor/laravel/framework/src/Illuminate/Log/composer.json vendored Normal file → Executable file
View File

@@ -14,9 +14,9 @@
}
],
"require": {
"php": "^7.2.5|^8.0",
"illuminate/contracts": "^7.0",
"illuminate/support": "^7.0",
"php": "^7.3|^8.0",
"illuminate/contracts": "^8.0",
"illuminate/support": "^8.0",
"monolog/monolog": "^2.0"
},
"autoload": {
@@ -26,7 +26,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "7.x-dev"
"dev-master": "8.x-dev"
}
},
"config": {