Overview

Packages

  • Log
    • Filters
    • Formatters
    • Handlers

Classes

  • Horde_Log_Formatter_Simple
  • Horde_Log_Formatter_Xml
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Horde Log package
 4:  *
 5:  * This package is based on Zend_Log from the Zend Framework
 6:  * (http://framework.zend.com).  Both that package and this
 7:  * one were written by Mike Naberezny and Chuck Hagenbuch.
 8:  *
 9:  * @author     Mike Naberezny <mike@maintainable.com>
10:  * @author     Chuck Hagenbuch <chuck@horde.org>
11:  * @category   Horde
12:  * @license    http://www.horde.org/licenses/bsd BSD
13:  * @package    Log
14:  * @subpackage Formatters
15:  */
16: 
17: /**
18:  * @author     Mike Naberezny <mike@maintainable.com>
19:  * @author     Chuck Hagenbuch <chuck@horde.org>
20:  * @category   Horde
21:  * @license    http://www.horde.org/licenses/bsd BSD
22:  * @package    Log
23:  * @subpackage Formatters
24:  */
25: class Horde_Log_Formatter_Simple implements Horde_Log_Formatter
26: {
27:     /**
28:      * Format string.
29:      *
30:      * @var string
31:      */
32:     protected $_format;
33: 
34:     /**
35:      * Constructor.
36:      *
37:      * @param array $options  Configuration options:
38:      * <pre>
39:      * 'format' - (string) The log template.
40:      * </pre>
41:      *
42:      * @throws InvalidArgumentException
43:      */
44:     public function __construct($options = null)
45:     {
46:         $format = (is_array($options) && isset($options['format']))
47:             ? $options['format']
48:             : $options;
49: 
50:         if (is_null($format)) {
51:             $format = '%timestamp% %levelName%: %message%' . PHP_EOL;
52:         }
53: 
54:         if (!is_string($format)) {
55:             throw new InvalidArgumentException('Format must be a string');
56:         }
57: 
58:         $this->_format = $format;
59:     }
60: 
61:     /**
62:      * Formats an event to be written by the handler.
63:      *
64:      * @param array $event  Log event.
65:      *
66:      * @return string  Formatted line.
67:      */
68:     public function format($event)
69:     {
70:         $output = $this->_format;
71:         foreach ($event as $name => $value) {
72:             $output = str_replace("%$name%", $value, $output);
73:         }
74:         return $output;
75:     }
76: 
77: }
78: 
API documentation generated by ApiGen