<commit_before><?php
/**
 * AMQPAppender appends log events to a AMQP.
 *
 * This appender uses a layout.
 *
 * Configurable parameters for this appender are:
 *
 * - <string> host                - AMQP host
 * - <int>    port                - AMQP port
 * - <string> vhost               - AMQP vhost
 * - <string> login               - AMQP login
 * - <string> password            - AMQP password
 * - <string> routingKey          - AMQP routing key. Set up AMQP server to route messages with this key to your queue
 * - <int>    skipConnectionError - 1 by defalut. All connection errors will be skipped without any error or exception
 *
 * @version 0.1
 * @author <NAME> (Wikimart LLC)
 * @license GPL
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 */
class LoggerAppenderAMQP extends LoggerAppender
{
    /**
     * AMQP connection settings
     */
    protected $_host;
    protected $_port;
    protected $_vhost;
    protected $_login;
    protected $_password;
    protected $_routingKey;
    protected $_skipConnectionError = 1;

    protected static $_AMQPConnection;
    protected static $_AMQPExchange;

	/**
	 * Forwards the logging event to the AMQP.
	 * @param LoggerLoggingEvent $event
	 */
	protected function append(LoggerLoggingEvent $event)
	{
        try
        {
            $this->getAMQPExchange()->publish(
                $this->layout->format($event),
                $this->getRoutingKey(),
                AMQP_NOPARAM,
                array(
                    'content_type' => 'application/json',
                    'content_encoding' => 'UTF-8'
                )
            );
        }
        catch (Exception $e)
        {
            if (!$this->getSkipConnectionError())
            {
                throw $e;
            }
        }
	}

    protected function setAMQPConnection($AMQPConnection)
    {
        self::$_AMQPConnection = $AMQPConnection;
    }

    protected function getAMQPConnection()
    {
        if (is_null(self::$_AMQPConnection))
        {
            self::$_AMQPConnection = $this->createAMQPConnection();
        }
        return self::$_AMQPConnection;
    }

    protected function createAMQPConnection()
    {
        $connection = new AMQPConnection();
        $connection->setHost($this->getHost());
        $connection->setPort($this->getPort());
        $connection->setVhost($this->getVhost());
        $connection->setLogin($this->getLogin());
        $connection->setPassword($this->getPassword());
        $connection->connect();

        return $connection;
    }

    protected function setAMQPExchange($AMQPExchange)
    {
        self::$_AMQPExchange = $AMQPExchange;
    }

    protected function getAMQPExchange()
    {
        if (is_null(self::$_AMQPExchange))
        {
            $channel = new AMQPChannel($this->getAMQPConnection());
            $exchange = new AMQPExchange($channel);
            self::$_AMQPExchange = $exchange;
        }
        return self::$_AMQPExchange;
    }

    public function setRoutingKey($AMQPRoutingKey)
    {
        $this->_routingKey = $AMQPRoutingKey;
    }

    public function getRoutingKey()
    {
        return $this->_routingKey;
    }

    public function setHost($host)<commit_msg>Code formatting<commit_after><?php
/**
 * AMQPAppender appends log events to a AMQP.
 *
 * This appender uses a layout.
 *
 * Configurable parameters for this appender are:
 *
 * - <string> host                - AMQP host
 * - <int>    port                - AMQP port
 * - <string> vhost               - AMQP vhost
 * - <string> login               - AMQP login
 * - <string> password            - AMQP password
 * - <string> routingKey          - AMQP routing key. Set up AMQP server to route messages with this key to your queue
 * - <int>    skipConnectionError - 1 by defalut. All connection errors will be skipped without any error or exception
 *
 * @version 0.1
 * @author <NAME> (Wikimart LLC)
 * @license GPL
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 */
class LoggerAppenderAMQP extends LoggerAppender
{
    /**
     * AMQP connection settings
     */
    protected $_host;
    protected $_port;
    protected $_vhost;
    protected $_login;
    protected $_password;
    protected $_routingKey;
    protected $_skipConnectionError = 1;

    protected static $_AMQPConnection;
    protected static $_AMQPExchange;

    /**
     * Forwards the logging event to the AMQP.
     * @param LoggerLoggingEvent $event
     */
    protected function append(LoggerLoggingEvent $event)
    {
        try {
            $this->getAMQPExchange()->publish(
                $this->layout->format($event),
                $this->getRoutingKey(),
                AMQP_NOPARAM,
                array(
                    'content_type' => 'application/json',
                    'content_encoding' => 'UTF-8'
                )
            );
        } catch (Exception $e) {
            if (!$this->getSkipConnectionError()) {
                throw $e;
            }
        }
    }

    protected function setAMQPConnection($AMQPConnection)
    {
        self::$_AMQPConnection = $AMQPConnection;
    }

    protected function getAMQPConnection()
    {
        if (is_null(self::$_AMQPConnection)) {
            self::$_AMQPConnection = $this->createAMQPConnection();
        }
        return self::$_AMQPConnection;
    }

    protected function createAMQPConnection()
    {
        $connection = new AMQPConnection();
        $connection->setHost($this->getHost());
        $connection->setPort($this->getPort());
        $connection->setVhost($this->getVhost());
        $connection->setLogin($this->getLogin());
        $connection->setPassword($this->getPassword());
        $connection->connect();

        return $connection;
    }

    protected function setAMQPExchange($AMQPExchange)
    {
        self::$_AMQPExchange = $AMQPExchange;
    }

    protected function getAMQPExchange()
    {
        if (is_null(self::$_AMQPExchange)) {
            $channel = new AMQPChannel($this->getAMQPConnection());
            $exchange = new AMQPExchange($channel);
            self::$_AMQPExchange = $exchange;
        }
        return self::$_AMQPExchange;
    }

    public function setRoutingKey($AMQPRoutingKey)
    {
        $this->_routingKey = $AMQPRoutingKey;
    }

    public function getRoutingKey()
    {
        return $this->_routingKey;
    }

    public function setHost($host)
{'fraction_non_alphanumeric': 0.11219286045433473, 'fraction_numerical': 0.0015453562046051615, 'mean_word_length': 2.1070571291406623, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 65, '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': '4613327', 'n_tokens_mistral': 1901, 'n_tokens_neox': 1755, 'n_words': 412}