<commit_before><?php

namespace Kunstmaan\AdminBundle\Modules;

use Doctrine\ORM\ORMException;

use Monolog\Handler\NullHandler;

use Symfony\Component\DependencyInjection\Container;

use Doctrine\ORM\EntityManager;

use Kunstmaan\AdminBundle\Entity\ErrorLogItem;
use Monolog\Logger;
use Monolog\Handler\AbstractProcessingHandler;

class LogHandler extends AbstractProcessingHandler
{
    private $initialized = false;
    private $container;

    public function __construct(Container &$container, $level = Logger::ERROR, $bubble = true){
        $this->container = $container;
        parent::__construct($level, $bubble);
    }

    protected function write(array $record){
        if (!$this->initialized) {
            $this->initialize();
        }

        $this->container->get('monolog.logger.doctrine')->pushHandler(new NullHandler());
        
	    try{
	    	$user = $this->container->get('security.context')->getToken()->getUser();
	    	
	    	$logitem = new ErrorLogItem();
	    	if($user){
	    		$logitem->setUser($user);
	    	}
	    	$logitem->setStatus("error");
	        $logitem->setChannel($record['channel']);
	        $logitem->setLevel($record['level']);
	        $logitem->setMessage($record['formatted']);
		    $em = $this->container->get('doctrine')->getEntityManager();
			$em->persist($logitem);
			$em->flush();
	        /*$conn = $this->container->get('doctrine')->getEntityManager()->getConnection()->getWrappedConnection();
	        $prep = $conn->prepare('INSERT INTO errorlogitem (channel, level, message) VALUES (?, ?, ?)');
	        $prep->bindParam(1, $record['channel']);
	        $prep->bindParam(2, $record['level']);
	        $prep->bindParam(3, $record['formatted']);
	        $prep->execute();*/
	     }catch(\PDOException $e){
	     	// catching the exception during fullreload: errorlogitem table not found
	     	// TODO do something useful
	     }catch(\ORMException $e){
	     	// catching the exception during fullreload: The EntityManager is closed
	     	// TODO do something useful
	     }
		    
		 $this->container->get('monolog.logger.doctrine')->popHandler();
	    
    }

    private function initialize(){
    	$this->initialized = true;
    }
}<commit_msg>Fix for spl_object_hash() expects parameter 1 to be object<commit_after><?php

namespace Kunstmaan\AdminBundle\Modules;

use Kunstmaan\AdminBundle\Entity\User;
use Kunstmaan\AdminBundle\Entity\ErrorLogItem;

use Symfony\Component\DependencyInjection\Container;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\EntityManager;
use Monolog\Logger;
use Monolog\Handler\NullHandler;
use Monolog\Handler\AbstractProcessingHandler;

class LogHandler extends AbstractProcessingHandler
{
    private $initialized = false;
    private $container;

    public function __construct(Container &$container, $level = Logger::ERROR, $bubble = true){
        $this->container = $container;
        parent::__construct($level, $bubble);
    }

    protected function write(array $record){
        if (!$this->initialized) {
            $this->initialize();
        }

        $this->container->get('monolog.logger.doctrine')->pushHandler(new NullHandler());
        
	    try{
	    	$user = $this->container->get('security.context')->getToken()->getUser();
	    	
	    	$logitem = new ErrorLogItem();
	    	if($user instanceof User){
	    		$logitem->setUser($user);
	    	}
	    	$logitem->setStatus("error");
	        $logitem->setChannel($record['channel']);
	        $logitem->setLevel($record['level']);
	        $logitem->setMessage($record['formatted']);
		    $em = $this->container->get('doctrine')->getEntityManager();
			$em->persist($logitem);
			$em->flush();
	     }catch(\PDOException $e){
	     	// catching the exception during fullreload: errorlogitem table not found
	     	// TODO do something useful
	     }catch(\ORMException $e){
	     	// catching the exception during fullreload: The EntityManager is closed
	     	// TODO do something useful
	     }
		    
		 $this->container->get('monolog.logger.doctrine')->popHandler();
	    
    }

    private function initialize(){
    	$this->initialized = true;
    }
}
{'fraction_non_alphanumeric': 0.14865844815083393, 'fraction_numerical': 0.0009668842156151801, 'mean_word_length': 3.2703818369453046, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, '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': '2487780', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1167, 'n_words': 227}