friendica-addons/monolog/src/Monolog/IntrospectionProcessor.php

63 lines
1.9 KiB
PHP
Raw Normal View History

2022-10-17 21:25:03 +02:00
<?php
/**
2023-01-09 15:19:09 +01:00
* @copyright Copyright (C) 2010-2023, the Friendica project
2022-10-17 21:25:03 +02:00
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
2023-01-18 00:17:49 +01:00
namespace Friendica\Addon\monolog\src\Monolog;
2022-10-17 21:25:03 +02:00
use Friendica\Core\Logger\Util\Introspection;
use Monolog\Logger;
use Monolog\Processor\ProcessorInterface;
/**
* Injects line/file//function where the log message came from
*/
class IntrospectionProcessor implements ProcessorInterface
{
private $level;
private $introspection;
/**
* @param Introspection $introspection Holds the Introspection of the current call
* @param string|int $level The minimum logging level at which this Processor will be triggered
*/
public function __construct(Introspection $introspection, $level = Logger::DEBUG)
{
$this->level = Logger::toMonologLevel($level);
2023-01-18 00:17:49 +01:00
$introspection->addClasses(['Monolog\\', IntrospectionProcessor::class]);
2022-10-17 21:25:03 +02:00
$this->introspection = $introspection;
}
2023-01-18 00:17:49 +01:00
public function __invoke(array $record): array
2022-10-17 21:25:03 +02:00
{
// return if the level is not high enough
2023-01-18 00:17:49 +01:00
if ($record['level'] < $this->level) {
2022-10-17 21:25:03 +02:00
return $record;
}
// we should have the call source now
2023-01-18 00:17:49 +01:00
$record['extra'] = array_merge(
$record['extra'],
2022-10-17 21:25:03 +02:00
$this->introspection->getRecord()
);
return $record;
}
}