1<?php 2 3/* 4 * This file is part of pgFouine. 5 * 6 * pgFouine - a PostgreSQL log analyzer 7 * Copyright (c) 2005-2008 Guillaume Smet 8 * 9 * pgFouine is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or (at 12 * your option) any later version. 13 * 14 * pgFouine is distributed in the hope that it will be useful, but 15 * WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with pgFouine; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. 22 */ 23 24class LogObject { 25 var $text; 26 var $connectionId; 27 var $database; 28 var $user; 29 var $timestamp; 30 var $commandNumber = 0; 31 var $ignored; 32 var $context; 33 var $notices = array(); 34 var $number = 0; 35 var $location; 36 37 function LogObject($connectionId, $user, $database, $text = '', $ignored = false) { 38 $this->connectionId = $connectionId; 39 $this->user = $user; 40 $this->database = $database; 41 $this->text = $text; 42 $this->ignored = $ignored; 43 } 44 45 function setContextInformation($timestamp, $commandNumber) { 46 $this->timestamp = $timestamp; 47 $this->commandNumber = $commandNumber; 48 } 49 50 function getCommandNumber() { 51 return $this->commandNumber; 52 } 53 54 function getTimestamp() { 55 return $this->timestamp; 56 } 57 58 function getEventType() { 59 return false; 60 } 61 62 function append($text) { 63 if(DEBUG > 1 && !$text) stderr('Empty text for append', true); 64 $this->text .= ' '.$text; 65 } 66 67 function addNotice($notice) { 68 $this->notices[] = $notice; 69 } 70 71 function getNotices() { 72 return $this->notices; 73 } 74 75 function setContext($context) { 76 $this->context = normalizeWhitespaces($context); 77 } 78 79 function getNormalizedText() { 80 $regexpRemoveText = "/'[^']*'/"; 81 $regexpRemoveNumbers = '/([^a-zA-Z_\$-])-?([0-9]+)/'; 82 $regexpRemoveHexadecimalNumbers = '/([^a-z_\$-])0x[0-9a-f]{1,10}/i'; 83 $regexpRemoveIn = '/(IN\s*)\([\'0x,\s]*\)/i'; 84 85 $text = $this->text; 86 if($text) { 87 $text = normalizeWhitespaces($text, CONFIG_KEEP_FORMATTING); 88 $text = str_replace("\\'", '', $text); 89 $text = preg_replace($regexpRemoveText, "''", $text); 90 $text = preg_replace("/''('')+/", "''", $text); 91 $text = preg_replace($regexpRemoveNumbers, '${1}0', $text); 92 $text = preg_replace($regexpRemoveHexadecimalNumbers, '${1}0x', $text); 93 $text = preg_replace($regexpRemoveIn, '${1}(...)', $text); 94 } 95 return $text; 96 } 97 98 function accumulateTo(& $accumulator) { 99 if(!$this->isIgnored()) { 100 $this->text = normalizeWhitespaces($this->text, CONFIG_KEEP_FORMATTING); 101 $accumulator->fireEvent($this); 102 } 103 } 104 105 function isIgnored() { 106 if(CONFIG_DATABASE && $this->database != CONFIG_DATABASE) { 107 return true; 108 } 109 if(CONFIG_DATABASE_REGEXP && !preg_match(CONFIG_DATABASE_REGEXP, $this->database)) { 110 return true; 111 } 112 if(CONFIG_DATABASE_LIST && !in_array($this->database, explode(',', CONFIG_DATABASE_LIST))) { 113 return true; 114 } 115 if(CONFIG_USER && $this->user != CONFIG_USER) { 116 return true; 117 } 118 if(CONFIG_USER_REGEXP && !preg_match(CONFIG_USER_REGEXP, $this->user)) { 119 return true; 120 } 121 if(CONFIG_USER_LIST && !in_array($this->user, explode(',', CONFIG_USER_LIST))) { 122 return true; 123 } 124 if((CONFIG_TIMESTAMP_FILTER && ($this->timestamp < CONFIG_FROM_TIMESTAMP || $this->timestamp > CONFIG_TO_TIMESTAMP))) { 125 $this->ignored = true; 126 } 127 return $this->ignored; 128 } 129 130 function getConnectionId() { 131 return $this->connectionId; 132 } 133 134 function getDatabase() { 135 return $this->database; 136 } 137 138 function getUser() { 139 return $this->user; 140 } 141 142 function getText() { 143 return $this->text; 144 } 145 146 function getContext() { 147 return $this->context; 148 } 149 150 function getDetailedInformation() { 151 $detailedInformation = formatTimestamp($this->getTimestamp()); 152 if($this->getUser() && $this->getDatabase()) { 153 $detailedInformation .= ' - '.$this->getUser().'@'.$this->getDatabase(); 154 } 155 return $detailedInformation; 156 } 157 158 function appendDetail($detail) { 159 } 160 161 function setNumber($number) { 162 $this->number = $number; 163 } 164 165 function getNumber() { 166 return $this->number; 167 } 168 169 function setLocation($location) { 170 $this->location = $location; 171 } 172 173 function getLocation() { 174 return $this->location; 175 } 176} 177 178?>