prestashop /tools/swift/Swift/Log.php

Language PHP Lines 153
MD5 Hash 9c3be6a3428b14115d9df4af63fff639 Estimated Cost $1,236 (why?)
Repository https://bitbucket.org/enurkov/prestashop.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php

/**
 * Swift Mailer Logging Layer base class.
 * Please read the LICENSE file
 * @author Chris Corbyn <chris@w3style.co.uk>
 * @package Swift_Log
 * @license GNU Lesser General Public License
 */

/**
 * The Logger class/interface.
 * @package Swift_Log
 * @author Chris Corbyn <chris@w3style.co.uk>
 */
abstract class Swift_Log
{
  /**
   * A command type entry
   */
  const COMMAND = ">>";
  /**
   * A response type entry
   */
  const RESPONSE = "<<";
  /**
   * An error type entry
   */
  const ERROR = "!!";
  /**
   * A standard entry
   */
  const NORMAL = "++";
  /**
   * Logging is off.
   */
  const LOG_NOTHING = 0;
  /**
   * Only errors are logged.
   */
  const LOG_ERRORS = 1;
  /**
   * Errors + sending failures.
   */
  const LOG_FAILURES = 2;
  /**
   * All SMTP instructions + failures + errors.
   */
  const LOG_NETWORK = 3;
  /**
   * Runtime info + SMTP instructions + failures + errors.
   */
  const LOG_EVERYTHING = 4;
  /**
   * Failed recipients
   * @var array
   */
  protected $failedRecipients = array();
  /**
   * The maximum number of log entries
   * @var int
   */
  protected $maxSize = 50;
  /**
   * The level of logging currently set.
   * @var int
   */
  protected $logLevel = self::LOG_NOTHING;
  
  /**
   * Add a new entry to the log
   * @param string The information to log
   * @param string The type of entry (see the constants: COMMAND, RESPONSE, ERROR, NORMAL)
   */
  abstract public function add($text, $type = self::NORMAL);
  /**
   * Dump the contents of the log to the browser.
   * @param boolean True if the string should be returned rather than output.
   */
  abstract public function dump($return_only=false);
  /**
   * Empty the log contents
   */
  abstract public function clear();
  /**
   * Check if logging is enabled.
   */
  public function isEnabled()
  {
    return ($this->logLevel > self::LOG_NOTHING);
  }
  /**
   * Add a failed recipient to the list
   * @param string The address of the recipient
   */
  public function addFailedRecipient($address)
  {
    $this->failedRecipients[$address] = null;
    $this->add("Recipient '" . $address . "' rejected by connection.", self::ERROR);
  }
  /**
   * Get the list of failed recipients
   * @return array
   */
  public function getFailedRecipients()
  {
    return array_keys($this->failedRecipients);
  }
  /**
   * Set the maximum size of this log (zero is no limit)
   * @param int The maximum entries
   */
  public function setMaxSize($size)
  {
    $this->maxSize = (int) $size;
  }
  /**
   * Get the current maximum allowed log size
   * @return int
   */
  public function getMaxSize()
  {
    return $this->maxSize;
  }
  /**
   * Set the log level to one of the constants provided.
   * @param int Level
   */
  public function setLogLevel($level)
  {
    $level = (int)$level;
    $this->add("Log level changed to " . $level, self::NORMAL);
    $this->logLevel = $level;
  }
  /**
   * Get the current log level.
   * @return int
   */
  public function getLogLevel()
  {
    return $this->logLevel;
  }
  /**
   * Check if the log level includes the one given.
   * @param int Level
   * @return boolean
   */
  public function hasLevel($level)
  {
    return ($this->logLevel >= ((int)$level));
  }
}
Back to Top