Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Resplit LOG field into source, message and params - Close #483
Browse files Browse the repository at this point in the history
Upgrade to be tested on PostgreSQL
  • Loading branch information
cdujeu committed Mar 15, 2014
1 parent 4ebab98 commit 17861c9
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 15 deletions.
Expand Up @@ -2161,12 +2161,13 @@ public function listLogFiles($dir, $root = NULL, $hash = null, $returnNodes = fa
$logger = AJXP_Logger::getInstance();
$parts = explode("/", $dir);
if (count($parts)>4) {
$config = '<columns switchDisplayMode="list" switchGridMode="grid" template_name="ajxp_conf.logs">
<column messageId="ajxp_conf.17" attributeName="date" sortType="MyDate" defaultWidth="10%"/>
<column messageId="ajxp_conf.18" attributeName="ip" sortType="String" defaultWidth="10%"/>
$config = '<columns switchDisplayMode="list" switchGridMode="list" template_name="ajxp_conf.logs">
<column messageId="ajxp_conf.17" attributeName="date" sortType="MyDate" defaultWidth="18%"/>
<column messageId="ajxp_conf.18" attributeName="ip" sortType="String" defaultWidth="5%"/>
<column messageId="ajxp_conf.19" attributeName="level" sortType="String" defaultWidth="10%"/>
<column messageId="ajxp_conf.20" attributeName="user" sortType="String" defaultWidth="10%"/>
<column messageId="ajxp_conf.21" attributeName="action" sortType="String" defaultWidth="10%"/>
<column messageId="ajxp_conf.20" attributeName="user" sortType="String" defaultWidth="5%"/>
<column messageId="ajxp_conf.124" attributeName="source" sortType="String" defaultWidth="5%"/>
<column messageId="ajxp_conf.21" attributeName="action" sortType="String" defaultWidth="7%"/>
<column messageId="ajxp_conf.22" attributeName="params" sortType="String" defaultWidth="50%"/>
</columns>';
if(!$returnNodes) AJXP_XMLWriter::sendFilesListComponentConfig($config);
Expand Down
1 change: 1 addition & 0 deletions core/src/plugins/access.ajxp_conf/i18n/de.php
Expand Up @@ -146,4 +146,5 @@
"121" => "Get professional support for your install",
"122" => "All Settings",
"123" => "Other plugins",
"124" => "Source",
);
1 change: 1 addition & 0 deletions core/src/plugins/access.ajxp_conf/i18n/en.php
Expand Up @@ -144,4 +144,5 @@
"121" => "Get professional support for your install",
"122" => "All Settings",
"123" => "Other plugins",
"124" => "Source",
);
1 change: 1 addition & 0 deletions core/src/plugins/access.ajxp_conf/i18n/es.php
Expand Up @@ -144,4 +144,5 @@
"121" => "Get professional support for your install",
"122" => "All Settings",
"123" => "Other plugins",
"124" => "Source",
);
1 change: 1 addition & 0 deletions core/src/plugins/access.ajxp_conf/i18n/fi.php
Expand Up @@ -147,5 +147,6 @@
"121" => "Get professional support for your install",
"122" => "All Settings",
"123" => "Other plugins",
"124" => "Source",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/access.ajxp_conf/i18n/fr.php
Expand Up @@ -144,5 +144,6 @@
"121" => "Get professional support for your install",
"122" => "Paramètres",
"123" => "Autres extensions",
"124" => "Source",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/access.ajxp_conf/i18n/hu.php
Expand Up @@ -146,5 +146,6 @@
"121" => "Get professional support for your install",
"122" => "All Settings",
"123" => "Other plugins",
"124" => "Source",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/access.ajxp_conf/i18n/pt.php
Expand Up @@ -144,4 +144,5 @@
"121" => "Get professional support for your install",
"122" => "All Settings",
"123" => "Other plugins",
"124" => "Source",
);
1 change: 1 addition & 0 deletions core/src/plugins/access.ajxp_conf/i18n/si.php
Expand Up @@ -145,4 +145,5 @@
"121" => "Get professional support for your install",
"122" => "All Settings",
"123" => "Other plugins",
"124" => "Source",
);
17 changes: 10 additions & 7 deletions core/src/plugins/log.sql/class.sqlLogDriver.php
Expand Up @@ -98,7 +98,7 @@ public function formatXmlLogList($node, $icon, $dateattrib, $display, $text, $fi
*
* @return String Formatted XML node for insertion into the log reader
*/
public function formatXmlLogItem($node, $icon, $dateattrib, $filename, $remote_ip, $log_level, $user, $action, $params, $rootPath = "/logs")
public function formatXmlLogItem($node, $icon, $dateattrib, $filename, $remote_ip, $log_level, $user, $source, $action, $params, $rootPath = "/logs")
{
$remote_ip = $this->inet_dtop($remote_ip);
$log_unixtime = strtotime($dateattrib);
Expand All @@ -110,8 +110,9 @@ public function formatXmlLogItem($node, $icon, $dateattrib, $filename, $remote_i
// Some actions or parameters can contain characters that need to be encoded, especially when a piece of code raises a notification or error.
$action = AJXP_Utils::xmlEntities($action);
$params = AJXP_Utils::xmlEntities($params);
$source = AJXP_Utils::xmlEntities($source);

return "<$node icon=\"{$icon}\" date=\"{$log_datetime}\" ajxp_modiftime=\"{$log_unixtime}\" is_file=\"true\" filename=\"{$rootPath}/{$log_year}/{$log_month}/{$log_date}/{$log_datetime}\" ajxp_mime=\"log\" ip=\"{$remote_ip}\" level=\"{$log_level}\" user=\"{$user}\" action=\"{$action}\" params=\"{$params}\"/>";
return "<$node icon=\"{$icon}\" date=\"{$log_datetime}\" ajxp_modiftime=\"{$log_unixtime}\" is_file=\"true\" filename=\"{$rootPath}/{$log_year}/{$log_month}/{$log_date}/{$log_datetime}\" ajxp_mime=\"log\" ip=\"{$remote_ip}\" level=\"{$log_level}\" user=\"{$user}\" action=\"{$action}\" source=\"{$source}\" params=\"{$params}\"/>";
}

/**
Expand All @@ -128,12 +129,13 @@ public function formatXmlLogItem($node, $icon, $dateattrib, $filename, $remote_i
public function write2($level, $ip, $user, $source, $prefix, $message)
{
$log_row = Array(
'logdate' => new DateTime('NOW'),
'logdate' => new DateTime('NOW'),
'remote_ip' => $this->inet_ptod($ip),
'severity' => strtoupper((string) $level),
'user' => $user,
'message' => $source,
'params' => $prefix."\t".$message
'severity' => strtoupper((string) $level),
'user' => $user,
'source' => $source,
'message' => $prefix,
'params' => $message
);
//we already handle exception for write2 in core.log
dibi::query('INSERT INTO [ajxp_log]', $log_row);
Expand Down Expand Up @@ -277,6 +279,7 @@ public function xmlLogs($parentDir, $date, $nodeName = "log", $rootPath = "/logs
$r['remote_ip'],
$r['severity'],
$r['user'],
$r['source'],
$r['message'],
$r['params'],
$rootPath));
Expand Down
1 change: 1 addition & 0 deletions core/src/plugins/log.sql/create.mysql
Expand Up @@ -4,6 +4,7 @@ CREATE TABLE IF NOT EXISTS `ajxp_log` (
`remote_ip` VARCHAR(45),
`severity` ENUM('DEBUG', 'INFO', 'NOTICE', 'WARNING', 'ERROR'),
`user` VARCHAR(255),
`source` VARCHAR(255),
`message` TEXT,
`params` TEXT
);
1 change: 1 addition & 0 deletions core/src/plugins/log.sql/create.pgsql
Expand Up @@ -12,6 +12,7 @@ CREATE TABLE ajxp_log (
remote_ip varchar(45),
severity ajxp_log_severity,
"user" varchar(255),
source varchar(255),
message text,
params text
);
1 change: 1 addition & 0 deletions core/src/plugins/log.sql/create.sqlite
Expand Up @@ -4,6 +4,7 @@ CREATE TABLE IF NOT EXISTS ajxp_log (
remote_ip text DEFAULT NULL,
severity text DEFAULT NULL,
"user" text DEFAULT NULL,
source text DEFAULT NULL,
message text DEFAULT NULL,
params text DEFAULT NULL
);
6 changes: 6 additions & 0 deletions core/src/plugins/log.sql/update-from-5.2.2.mysql
@@ -0,0 +1,6 @@
CREATE TABLE `ajxp_log2` LIKE `ajxp_log.back`; INSERT `ajxp_log.back` SELECT * FROM `ajxp_log`;
CREATE TABLE `ajxp_log2` LIKE `ajxp_log`; INSERT `ajxp_log2` SELECT * FROM `ajxp_log`;
ALTER TABLE `ajxp_log2` ADD `source` VARCHAR( 255 ) NOT NULL AFTER `user` , ADD INDEX ( `source` ) ;
UPDATE `ajxp_log2` INNER JOIN ajxp_log ON ajxp_log2.id=ajxp_log.id SET ajxp_log2.source = ajxp_log.message, ajxp_log2.message = SUBSTRING_INDEX(SUBSTRING_INDEX(ajxp_log.params, '\t', 1), '\t', -1),ajxp_log2.params = SUBSTRING_INDEX(SUBSTRING_INDEX(ajxp_log.params, '\t', 2), '\t', -1);
DROP TABLE `ajxp_log`;
RENAME TABLE `ajxp_log2` TO `ajxp_log`;
6 changes: 6 additions & 0 deletions core/src/plugins/log.sql/update-from-5.2.2.pgsql
@@ -0,0 +1,6 @@
CREATE TABLE `ajxp_log2` LIKE `ajxp_log.back`; INSERT `ajxp_log.back` SELECT * FROM `ajxp_log`;
CREATE TABLE `ajxp_log2` LIKE `ajxp_log`; INSERT `ajxp_log2` SELECT * FROM `ajxp_log`;
ALTER TABLE `ajxp_log2` ADD `source` VARCHAR( 255 ) NOT NULL AFTER `user` , ADD INDEX ( `source` ) ;
UPDATE `ajxp_log2` INNER JOIN ajxp_log ON ajxp_log2.id=ajxp_log.id SET ajxp_log2.source = ajxp_log.message, ajxp_log2.message = SUBSTRING_INDEX(SUBSTRING_INDEX(ajxp_log.params, '\t', 1), '\t', -1),ajxp_log2.params = SUBSTRING_INDEX(SUBSTRING_INDEX(ajxp_log.params, '\t', 2), '\t', -1);
DROP TABLE `ajxp_log`;
RENAME TABLE `ajxp_log2` TO `ajxp_log`;
1 change: 1 addition & 0 deletions core/src/plugins/log.sql/update-from-5.2.2.sqlite
@@ -0,0 +1 @@
ALTER TABLE "ajxp_log" ADD COLUMN "source" text
12 changes: 9 additions & 3 deletions core/src/plugins/log.text/class.textLogDriver.php
Expand Up @@ -256,8 +256,14 @@ public function xmlLogs($parentDir, $date, $nodeName = "log", $rootPath = "/logs
$lines = file($fName);
foreach ($lines as $line) {
$line = AJXP_Utils::xmlEntities($line);
$matches = explode("\t",$line,6);
if (count($matches) == 6) {
$matches = explode("\t",$line,7);
if (count($matches) == 6){
$matches[4] = $matches[3];
$matches[5] = $matches[4];
$matches[6] = $matches[5];
$matches[3] = "";
}
if (count($matches) == 7) {
$fileName = $parentDir."/".$matches[0];
foreach ($matches as $key => $match) {
$match = AJXP_Utils::xmlEntities($match);
Expand All @@ -269,7 +275,7 @@ public function xmlLogs($parentDir, $date, $nodeName = "log", $rootPath = "/logs
$date = $matches[0];
list($m,$d,$Y,$h,$i,$s) = sscanf($date, "%i-%i-%i %i:%i:%i");
$tStamp = mktime($h,$i,$s,$m,$d,$Y);
print(SystemTextEncoding::toUTF8("<$nodeName is_file=\"1\" ajxp_modiftime=\"$tStamp\" filename=\"$fileName\" ajxp_mime=\"log\" date=\"$matches[0]\" ip=\"$matches[1]\" level=\"$matches[2]\" user=\"$matches[3]\" action=\"$matches[4]\" params=\"$matches[5]\" icon=\"toggle_log.png\" />", false));
print(SystemTextEncoding::toUTF8("<$nodeName is_file=\"1\" ajxp_modiftime=\"$tStamp\" filename=\"$fileName\" ajxp_mime=\"log\" date=\"$matches[0]\" ip=\"$matches[1]\" level=\"$matches[2]\" user=\"$matches[3]\" source=\"$matches[4]\" action=\"$matches[5]\" params=\"$matches[6]\" icon=\"toggle_log.png\" />", false));
}
}
return ;
Expand Down

0 comments on commit 17861c9

Please sign in to comment.