1<?php 2 3namespace splitbrain\dokuwiki\plugin\smtp; 4 5use Psr\Log\LoggerInterface; 6 7/** 8 * Simple PSR-3 logger 9 * 10 * Simply logs to an internal variable 11 * 12 * @package splitbrain\dokuwiki\plugin\smtp 13 */ 14class Logger implements LoggerInterface { 15 16 protected $log = array(); 17 18 /** 19 * Get all log messages 20 * 21 * @return array 22 */ 23 public function getLog() { 24 return $this->log; 25 } 26 27 /** 28 * System is unusable. 29 * 30 * @param string $message 31 * @param array $context 32 * 33 * @return null 34 */ 35 public function emergency($message, array $context = array()) 36 { 37 $this->log('emergency', $message, $context); 38 } 39 40 /** 41 * Action must be taken immediately. 42 * 43 * Example: Entire website down, database unavailable, etc. This should 44 * trigger the SMS alerts and wake you up. 45 * 46 * @param string $message 47 * @param array $context 48 * 49 * @return null 50 */ 51 public function alert($message, array $context = array()) 52 { 53 $this->log('alert', $message, $context); 54 } 55 56 /** 57 * Critical conditions. 58 * 59 * Example: Application component unavailable, unexpected exception. 60 * 61 * @param string $message 62 * @param array $context 63 * 64 * @return null 65 */ 66 public function critical($message, array $context = array()) 67 { 68 $this->log('critical', $message, $context); 69 } 70 71 /** 72 * Runtime errors that do not require immediate action but should typically 73 * be logged and monitored. 74 * 75 * @param string $message 76 * @param array $context 77 * 78 * @return null 79 */ 80 public function error($message, array $context = array()) 81 { 82 $this->log('error', $message, $context); 83 } 84 85 /** 86 * Exceptional occurrences that are not errors. 87 * 88 * Example: Use of deprecated APIs, poor use of an API, undesirable things 89 * that are not necessarily wrong. 90 * 91 * @param string $message 92 * @param array $context 93 * 94 * @return null 95 */ 96 public function warning($message, array $context = array()) 97 { 98 $this->log('warning', $message, $context); 99 } 100 101 /** 102 * Normal but significant events. 103 * 104 * @param string $message 105 * @param array $context 106 * 107 * @return null 108 */ 109 public function notice($message, array $context = array()) 110 { 111 $this->log('notice', $message, $context); 112 } 113 114 /** 115 * Interesting events. 116 * 117 * Example: User logs in, SQL logs. 118 * 119 * @param string $message 120 * @param array $context 121 * 122 * @return null 123 */ 124 public function info($message, array $context = array()) 125 { 126 $this->log('info', $message, $context); 127 } 128 129 /** 130 * Detailed debug information. 131 * 132 * @param string $message 133 * @param array $context 134 * 135 * @return null 136 */ 137 public function debug($message, array $context = array()) 138 { 139 $this->log('debug', $message, $context); 140 } 141 142 /** 143 * Logs with an arbitrary level. 144 * 145 * @param mixed $level 146 * @param string $message 147 * @param array $context 148 * 149 * @return null 150 */ 151 public function log($level, $message, array $context = array()) 152 { 153 $this->log[] = array($level, $message, $context); 154 } 155} 156