7
* This source file is subject to the new BSD license that is bundled
8
* with this package in the file LICENSE.txt.
9
* It is also available through the world-wide-web at this URL:
10
* http://framework.zend.com/license/new-bsd
11
* If you did not receive a copy of the license and are unable to
12
* obtain it through the world-wide-web, please send an email
13
* to license@zend.com so we can send you a copy immediately.
17
* @subpackage Formatter
18
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
19
* @license http://framework.zend.com/license/new-bsd New BSD License
20
* @version $Id: Xml.php 12363 2008-11-07 10:45:22Z beberlei $
23
/** Zend_Log_Formatter_Interface */
24
require_once 'Zend/Log/Formatter/Interface.php';
29
* @subpackage Formatter
30
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
31
* @license http://framework.zend.com/license/new-bsd New BSD License
32
* @version $Id: Xml.php 12363 2008-11-07 10:45:22Z beberlei $
34
class Zend_Log_Formatter_Xml implements Zend_Log_Formatter_Interface
37
* @var Relates XML elements to log data field keys.
39
protected $_rootElement;
42
* @var Relates XML elements to log data field keys.
44
protected $_elementMap;
49
* @param array $elementMap
51
public function __construct($rootElement = 'logEntry', $elementMap = null)
53
$this->_rootElement = $rootElement;
54
$this->_elementMap = $elementMap;
58
* Formats data into a single line to be written by the writer.
60
* @param array $event event data
61
* @return string formatted line to write to the log
63
public function format($event)
65
if ($this->_elementMap === null) {
66
$dataToInsert = $event;
68
$dataToInsert = array();
69
foreach ($this->_elementMap as $elementName => $fieldKey) {
70
$dataToInsert[$elementName] = $event[$fieldKey];
74
$dom = new DOMDocument();
75
$elt = $dom->appendChild(new DOMElement($this->_rootElement));
77
foreach ($dataToInsert as $key => $value) {
78
if($key == "message") {
79
$value = htmlspecialchars($value);
81
$elt->appendChild(new DOMElement($key, $value));
84
$xml = $dom->saveXML();
85
$xml = preg_replace('/<\?xml version="1.0"( encoding="[^\"]*")?\?>\n/u', '', $xml);
87
return $xml . PHP_EOL;