<commit_before><?php

namespace swestcott\MonologExtension\Context\Initializer;

use Behat\Behat\Context\Initializer\InitializerInterface,
    Behat\Behat\Context\ContextInterface;

class MonologInitializer implements InitializerInterface
{
    private $container;

    public function __construct($container)
    {
        $this->container = $container;
    }

    public function initialize(ContextInterface $context)
    {
        $loggerName = $this->container->getParameter('behat.monolog.logger_name');
        $class = $this->container->getParameter('behat.monolog.service.class');

        $def = $this->container->getDefinition('behat.monolog.logger');
        $def->addArgument(get_class($context));
        $logger = $this->container->get('behat.monolog.logger');

        $handlers = $this->container->getParameter('behat.monolog.handlers');

        // Register each configured handler with logger
        foreach($handlers as $name) {
            $handler = $this->container->get($name);
            $logger->pushHandler($handler);
        }

        $context->$loggerName = $logger;
    }

    public function supports(ContextInterface $context)
    {
        return get_class($context) === $this->container->getParameter('behat.context.class');
    }
}<commit_msg>Add support for subcontexts too<commit_after><?php

namespace swestcott\MonologExtension\Context\Initializer;

use Behat\Behat\Context\Initializer\InitializerInterface,
    Behat\Behat\Context\ContextInterface;

class MonologInitializer implements InitializerInterface
{
    private $container;

    public function __construct($container)
    {
        $this->container = $container;
    }

    public function initialize(ContextInterface $context)
    {
        $loggerName = $this->container->getParameter('behat.monolog.logger_name');
        $class = $this->container->getParameter('behat.monolog.service.class');

        $def = $this->container->getDefinition('behat.monolog.logger');
        $def->addArgument(get_class($context));
        $logger = $this->container->get('behat.monolog.logger');

        $handlers = $this->container->getParameter('behat.monolog.handlers');

        // Register each configured handler with logger
        foreach($handlers as $name) {
            $handler = $this->container->get($name);
            $logger->pushHandler($handler);
        }

        $context->$loggerName = $logger;
    }

    public function supports(ContextInterface $context)
    {
        return ($context instanceof BehatContext);
    }
}
{'fraction_non_alphanumeric': 0.13175542406311638, 'fraction_numerical': 0.0, 'mean_word_length': 3.379965457685665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5662268', 'n_tokens_mistral': 696, 'n_tokens_neox': 682, 'n_words': 111}