mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2025-07-09 18:08:49 +00:00
Fix Monolog
- Use new hook-loading
This commit is contained in:
parent
f328dc2b83
commit
745f9c1e5f
139 changed files with 2906 additions and 3083 deletions
|
@ -5,62 +5,3 @@
|
|||
* Version: 1.0
|
||||
* Author: Philipp Holzer
|
||||
*/
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Addon\monolog\src\IntrospectionProcessor;
|
||||
use Friendica\DI;
|
||||
use Psr\Log\LogLevel;
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
function monolog_install()
|
||||
{
|
||||
Hook::register('logger_instance' , __FILE__, 'monolog_instance');
|
||||
}
|
||||
|
||||
function monolog_uninstall()
|
||||
{
|
||||
Hook::unregister('logger_instance', __FILE__, 'monolog_instance');
|
||||
}
|
||||
|
||||
function monolog_instance(array &$data)
|
||||
{
|
||||
if ($data['name'] !== 'monolog') {
|
||||
return;
|
||||
}
|
||||
|
||||
$loggerTimeZone = new \DateTimeZone('UTC');
|
||||
|
||||
$logger = new Monolog\Logger($data['channel']);
|
||||
$logger->setTimezone($loggerTimeZone);
|
||||
$logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor());
|
||||
$logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor());
|
||||
$logger->pushProcessor(new Monolog\Processor\UidProcessor());
|
||||
$logger->pushProcessor(new IntrospectionProcessor($data['introspection'], LogLevel::DEBUG));
|
||||
|
||||
$stream = DI::config()->get('system', 'logfile');
|
||||
|
||||
// just add a stream in case it's either writable or not file
|
||||
if (!is_file($stream) || is_writable($stream)) {
|
||||
try {
|
||||
$loglevel = Monolog\Logger::toMonologLevel($data['loglevel']);
|
||||
|
||||
// fallback to notice if an invalid loglevel is set
|
||||
if (!is_int($loglevel)) {
|
||||
$loglevel = LogLevel::NOTICE;
|
||||
}
|
||||
|
||||
$fileHandler = new Monolog\Handler\StreamHandler($stream, $loglevel);
|
||||
|
||||
$formatter = new Monolog\Formatter\LineFormatter("%datetime% %channel% [%level_name%]: %message% %context% %extra%\n");
|
||||
$fileHandler->setFormatter($formatter);
|
||||
|
||||
$logger->pushHandler($fileHandler);
|
||||
} catch (\Throwable $e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$data['storage'] = $logger;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue