AdyenLogger.php 3.59 KB
Newer Older
1
<?php
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/**
 *                       ######
 *                       ######
 * ############    ####( ######  #####. ######  ############   ############
 * #############  #####( ######  #####. ######  #############  #############
 *        ######  #####( ######  #####. ######  #####  ######  #####  ######
 * ###### ######  #####( ######  #####. ######  #####  #####   #####  ######
 * ###### ######  #####( ######  #####. ######  #####          #####  ######
 * #############  #############  #############  #############  #####  ######
 *  ############   ############  #############   ############  #####  ######
 *                                      ######
 *                               #############
 *                               ############
 *
 * Adyen Payment module (https://www.adyen.com/)
 *
 * Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
 * See LICENSE.txt for license details.
 *
 * Author: Adyen <magento@adyen.com>
 */

24 25 26 27 28 29
namespace Adyen\Payment\Logger;

use Monolog\Logger;

class AdyenLogger extends Logger
{
30 31 32 33 34 35 36 37 38 39 40 41 42 43
    /**
     * Detailed debug information
     */
    const ADYEN_DEBUG = 101;
    const ADYEN_NOTIFICATION = 201;
    const ADYEN_RESULT = 202;
    const ADYEN_NOTIFICATION_CRONJOB = 203;

    /**
     * Logging levels from syslog protocol defined in RFC 5424
     * Overrule the default to add Adyen specific loggers to log into seperate files
     *
     * @var array $levels Logging levels
     */
44
    protected static $levels = [
45 46 47 48 49 50 51 52 53 54 55 56
        100 => 'DEBUG',
        101 => 'ADYEN_DEBUG',
        200 => 'INFO',
        201 => 'ADYEN_NOTIFICATION',
        202 => 'ADYEN_RESULT',
        203 => 'ADYEN_NOTIFICATION_CRONJOB',
        250 => 'NOTICE',
        300 => 'WARNING',
        400 => 'ERROR',
        500 => 'CRITICAL',
        550 => 'ALERT',
        600 => 'EMERGENCY',
57
    ];
58 59 60 61 62 63

    /**
     * Adds a log record at the INFO level.
     *
     * This method allows for compatibility with common interfaces.
     *
64 65
     * @param string $message The log message
     * @param array $context The log context
66 67
     * @return Boolean Whether the record has been processed
     */
68
    public function addAdyenNotification($message, array $context = [])
69
    {
70 71 72
        return $this->addRecord(static::ADYEN_NOTIFICATION, $message, $context);
    }

73
    public function addAdyenDebug($message, array $context = [])
74 75
    {
        return $this->addRecord(static::ADYEN_DEBUG, $message, $context);
76 77
    }

78
    public function addAdyenResult($message, array $context = [])
79
    {
80
        return $this->addRecord(static::ADYEN_RESULT, $message, $context);
81 82
    }

83
    public function addAdyenNotificationCronjob($message, array $context = [])
84 85 86
    {
        return $this->addRecord(static::ADYEN_NOTIFICATION_CRONJOB, $message, $context);
    }
87

88 89 90
    /**
     * Adds a log record.
     *
91 92 93
     * @param integer $level The logging level
     * @param string $message The log message
     * @param array $context The log context
94 95 96 97 98 99 100
     * @return Boolean Whether the record has been processed
     */
    public function addRecord($level, $message, array $context = [])
    {
        $context['is_exception'] = $message instanceof \Exception;
        return parent::addRecord($level, $message, $context);
    }
101 102 103 104 105 106

    /**
     * Adds a log record at the INFO level.
     *
     * This method allows for compatibility with common interfaces.
     *
107 108
     * @param string $message The log message
     * @param array $context The log context
109 110
     * @return Boolean Whether the record has been processed
     */
111
    public function addNotificationLog($message, array $context = [])
112 113 114
    {
        return $this->addRecord(static::INFO, $message, $context);
    }
115
}