http://wiki.freedesk.purplepixie.org/w/index.php?title=Logging_Module&feed=atom&action=historyLogging Module - Revision history2024-03-28T21:52:35ZRevision history for this page on the wikiMediaWiki 1.19.0http://wiki.freedesk.purplepixie.org/w/index.php?title=Logging_Module&diff=72&oldid=prevDave: Created page with "Logging modules provide a method for the FreeDESK log (syslog) to be outputted and stored. The default method uses a database table (syslog). All logging modules must be deri..."2012-08-22T00:01:23Z<p>Created page with "Logging modules provide a method for the FreeDESK log (syslog) to be outputted and stored. The default method uses a database table (syslog). All logging modules must be deri..."</p>
<p><b>New page</b></p><div>Logging modules provide a method for the FreeDESK log (syslog) to be outputted and stored. The default method uses a database table (syslog).<br />
<br />
All logging modules must be derived from the base class LogMethodBase.<br />
<br />
The inbuilt method logging to a database table as an example is as follows:<br />
<br />
<source lang="php"><br />
<br />
<?php <br />
/* -------------------------------------------------------------<br />
This file is part of FreeDESK<br />
<br />
FreeDESK is (C) Copyright 2012 David Cutting<br />
<br />
FreeDESK is free software: you can redistribute it and/or modify<br />
it under the terms of the GNU General Public License as published by<br />
the Free Software Foundation, either version 3 of the License, or<br />
(at your option) any later version.<br />
<br />
FreeDESK is distributed in the hope that it will be useful,<br />
but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
GNU General Public License for more details.<br />
<br />
You should have received a copy of the GNU General Public License<br />
along with FreeDESK. If not, see www.gnu.org/licenses<br />
<br />
For more information see www.purplepixie.org/freedesk/<br />
-------------------------------------------------------------- */<br />
<br />
/**<br />
* LogMethodDB implements database-level logging<br />
**/<br />
class LogMethodDB extends LogMethodBase<br />
{<br />
/**<br />
* FreeDESK instance<br />
**/<br />
private $DESK = null;<br />
<br />
/**<br />
* Constructor<br />
* @param mixed $freeDESK FreeDESK instance<br />
**/<br />
function LogMethodDB(&$freeDESK)<br />
{<br />
$this->DESK = &$freeDESK;<br />
$this->DESK->PluginManager->Register(new Plugin(<br />
"Core Database Logging", "0.01", "Log", "Database", "LogMethodDB" ));<br />
}<br />
<br />
/**<br />
* Log an event<br />
* @param string $event Event description<br />
* @param string $class Event class<br />
* @param string $type Event type (optional, default "")<br />
* @param int $level Event level (0 = fatal, 10 = low priority info only) (optional, default 10)<br />
**/<br />
function Log($event, $class, $type="", $level=10)<br />
{<br />
if (strlen($event)>254)<br />
$event=substr($event,0,251)."...";<br />
$q="INSERT INTO ".$this->DESK->Database->Table("syslog")."(".$this->DESK->Database->Field("event_dt").",";<br />
$q.=$this->DESK->Database->Field("event").",".$this->DESK->Database->Field("event_class").",";<br />
$q.=$this->DESK->Database->Field("event_type").",".$this->DESK->Database->Field("event_level").") ";<br />
$q.="VALUES(NOW(),\"".$this->DESK->Database->Safe($event)."\",\"".$this->DESK->Database->Safe($class)."\",";<br />
$q.="\"".$this->DESK->Database->Safe($type)."\",".$this->DESK->Database->Safe($level).")";<br />
<br />
<br />
// Log into DB ensure report flag is false to avoid infinite loop if SQL error in this method<br />
$this->DESK->Database->Query($q, false);<br />
}<br />
<br />
}<br />
<br />
?><br />
</source></div>Dave