1*ae1ee236SAndreas Gohr<?php 2*ae1ee236SAndreas Gohr 3*ae1ee236SAndreas Gohrnamespace Psr\Log; 4*ae1ee236SAndreas Gohr 5*ae1ee236SAndreas Gohr/** 6*ae1ee236SAndreas Gohr * This is a simple Logger trait that classes unable to extend AbstractLogger 7*ae1ee236SAndreas Gohr * (because they extend another class, etc) can include. 8*ae1ee236SAndreas Gohr * 9*ae1ee236SAndreas Gohr * It simply delegates all log-level-specific methods to the `log` method to 10*ae1ee236SAndreas Gohr * reduce boilerplate code that a simple Logger that does the same thing with 11*ae1ee236SAndreas Gohr * messages regardless of the error level has to implement. 12*ae1ee236SAndreas Gohr */ 13*ae1ee236SAndreas Gohrtrait LoggerTrait 14*ae1ee236SAndreas Gohr{ 15*ae1ee236SAndreas Gohr /** 16*ae1ee236SAndreas Gohr * System is unusable. 17*ae1ee236SAndreas Gohr * 18*ae1ee236SAndreas Gohr * @param string $message 19*ae1ee236SAndreas Gohr * @param array $context 20*ae1ee236SAndreas Gohr * 21*ae1ee236SAndreas Gohr * @return null 22*ae1ee236SAndreas Gohr */ 23*ae1ee236SAndreas Gohr public function emergency($message, array $context = array()) 24*ae1ee236SAndreas Gohr { 25*ae1ee236SAndreas Gohr $this->log(LogLevel::EMERGENCY, $message, $context); 26*ae1ee236SAndreas Gohr } 27*ae1ee236SAndreas Gohr 28*ae1ee236SAndreas Gohr /** 29*ae1ee236SAndreas Gohr * Action must be taken immediately. 30*ae1ee236SAndreas Gohr * 31*ae1ee236SAndreas Gohr * Example: Entire website down, database unavailable, etc. This should 32*ae1ee236SAndreas Gohr * trigger the SMS alerts and wake you up. 33*ae1ee236SAndreas Gohr * 34*ae1ee236SAndreas Gohr * @param string $message 35*ae1ee236SAndreas Gohr * @param array $context 36*ae1ee236SAndreas Gohr * 37*ae1ee236SAndreas Gohr * @return null 38*ae1ee236SAndreas Gohr */ 39*ae1ee236SAndreas Gohr public function alert($message, array $context = array()) 40*ae1ee236SAndreas Gohr { 41*ae1ee236SAndreas Gohr $this->log(LogLevel::ALERT, $message, $context); 42*ae1ee236SAndreas Gohr } 43*ae1ee236SAndreas Gohr 44*ae1ee236SAndreas Gohr /** 45*ae1ee236SAndreas Gohr * Critical conditions. 46*ae1ee236SAndreas Gohr * 47*ae1ee236SAndreas Gohr * Example: Application component unavailable, unexpected exception. 48*ae1ee236SAndreas Gohr * 49*ae1ee236SAndreas Gohr * @param string $message 50*ae1ee236SAndreas Gohr * @param array $context 51*ae1ee236SAndreas Gohr * 52*ae1ee236SAndreas Gohr * @return null 53*ae1ee236SAndreas Gohr */ 54*ae1ee236SAndreas Gohr public function critical($message, array $context = array()) 55*ae1ee236SAndreas Gohr { 56*ae1ee236SAndreas Gohr $this->log(LogLevel::CRITICAL, $message, $context); 57*ae1ee236SAndreas Gohr } 58*ae1ee236SAndreas Gohr 59*ae1ee236SAndreas Gohr /** 60*ae1ee236SAndreas Gohr * Runtime errors that do not require immediate action but should typically 61*ae1ee236SAndreas Gohr * be logged and monitored. 62*ae1ee236SAndreas Gohr * 63*ae1ee236SAndreas Gohr * @param string $message 64*ae1ee236SAndreas Gohr * @param array $context 65*ae1ee236SAndreas Gohr * 66*ae1ee236SAndreas Gohr * @return null 67*ae1ee236SAndreas Gohr */ 68*ae1ee236SAndreas Gohr public function error($message, array $context = array()) 69*ae1ee236SAndreas Gohr { 70*ae1ee236SAndreas Gohr $this->log(LogLevel::ERROR, $message, $context); 71*ae1ee236SAndreas Gohr } 72*ae1ee236SAndreas Gohr 73*ae1ee236SAndreas Gohr /** 74*ae1ee236SAndreas Gohr * Exceptional occurrences that are not errors. 75*ae1ee236SAndreas Gohr * 76*ae1ee236SAndreas Gohr * Example: Use of deprecated APIs, poor use of an API, undesirable things 77*ae1ee236SAndreas Gohr * that are not necessarily wrong. 78*ae1ee236SAndreas Gohr * 79*ae1ee236SAndreas Gohr * @param string $message 80*ae1ee236SAndreas Gohr * @param array $context 81*ae1ee236SAndreas Gohr * 82*ae1ee236SAndreas Gohr * @return null 83*ae1ee236SAndreas Gohr */ 84*ae1ee236SAndreas Gohr public function warning($message, array $context = array()) 85*ae1ee236SAndreas Gohr { 86*ae1ee236SAndreas Gohr $this->log(LogLevel::WARNING, $message, $context); 87*ae1ee236SAndreas Gohr } 88*ae1ee236SAndreas Gohr 89*ae1ee236SAndreas Gohr /** 90*ae1ee236SAndreas Gohr * Normal but significant events. 91*ae1ee236SAndreas Gohr * 92*ae1ee236SAndreas Gohr * @param string $message 93*ae1ee236SAndreas Gohr * @param array $context 94*ae1ee236SAndreas Gohr * 95*ae1ee236SAndreas Gohr * @return null 96*ae1ee236SAndreas Gohr */ 97*ae1ee236SAndreas Gohr public function notice($message, array $context = array()) 98*ae1ee236SAndreas Gohr { 99*ae1ee236SAndreas Gohr $this->log(LogLevel::NOTICE, $message, $context); 100*ae1ee236SAndreas Gohr } 101*ae1ee236SAndreas Gohr 102*ae1ee236SAndreas Gohr /** 103*ae1ee236SAndreas Gohr * Interesting events. 104*ae1ee236SAndreas Gohr * 105*ae1ee236SAndreas Gohr * Example: User logs in, SQL logs. 106*ae1ee236SAndreas Gohr * 107*ae1ee236SAndreas Gohr * @param string $message 108*ae1ee236SAndreas Gohr * @param array $context 109*ae1ee236SAndreas Gohr * 110*ae1ee236SAndreas Gohr * @return null 111*ae1ee236SAndreas Gohr */ 112*ae1ee236SAndreas Gohr public function info($message, array $context = array()) 113*ae1ee236SAndreas Gohr { 114*ae1ee236SAndreas Gohr $this->log(LogLevel::INFO, $message, $context); 115*ae1ee236SAndreas Gohr } 116*ae1ee236SAndreas Gohr 117*ae1ee236SAndreas Gohr /** 118*ae1ee236SAndreas Gohr * Detailed debug information. 119*ae1ee236SAndreas Gohr * 120*ae1ee236SAndreas Gohr * @param string $message 121*ae1ee236SAndreas Gohr * @param array $context 122*ae1ee236SAndreas Gohr * 123*ae1ee236SAndreas Gohr * @return null 124*ae1ee236SAndreas Gohr */ 125*ae1ee236SAndreas Gohr public function debug($message, array $context = array()) 126*ae1ee236SAndreas Gohr { 127*ae1ee236SAndreas Gohr $this->log(LogLevel::DEBUG, $message, $context); 128*ae1ee236SAndreas Gohr } 129*ae1ee236SAndreas Gohr 130*ae1ee236SAndreas Gohr /** 131*ae1ee236SAndreas Gohr * Logs with an arbitrary level. 132*ae1ee236SAndreas Gohr * 133*ae1ee236SAndreas Gohr * @param mixed $level 134*ae1ee236SAndreas Gohr * @param string $message 135*ae1ee236SAndreas Gohr * @param array $context 136*ae1ee236SAndreas Gohr * 137*ae1ee236SAndreas Gohr * @return null 138*ae1ee236SAndreas Gohr */ 139*ae1ee236SAndreas Gohr abstract public function log($level, $message, array $context = array()); 140*ae1ee236SAndreas Gohr} 141