Overview

Namespaces

  • FastFeed
    • Aggregator
    • Cache
    • Exception
    • Logger
    • Parser
    • Processor
  • PHP

Classes

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