|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00030 class database_logger extends base_logger { 00031 00032 protected $datecol; // Name of the field where the timestamp will be stored 00033 protected $levelcol; // Name of the field where the level of the message will be stored 00034 protected $messagecol; // Name of the field where the message will be stored 00035 protected $logtable; // Table, without prefix where information must be logged 00036 protected $columns; // Array of columns and values to set in all actions logged 00037 00038 // Protected API starts here 00039 00040 public function __construct($level, $datecol = false, $levelcol = false, $messagecol = null, $logtable = null, $columns = null) { 00041 // TODO check $datecol exists 00042 // TODO check $levelcol exists 00043 // TODO check $logtable exists 00044 // TODO check $messagecol exists 00045 // TODO check all $columns exist 00046 $this->datecol = $datecol; 00047 $this->levelcol = $levelcol; 00048 $this->messagecol = $messagecol; 00049 $this->logtable = $logtable; 00050 $this->columns = $columns; 00051 parent::__construct($level, (bool)$datecol, (bool)$levelcol); 00052 } 00053 00054 protected function action($message, $level, $options = null) { 00055 $columns = $this->columns; 00056 if ($this->datecol) { 00057 $columns[$this->datecol] = time(); 00058 } 00059 if ($this->levelcol) { 00060 $columns[$this->levelcol] = $level; 00061 } 00062 $columns[$this->messagecol] = $message; //TODO: should this be cleaned? 00063 return $this->insert_log_record($this->logtable, $columns); 00064 } 00065 00066 protected function insert_log_record($table, $columns) { 00067 // TODO: Allow to use an alternate connection (created in constructor) 00068 // based in some CFG->backup_database_logger_newconn = true in order 00069 // to preserve DB logs if the whole backup/restore transaction is 00070 // rollback 00071 global $DB; 00072 return $DB->insert_record($this->logtable, $columns, false); // Don't return inserted id 00073 } 00074 }