php-etl/log-plugin

用于添加日志支持的插件

v0.3.1 2023-04-21 07:52 UTC

This package is auto-updated.

Last update: 2024-09-21 10:51:09 UTC


README

目标

此软件包旨在将日志功能集成到Pipeline堆栈中。

原则

本库中的工具将使用来自nikic/php-parser的中间抽象语法树生成可执行PHP源代码。这种中间格式有助于您将此库生成的代码与其他中间件软件包结合使用。

配置格式

禁用日志记录

logger:
    null: ~

将日志记录到STDERR

logger:
    stderr: ~

用法

此库将在管道中为您构建日志功能。

您可以使用以下PHP脚本来测试和打印配置结果。

<?php

require __DIR__ . '/../vendor/autoload.php';

use Kiboko\Plugin\Log;
use PhpParser\Node;
use PhpParser\PrettyPrinter;
use Symfony\Component\Console;
use Symfony\Component\Yaml;

$input = new Console\Input\ArgvInput($argv);
$output = new Console\Output\ConsoleOutput();

class DefaultCommand extends Console\Command\Command
{
    protected static $defaultName = 'test';

    protected function configure()
    {
        $this->addArgument('file', Console\Input\InputArgument::REQUIRED);
    }

    protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
    {
        $factory = new Log\Service();

        $style = new Console\Style\SymfonyStyle(
            $input,
            $output,
        );

        $config = Yaml\Yaml::parse(input: file_get_contents($input->getArgument('file')));

        $style->section('Validation');
        $style->writeln($factory->validate($config) ? '<info>ok</info>' : '<error>failed</error>');
        $style->section('Normalized Config');
        $style->writeln(\json_encode($config = $factory->normalize($config), JSON_PRETTY_PRINT));
        $style->section('Generated code');
        $style->writeln((new PrettyPrinter\Standard())->prettyPrintFile([
            new Node\Stmt\Return_($factory->compile($config)->getNode()),
        ]));

        return 0;
    }
}

(new Console\Application())
    ->add(new DefaultCommand())
    ->run($input, $output)
;

另请参阅