10b7ac7c9SAndreas Gohr<?php 20b7ac7c9SAndreas Gohr 30b7ac7c9SAndreas Gohrnamespace splitbrain\dokuwiki\plugin\smtp; 40b7ac7c9SAndreas Gohr 50b7ac7c9SAndreas Gohruse Psr\Log\LoggerInterface; 60b7ac7c9SAndreas Gohr 70b7ac7c9SAndreas Gohr/** 80b7ac7c9SAndreas Gohr * Simple PSR-3 logger 90b7ac7c9SAndreas Gohr * 100b7ac7c9SAndreas Gohr * Simply logs to an internal variable 110b7ac7c9SAndreas Gohr * 120b7ac7c9SAndreas Gohr * @package splitbrain\dokuwiki\plugin\smtp 130b7ac7c9SAndreas Gohr */ 14*ee5c0205SAndreas Gohrclass Logger implements LoggerInterface 15*ee5c0205SAndreas Gohr{ 16*ee5c0205SAndreas Gohr protected $log = []; 170b7ac7c9SAndreas Gohr 180b7ac7c9SAndreas Gohr /** 190b7ac7c9SAndreas Gohr * Get all log messages 200b7ac7c9SAndreas Gohr * 210b7ac7c9SAndreas Gohr * @return array 220b7ac7c9SAndreas Gohr */ 23*ee5c0205SAndreas Gohr public function getLog() 24*ee5c0205SAndreas Gohr { 250b7ac7c9SAndreas Gohr return $this->log; 260b7ac7c9SAndreas Gohr } 270b7ac7c9SAndreas Gohr 280b7ac7c9SAndreas Gohr /** 290b7ac7c9SAndreas Gohr * System is unusable. 300b7ac7c9SAndreas Gohr * 310b7ac7c9SAndreas Gohr * @param string $message 320b7ac7c9SAndreas Gohr * @param array $context 330b7ac7c9SAndreas Gohr */ 34*ee5c0205SAndreas Gohr public function emergency($message, array $context = []) 350b7ac7c9SAndreas Gohr { 360b7ac7c9SAndreas Gohr $this->log('emergency', $message, $context); 370b7ac7c9SAndreas Gohr } 380b7ac7c9SAndreas Gohr 390b7ac7c9SAndreas Gohr /** 400b7ac7c9SAndreas Gohr * Action must be taken immediately. 410b7ac7c9SAndreas Gohr * 420b7ac7c9SAndreas Gohr * Example: Entire website down, database unavailable, etc. This should 430b7ac7c9SAndreas Gohr * trigger the SMS alerts and wake you up. 440b7ac7c9SAndreas Gohr * 450b7ac7c9SAndreas Gohr * @param string $message 460b7ac7c9SAndreas Gohr * @param array $context 470b7ac7c9SAndreas Gohr */ 48*ee5c0205SAndreas Gohr public function alert($message, array $context = []) 490b7ac7c9SAndreas Gohr { 500b7ac7c9SAndreas Gohr $this->log('alert', $message, $context); 510b7ac7c9SAndreas Gohr } 520b7ac7c9SAndreas Gohr 530b7ac7c9SAndreas Gohr /** 540b7ac7c9SAndreas Gohr * Critical conditions. 550b7ac7c9SAndreas Gohr * 560b7ac7c9SAndreas Gohr * Example: Application component unavailable, unexpected exception. 570b7ac7c9SAndreas Gohr * 580b7ac7c9SAndreas Gohr * @param string $message 590b7ac7c9SAndreas Gohr * @param array $context 600b7ac7c9SAndreas Gohr */ 61*ee5c0205SAndreas Gohr public function critical($message, array $context = []) 620b7ac7c9SAndreas Gohr { 630b7ac7c9SAndreas Gohr $this->log('critical', $message, $context); 640b7ac7c9SAndreas Gohr } 650b7ac7c9SAndreas Gohr 660b7ac7c9SAndreas Gohr /** 670b7ac7c9SAndreas Gohr * Runtime errors that do not require immediate action but should typically 680b7ac7c9SAndreas Gohr * be logged and monitored. 690b7ac7c9SAndreas Gohr * 700b7ac7c9SAndreas Gohr * @param string $message 710b7ac7c9SAndreas Gohr * @param array $context 720b7ac7c9SAndreas Gohr */ 73*ee5c0205SAndreas Gohr public function error($message, array $context = []) 740b7ac7c9SAndreas Gohr { 750b7ac7c9SAndreas Gohr $this->log('error', $message, $context); 760b7ac7c9SAndreas Gohr } 770b7ac7c9SAndreas Gohr 780b7ac7c9SAndreas Gohr /** 790b7ac7c9SAndreas Gohr * Exceptional occurrences that are not errors. 800b7ac7c9SAndreas Gohr * 810b7ac7c9SAndreas Gohr * Example: Use of deprecated APIs, poor use of an API, undesirable things 820b7ac7c9SAndreas Gohr * that are not necessarily wrong. 830b7ac7c9SAndreas Gohr * 840b7ac7c9SAndreas Gohr * @param string $message 850b7ac7c9SAndreas Gohr * @param array $context 860b7ac7c9SAndreas Gohr */ 87*ee5c0205SAndreas Gohr public function warning($message, array $context = []) 880b7ac7c9SAndreas Gohr { 890b7ac7c9SAndreas Gohr $this->log('warning', $message, $context); 900b7ac7c9SAndreas Gohr } 910b7ac7c9SAndreas Gohr 920b7ac7c9SAndreas Gohr /** 930b7ac7c9SAndreas Gohr * Normal but significant events. 940b7ac7c9SAndreas Gohr * 950b7ac7c9SAndreas Gohr * @param string $message 960b7ac7c9SAndreas Gohr * @param array $context 970b7ac7c9SAndreas Gohr */ 98*ee5c0205SAndreas Gohr public function notice($message, array $context = []) 990b7ac7c9SAndreas Gohr { 1000b7ac7c9SAndreas Gohr $this->log('notice', $message, $context); 1010b7ac7c9SAndreas Gohr } 1020b7ac7c9SAndreas Gohr 1030b7ac7c9SAndreas Gohr /** 1040b7ac7c9SAndreas Gohr * Interesting events. 1050b7ac7c9SAndreas Gohr * 1060b7ac7c9SAndreas Gohr * Example: User logs in, SQL logs. 1070b7ac7c9SAndreas Gohr * 1080b7ac7c9SAndreas Gohr * @param string $message 1090b7ac7c9SAndreas Gohr * @param array $context 1100b7ac7c9SAndreas Gohr */ 111*ee5c0205SAndreas Gohr public function info($message, array $context = []) 1120b7ac7c9SAndreas Gohr { 1130b7ac7c9SAndreas Gohr $this->log('info', $message, $context); 1140b7ac7c9SAndreas Gohr } 1150b7ac7c9SAndreas Gohr 1160b7ac7c9SAndreas Gohr /** 1170b7ac7c9SAndreas Gohr * Detailed debug information. 1180b7ac7c9SAndreas Gohr * 1190b7ac7c9SAndreas Gohr * @param string $message 1200b7ac7c9SAndreas Gohr * @param array $context 1210b7ac7c9SAndreas Gohr */ 122*ee5c0205SAndreas Gohr public function debug($message, array $context = []) 1230b7ac7c9SAndreas Gohr { 1240b7ac7c9SAndreas Gohr $this->log('debug', $message, $context); 1250b7ac7c9SAndreas Gohr } 1260b7ac7c9SAndreas Gohr 1270b7ac7c9SAndreas Gohr /** 1280b7ac7c9SAndreas Gohr * Logs with an arbitrary level. 1290b7ac7c9SAndreas Gohr * 1300b7ac7c9SAndreas Gohr * @param mixed $level 1310b7ac7c9SAndreas Gohr * @param string $message 1320b7ac7c9SAndreas Gohr * @param array $context 1330b7ac7c9SAndreas Gohr */ 134*ee5c0205SAndreas Gohr public function log($level, $message, array $context = []) 1350b7ac7c9SAndreas Gohr { 136*ee5c0205SAndreas Gohr $this->log[] = [$level, $message, $context]; 1370b7ac7c9SAndreas Gohr } 1380b7ac7c9SAndreas Gohr} 139