php-etl/log-plugin

Plugins for adding Logging support

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

This package is auto-updated.

Last update: 2024-04-21 09:55:45 UTC


README

Goal

This package aims at integrating logging capabilities in the Pipeline stack.

Principles

The tools in this library will produce executable PHP sources, using an intermediate Abstract Syntax Tree from nikic/php-parser. This intermediate format helps you combine the code produced by this library with other packages from Middleware.

Configuration format

Disabling logging

logger:
    null: ~

Logging to STDERR

logger:
    stderr: ~

Usage

This library will build for you logging capabilities inside a pipeline.

You can use the following PHP script to test and print the result of your configuration.

<?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)
;

See also