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