* @package generis */ class common_log_XMLAppender extends common_log_BaseAppender { // --- ASSOCIATIONS --- // --- ATTRIBUTES --- /** * Short description of attribute filename * * @access public * @var string */ public $filename = ''; // --- OPERATIONS --- /** * Short description of method init * * @access public * @author Joel Bout, * @param array configuration * @return boolean */ public function init($configuration) { $returnValue = (bool) false; if (isset($configuration['file'])) { $this->filename = $configuration['file']; $returnValue = parent::init($configuration); } else { $returnValue = false; } return (bool) $returnValue; } /** * Short description of method doLog * * @access public * @author Joel Bout, * @param Item item * @return mixed */ public function doLog(common_log_Item $item) { $doc = new DOMDocument(); $doc->preserveWhiteSpace = false; $doc->formatOutput = true; $success = @$doc->load($this->filename); if (!$success) { $doc->loadXML(''); } $event_element = $doc->createElement("event"); $message = $doc->createElement("description"); $message->appendChild( $doc->createCDATASection($item->getDescription()) ); $event_element->appendChild($message); $file = $doc->createElement("file"); $file->appendChild( $doc->createCDATASection($item->getCallerFile()) ); $event_element->appendChild($file); $line = $doc->createElement("line"); $line->appendChild( $doc->createCDATASection($item->getCallerLine()) ); $event_element->appendChild($line); $datetime = $doc->createElement("datetime"); $datetime->appendChild( $doc->createCDATASection($item->getDateTime()) ); $event_element->appendChild($datetime); $severity = $doc->createElement("severity"); $severity->appendChild( $doc->createCDATASection($item->getSeverity()) ); $event_element->appendChild($severity); $doc->documentElement->appendChild($event_element); @$doc->save($this->filename); } }