File:
0.00.1a/core/logging/LogMethodDB.php (
View as Code)
1: 2: /* -------------------------------------------------------------
3: This file is part of FreeDESK
4:
5: FreeDESK is (C) Copyright 2012 David Cutting
6:
7: FreeDESK is free software: you can redistribute it and/or modify
8: it under the terms of the GNU General Public License as published by
9: the Free Software Foundation, either version 3 of the License, or
10: (at your option) any later version.
11:
12: FreeDESK is distributed in the hope that it will be useful,
13: but WITHOUT ANY WARRANTY; without even the implied warranty of
14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: GNU General Public License for more details.
16:
17: You should have received a copy of the GNU General Public License
18: along with FreeDESK. If not, see www.gnu.org/licenses
19:
20: For more information see www.purplepixie.org/freedesk/
21: -------------------------------------------------------------- */
22:
23: /**
24: * LogMethodDB implements database-level logging
25: **/
26: class LogMethodDB extends LogMethodBase
27: {
28: /**
29: * FreeDESK instance
30: **/
31: private $DESK = null;
32:
33: /**
34: * Constructor
35: * @param mixed $freeDESK FreeDESK instance
36: **/
37: function LogMethodDB(&$freeDESK)
38: {
39: $this->DESK = &$freeDESK;
40: $this->DESK->PluginManager->Register(new Plugin(
41: "Core Database Logging", "0.01", "Log", "Database", "LogMethodDB" ));
42: }
43:
44: /**
45: * Log an event
46: * @param string $event Event description
47: * @param string $class Event class
48: * @param string $type Event type (optional, default "")
49: * @param int $level Event level (0 = fatal, 10 = low priority info only) (optional, default 10)
50: **/
51: function Log($event, $class, $type="", $level=10)
52: {
53: if (strlen($event)>254)
54: $event=substr($event,0,251)."...";
55: $q="INSERT INTO ".$this->DESK->Database->Table("syslog")."(".$this->DESK->Database->Field("event_dt").",";
56: $q.=$this->DESK->Database->Field("event").",".$this->DESK->Database->Field("event_class").",";
57: $q.=$this->DESK->Database->Field("event_type").",".$this->DESK->Database->Field("event_level").") ";
58: $q.="VALUES(NOW(),\"".$this->DESK->Database->Safe($event)."\",\"".$this->DESK->Database->Safe($class)."\",";
59: $q.="\"".$this->DESK->Database->Safe($type)."\",".$this->DESK->Database->Safe($level).")";
60:
61:
62: // Log into DB ensure report flag is false to avoid infinite loop if SQL error in this method
63: $this->DESK->Database->Query($q, false);
64: }
65:
66: }
67:
68: ?>
69: